:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1f2630;
  --border: #30363d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --accent: #58a6ff;
  --gold: #e3b341;
  --cell: #b685ff;
  --green: #3fb950;
  --red: #f85149;
  --radius: 12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom);
}

.app-header {
  padding: 16px 16px 8px;
  text-align: center;
}
.app-header h1 { font-size: 1.4rem; }
.subtitle { color: var(--text-dim); font-size: 0.85rem; margin-top: 2px; }

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.tab {
  flex: 1;
  padding: 10px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-dim);
  font-size: 0.95rem;
  font-weight: 600;
}
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0d1117;
}

main { padding: 8px 12px 40px; max-width: 560px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Best cards */
.best-cards { display: flex; gap: 10px; margin-bottom: 14px; }
.best-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
}
.best-card .label { font-size: 0.75rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.best-card .tier { font-size: 1.6rem; font-weight: 700; margin: 4px 0 2px; }
.best-card .value { font-size: 0.9rem; font-weight: 600; }
.best-card.coins .tier, .best-card.coins .value { color: var(--gold); }
.best-card.cells .tier, .best-card.cells .value { color: var(--cell); }

/* Sort bar */
.sort-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--text-dim);
  font-size: 0.85rem;
}
.segmented { display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.seg-btn {
  padding: 6px 14px;
  background: var(--surface);
  color: var(--text-dim);
  border: none;
  font-size: 0.85rem;
  font-weight: 600;
}
.seg-btn.active { background: var(--surface-2); color: var(--text); }

/* Tier list */
.tier-list { display: flex; flex-direction: column; gap: 8px; }
.tier-row {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 4px 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  color: var(--text);
  text-align: left;
  font: inherit;
}
.tier-row.best { border-color: var(--gold); }
.tier-row .tier-badge {
  grid-row: span 2;
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.tier-badge .t { font-size: 0.65rem; color: var(--text-dim); }
.tier-badge .n { font-size: 1.15rem; }
.tier-row .stat { font-size: 0.92rem; font-weight: 600; }
.tier-row .stat.coins { color: var(--gold); }
.tier-row .stat.cells { color: var(--cell); }
.tier-row .meta { grid-column: 2 / 4; font-size: 0.78rem; color: var(--text-dim); }
.tier-row .chevron { color: var(--text-dim); font-size: 1.2rem; grid-row: span 1; }

.empty-msg {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 16px;
  line-height: 1.6;
}
.hidden { display: none !important; }

/* Import */
.field-label { display: block; font-weight: 600; margin: 8px 0; }
textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 12px;
  font-size: 0.85rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 12px;
  padding: 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #0d1117; }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn:active { opacity: 0.8; }

.feedback { margin-top: 10px; font-size: 0.9rem; min-height: 1.2em; }
.feedback.ok { color: var(--green); }
.feedback.err { color: var(--red); }

/* Data tab */
#tab-data h2 { font-size: 1.1rem; margin: 8px 0; }
.hint { color: var(--text-dim); font-size: 0.85rem; line-height: 1.5; }
.data-actions { margin-top: 8px; }
.file-btn { cursor: pointer; }

/* Bottom sheet */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 20;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 80dvh;
  overflow-y: auto;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 10px 16px calc(24px + env(safe-area-inset-bottom));
  z-index: 21;
}
.sheet-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 4px auto 12px;
}
.sheet h2 { font-size: 1.1rem; margin-bottom: 10px; }

.run-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.run-card .run-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.run-card .run-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
  font-size: 0.88rem;
}
.run-card .k { color: var(--text-dim); }
.run-del {
  background: none;
  border: none;
  color: var(--red);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px;
}
