:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #222631;
  --border: #2c313d;
  --text: #e8eaf0;
  --muted: #9aa3b2;
  --accent: #7c9cff;
  --good: #4cc38a;
  --warn: #f0b429;
  --bad: #ef6b6b;
  --radius: 12px;
  --tabbar-h: 58px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--accent); text-decoration: none; }
main { max-width: 720px; margin: 0 auto; padding: 0 16px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }
h2 small, h1 small { color: var(--muted); font-weight: 400; font-size: .8em; }
h3 { margin: 0 0 4px; font-size: 19px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 10px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }

/* ---------- header / nav ---------- */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: rgba(15, 17, 21, .92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.top h1 { font-size: 20px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.backlink { font-size: 26px; line-height: 1; margin-right: 6px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(24, 27, 34, .96);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); font-size: 11px; gap: 2px;
}
.tabbar a .ic { font-size: 19px; line-height: 1; }
.tabbar a.on { color: var(--accent); }

/* ---------- buttons / chips ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 42px; padding: 0 14px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 15px; cursor: pointer; white-space: nowrap;
}
.btn.small { min-height: 34px; padding: 0 10px; font-size: 14px; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #0b0d12; font-weight: 600; }
.btn.good { background: var(--good); border-color: var(--good); color: #08140e; font-weight: 600; }
.btn.bad { color: var(--bad); border-color: rgba(239, 107, 107, .4); }
.btn.on { background: var(--accent); color: #0b0d12; border-color: var(--accent); font-weight: 600; }
.btn:disabled { opacity: .35; }

.chips { display: flex; gap: 8px; padding: 10px 0; }
.chips.scroll { overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 10px 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  min-height: 36px; padding: 0 12px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  font: inherit; font-size: 14px; cursor: pointer;
}
.chip small { color: var(--muted); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #0b0d12; }
.chip.on small { color: #0b0d12; }
.chip.sit { font-weight: 600; }
.chip-group { flex: none; align-self: center; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding-left: 4px; }

/* ---------- filters / forms ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 6px; }
.filters select, .filters input[type=search] { flex: 1 1 30%; min-width: 0; }
.filters input.wide { flex-basis: 100%; }
.filters .clear { font-size: 14px; padding: 0 4px; }
select, input, textarea {
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 10px; width: 100%; min-height: 42px;
}
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--accent); }
input[type=range] { padding: 0; accent-color: var(--accent); }
textarea { resize: vertical; }
.form { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.form label small { font-size: 12px; }
.form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex !important; flex-direction: row !important; align-items: center; gap: 8px; color: var(--text) !important; font-size: 15px !important; }
.checks { display: flex; gap: 20px; }
.more-fields { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.more-fields summary { cursor: pointer; color: var(--text); }
.more-fields[open] summary { margin-bottom: 10px; }
.more-fields > * + * { margin-top: 10px; }
.login { max-width: 360px; margin: 40px auto; }
.error { color: var(--bad); margin: 0; }
.row { display: flex; gap: 8px; align-items: flex-end; margin: 10px 0; }
.row label { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.row input { flex: 1; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.actions > .btn, .actions form .btn { flex: 1 1 auto; }
.actions form { display: contents; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 12px 0; }
.seg form, .seg .btn { width: 100%; }

/* ---------- game rows ---------- */
.games { list-style: none; margin: 0; padding: 0; min-height: 8px; }
.game {
  display: flex; align-items: stretch;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  margin-bottom: 6px; overflow: hidden;
}
.game .handle {
  flex: none; display: flex; align-items: center; justify-content: center;
  width: 34px; color: var(--muted); font-size: 18px;
  cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
}
.game .rank {
  flex: none; align-self: center; min-width: 30px; text-align: right; padding-right: 2px;
  color: var(--muted); font-variant-numeric: tabular-nums; font-size: 14px;
}
.game .handle + .rank { min-width: 22px; }
.game .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 8px 12px 8px 10px; color: var(--text); }
.game .title { font-weight: 600; line-height: 1.25; }
.game .meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 12.5px; color: var(--muted); }
.game .plat b { color: var(--text); font-weight: 500; }
.game .plat .alt { opacity: .75; }
.game .notes { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.game.is-maybe .title { opacity: .78; }
.games.compact .game .body { padding: 8px 12px; }

.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.playing { background: rgba(76, 195, 138, .18); color: var(--good); }
.badge.paused { background: rgba(240, 180, 41, .14); color: var(--warn); }
.badge.maybe { background: rgba(240, 180, 41, .14); color: var(--warn); }
.badge.tag { background: rgba(124, 156, 255, .15); color: var(--accent); }
.badge.date { background: rgba(124, 156, 255, .15); color: var(--accent); }
.badge.date.soon { background: var(--good); color: #08140e; }
.badge.date.out { background: rgba(76, 195, 138, .18); color: var(--good); }
.badge.rating { background: rgba(76, 195, 138, .18); color: var(--good); }

/* drag states */
.sortable-ghost { opacity: .35; }
.sortable-chosen { box-shadow: 0 6px 24px rgba(0, 0, 0, .5); border-color: var(--accent); }
.sortable-drag { opacity: .95; }

/* ---------- sections ---------- */
.section { margin: 14px 0 4px; }
.section > summary {
  list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 8px;
  padding: 6px 2px; font-weight: 700; font-size: 15px; color: var(--text);
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before { content: "▾"; color: var(--muted); width: 12px; }
.section:not([open]) > summary::before { content: "▸"; }
.section > summary small { color: var(--muted); font-weight: 400; }
.sortable .section-items { min-height: 44px; border-radius: var(--radius); }
.sortable .section-items:empty { border: 1px dashed var(--border); }
.footer-links { text-align: center; font-size: 14px; margin: 20px 0; }

/* ---------- lists index / menu ---------- */
.tiles { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tiles a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
}
.tiles b { color: var(--muted); font-weight: 500; }
.menu { list-style: none; padding: 0; margin: 16px 0; }
.menu a { display: block; padding: 14px; margin-bottom: 8px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.menu small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.plain { list-style: none; padding: 0; }
.section-edit .row { align-items: center; }
.section-edit small { color: var(--muted); min-width: 20px; text-align: center; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin: 16px 0; }

table.devices { width: 100%; border-collapse: collapse; margin: 10px 0 16px; }
table.devices th { font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; padding: 4px 2px; }
table.devices td { padding: 5px 2px; text-align: center; border-top: 1px solid var(--border); }
table.devices td:first-child { text-align: left; }
table.devices td:first-child input { min-height: 36px; padding: 6px 8px; }
table.devices td small { color: var(--muted); font-size: 11px; }

/* ---------- bottom sheet ---------- */
.sheet {
  width: 100%; max-width: 720px; max-height: 88vh;
  margin: auto auto 0; padding: 0;
  border: 1px solid var(--border); border-bottom: 0; border-radius: 18px 18px 0 0;
  background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgba(0, 0, 0, .55); }
.sheet[open] { animation: rise .18s ease-out; }
@keyframes rise { from { transform: translateY(40px); opacity: .4; } }
.sheet-inner { position: relative; padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-close { position: absolute; top: 10px; right: 10px; width: 36px; height: 36px; border-radius: 50%; border: 0; background: var(--surface-2); color: var(--muted); font-size: 16px; }
.sheet-head { padding-right: 40px; }
.sub { color: var(--muted); font-size: 13.5px; margin: 2px 0; }
.notes-full { white-space: pre-wrap; font-size: 14px; background: var(--surface-2); border-radius: 10px; padding: 10px; margin: 10px 0; }

/* ---------- flash / toast ---------- */
.flashes { max-width: 720px; margin: 10px auto 0; padding: 0 16px; }
.flash { background: var(--surface-2); border-left: 3px solid var(--accent); padding: 10px 12px; border-radius: 8px; font-size: 14px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); z-index: 30;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 16px; font-size: 14px; box-shadow: 0 6px 20px rgba(0, 0, 0, .4);
}
.toast.err { border-color: var(--bad); color: var(--bad); }

@media (min-width: 700px) {
  .tiles { grid-template-columns: repeat(3, 1fr); }
}

.notes-edit { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.notes-edit textarea { font-size: 16px; min-height: 0; }
.notes-edit .btn { align-self: flex-end; }
