/* Game Shelf: dark theme, one amber accent. Every color, font, and radius comes from these tokens. */
:root {
  --bg: #12151A;
  --surface: #1A1F27;
  --surface-2: #1F2530;
  --surface-3: #2A2F3A;      /* active option / pressed toggle */
  --panel: #171B22;
  --border: #262C36;
  --border-strong: #333B47;
  --border-input: #2C333E;
  --track: #232934;
  --text: #E8EAED;
  --text-soft: #D3D8DE;
  --text-dim: #B4BCC6;
  --text-muted: #9AA3AE;
  --placeholder: #8A939E;
  --accent: #F2A541;
  --accent-hover: #FFC777;
  --on-accent: #1A1206;
  --shelf-playing: var(--accent);
  --shelf-backlog: #8FB8FF;
  --shelf-finished: #7FD1B9;
  --shelf-dropped: #9AA3AE;
  --danger: #FF9B8F;
  --scrim: rgba(5, 7, 10, 0.6);
  --badge-bg: rgba(0, 0, 0, 0.55);

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: Inter, system-ui, sans-serif;
  --fs-body: 14px;
  --fs-meta: 13px;
  --fs-label: 12px;

  --radius-card: 12px;
  --radius-control: 10px;
  --radius-button: 8px;
  --gap: 16px;
  --page-pad: 32px;
  --touch: 44px;
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--fs-body);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
h1 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 26px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 100; padding: 8px 12px; background: var(--accent); color: var(--on-accent); border-radius: var(--radius-button); }
.skip-link:focus { left: 8px; }
.muted, .meta { color: var(--text-muted); }
.meta { font-size: var(--fs-meta); }
.section-label {
  font-size: var(--fs-label); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-muted); padding: 0 10px 6px;
}

/* ---------------------------------------------------------------- buttons */
.btn, .btn-accent, .btn-dashed {
  min-height: var(--touch); padding: 0 16px; border-radius: var(--radius-button);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn { border: 1px solid var(--border-strong); background: transparent; color: var(--text); }
.btn:hover:not(:disabled) { border-color: var(--text-muted); }
.btn-accent { border: 0; background: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-accent:hover:not(:disabled) { background: var(--accent-hover); }
.btn-dashed { border: 1px dashed var(--border-strong); background: transparent; color: var(--text-dim); width: 100%; }
.btn-dashed:hover { color: var(--text); border-color: var(--text-muted); }
.btn[aria-busy="true"] svg { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- header */
.app-header {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--gap);
  padding: 16px var(--page-pad); border-bottom: 1px solid var(--border);
}
.header-left, .header-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.header-left { gap: 28px; }
.logo { display: inline-block; line-height: var(--touch); font-family: var(--font-display); font-weight: 700; font-size: 22px; letter-spacing: -0.01em; color: var(--text); text-decoration: none; }
.logo:hover { color: var(--text); }
.logo span { color: var(--accent); }
.nav { display: flex; gap: 4px; }
.nav a { padding: 10px 14px; border-radius: var(--radius-button); color: var(--text-dim); text-decoration: none; font-weight: 500; }
.nav a:hover { color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }

.notice {
  margin: 16px var(--page-pad) 0; padding: 10px 14px; border-radius: var(--radius-button);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text-dim); font-size: var(--fs-meta);
}

/* ---------------------------------------------------------------- toolbar */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 20px var(--page-pad); }
.search {
  flex: 1 1 320px; display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px;
  border-radius: var(--radius-control); background: var(--surface); border: 1px solid var(--border-input); color: var(--text-muted);
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; min-height: 46px; background: transparent; border: 0; outline: none; color: var(--text); font-size: 15px; }
.search input::placeholder { color: var(--placeholder); }
.select {
  min-height: 48px; padding: 0 12px; border-radius: var(--radius-control);
  background: var(--surface); border: 1px solid var(--border-input); color: var(--text);
}
.view-toggle { display: flex; border: 1px solid var(--border-input); border-radius: var(--radius-control); overflow: hidden; }
.view-toggle button {
  width: 48px; height: 46px; border: 0; background: var(--surface); color: var(--text);
  display: flex; align-items: center; justify-content: center;
}
.view-toggle button[aria-pressed="true"] { background: var(--surface-3); }
.view-toggle button:focus-visible { outline-offset: -2px; }
.toolbar .btn-accent { min-height: 48px; padding: 0 18px; border-radius: var(--radius-control); }

/* ---------------------------------------------------------------- layout */
.layout { display: flex; flex-wrap: wrap; gap: 28px; padding: 0 var(--page-pad) 48px; align-items: flex-start; }
.sheet { flex: 1 1 220px; max-width: 260px; }
.sidebar { display: flex; flex-direction: column; gap: 24px; }
.main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: var(--gap); }
.main-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px; }
#results:focus { outline: none; }

/* ---------------------------------------------------------------- filters */
.filter-group { display: flex; flex-direction: column; gap: 4px; }
.opt {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 40px; padding: 0 10px;
  border: 0; border-radius: var(--radius-button); background: transparent; color: var(--text-soft); text-align: left;
}
.opt:hover { background: var(--surface); }
.opt[aria-pressed="true"] { background: var(--surface-3); color: var(--accent); font-weight: 500; }
.opt-count { font-size: var(--fs-label); color: var(--text-muted); }
.opt-more { color: var(--text-muted); font-size: var(--fs-meta); }

/* ---------------------------------------------------------------- art */
.art {
  position: relative; overflow: hidden; aspect-ratio: 460 / 215;
  background: linear-gradient(135deg, hsl(var(--h) 45% 34%), hsl(calc(var(--h) + 40) 35% 18%));
}
.art-initials {
  position: absolute; left: 12px; bottom: 8px;
  font-family: var(--font-display); font-weight: 700; font-size: 30px; color: rgba(255, 255, 255, 0.9);
}
.art-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.art-badge {
  position: absolute; right: 10px; bottom: 10px; padding: 3px 7px; border-radius: 4px;
  font-size: 11px; font-weight: 600; color: #F1F3F5; background: var(--badge-bg);
}
.art-thumb { width: 64px; flex: none; border-radius: 4px; }
.art-thumb .art-initials { font-size: 11px; left: 4px; bottom: 2px; }

/* ---------------------------------------------------------------- grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: var(--gap); }
.card {
  display: flex; flex-direction: column; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-card);
  background: var(--surface); color: inherit; text-align: left; overflow: hidden;
  content-visibility: auto; contain-intrinsic-size: auto 200px;
}
.card:hover { border-color: var(--accent); }
.card-body { width: 100%; padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; }
.card-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { display: flex; justify-content: space-between; gap: 8px; font-size: var(--fs-meta); color: var(--text-muted); }

.shelf { font-weight: 500; white-space: nowrap; }
.shelf-playing { color: var(--shelf-playing); }
.shelf-backlog { color: var(--shelf-backlog); }
.shelf-finished { color: var(--shelf-finished); }
.shelf-dropped { color: var(--shelf-dropped); }

/* ---------------------------------------------------------------- list */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-card); }
.table { width: 100%; min-width: 760px; border-collapse: collapse; }
.table th { background: var(--surface); text-align: left; padding: 0; font-weight: 500; }
.th-sort {
  width: 100%; min-height: var(--touch); padding: 0 16px; border: 0; background: transparent;
  color: var(--text-muted); font-weight: 500; text-align: left; white-space: nowrap;
}
.th-sort:hover, th[aria-sort="ascending"] .th-sort, th[aria-sort="descending"] .th-sort { color: var(--text); }
.th-sort:focus-visible { outline-offset: -2px; }
.table td { padding: 8px 16px; border-top: 1px solid var(--border); }
.table td.muted { color: var(--text-dim); }
.row-game {
  display: flex; align-items: center; gap: 12px; min-height: var(--touch); padding: 0; border: 0;
  background: transparent; color: var(--text); font-weight: 600; text-align: left;
}
.row-game:hover span:last-child { color: var(--accent); }

/* ---------------------------------------------------------------- empty, toast, stats */
.empty {
  padding: 64px 24px; border: 1px dashed var(--border-strong); border-radius: var(--radius-card);
  text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center;
}
.empty p { margin: 0; font-size: 16px; }
.sentinel { height: 1px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  padding: 12px 16px; border-radius: var(--radius-button); background: var(--surface-2);
  border: 1px solid var(--border-strong); color: var(--text); box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.stats { max-width: 1280px; margin: 0 auto; padding: 28px var(--page-pad) 56px; display: flex; flex-direction: column; gap: 28px; }
.stats h1 { font-size: 28px; }

}

/* ---------------------------------------------------------------- detail panel */
body.panel-open { overflow: hidden; }
#panel-root { position: fixed; inset: 0; z-index: 40; display: flex; justify-content: flex-end; }
.panel-backdrop { position: absolute; inset: 0; background: var(--scrim); animation: fade 0.15s ease-out; }
.panel {
  position: relative; width: 420px; max-width: 100%; height: 100%; overflow-y: auto; overscroll-behavior: contain;
  background: var(--panel); border-left: 1px solid var(--border-input);
  display: flex; flex-direction: column; gap: 20px; padding: 24px;
  animation: slide-in 0.2s ease-out;
}
@keyframes slide-in { from { transform: translateX(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
#panel-root.no-anim .panel, #panel-root.no-anim .panel-backdrop { animation: none; }
@media (prefers-reduced-motion: reduce) { .panel, .panel-backdrop { animation: none; } }
.panel-top { display: flex; justify-content: space-between; align-items: center; }
.panel-top .section-label { padding: 0; }
.pick-label { color: var(--accent); }
.icon-btn {
  width: var(--touch); height: var(--touch); border: 0; border-radius: var(--radius-button);
  background: var(--surface-2); color: var(--text); display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--surface-3); }
.art-panel { flex: none; border-radius: var(--radius-control); }
.art-panel .art-initials { left: 50%; bottom: 50%; transform: translate(-50%, 50%); font-size: 44px; }
.panel h2 { margin: 0; font-family: var(--font-display); font-size: 24px; line-height: 1.2; }

.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.tile { background: var(--surface-2); border-radius: var(--radius-button); padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.tile-label { font-size: var(--fs-label); color: var(--text-muted); }
.tile-value { font-size: 18px; font-weight: 600; }

.panel-section { display: flex; flex-direction: column; gap: 8px; }
.field-label { font-size: var(--fs-label); color: var(--text-muted); }
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.hint { font-size: var(--fs-label); color: var(--text-muted); }
.shelf-picker { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.shelf-btn {
  min-height: var(--touch); border-radius: var(--radius-button); border: 1px solid var(--border-strong);
  background: transparent; color: var(--text-soft); font-size: var(--fs-meta); font-weight: 500;
}
.shelf-btn:hover:not(:disabled) { border-color: var(--text-muted); }
.shelf-btn:disabled { opacity: 1; cursor: default; }
.shelf-btn:disabled:not([aria-pressed="true"]) { color: var(--text-muted); }
.shelf-btn[aria-pressed="true"] { color: var(--bg); border-color: transparent; }
.shelf-btn-playing[aria-pressed="true"] { background: var(--shelf-playing); }
.shelf-btn-backlog[aria-pressed="true"] { background: var(--shelf-backlog); }
.shelf-btn-finished[aria-pressed="true"] { background: var(--shelf-finished); }
.shelf-btn-dropped[aria-pressed="true"] { background: var(--shelf-dropped); }

.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { padding: 4px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-soft); font-size: var(--fs-meta); }
.info { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.info-row { display: flex; justify-content: space-between; gap: 16px; }
.info dt { color: var(--text-muted); }
.info dd { margin: 0; text-align: right; }

.panel textarea, .dialog input {
  background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius-button);
  color: var(--text); padding: 10px; resize: vertical; width: 100%;
}
.panel textarea::placeholder { color: var(--placeholder); }
.panel textarea:focus, .dialog input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.links { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.links a { text-decoration: none; padding: 0 8px; }
.links .btn { color: var(--text); }
.links .btn-accent { color: var(--on-accent); }
.btn-roll {
  min-height: var(--touch); border-radius: var(--radius-button); border: 1px dashed var(--accent);
  background: transparent; color: var(--accent); font-weight: 600;
}
.btn-roll:hover { background: var(--surface-2); }

/* ---------------------------------------------------------------- sign-in dialog */
.dialog {
  width: min(400px, calc(100vw - 32px)); padding: 24px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-card); background: var(--panel); color: var(--text);
}
.dialog::backdrop { background: var(--scrim); }
.dialog form { display: flex; flex-direction: column; gap: 10px; }
.dialog h2 { margin: 0; font-family: var(--font-display); font-size: 22px; }
.dialog p { margin: 0; }
.dialog input { min-height: var(--touch); }
.error { color: var(--danger); font-size: var(--fs-meta); min-height: 1em; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.link-btn { padding: 0; border: 0; background: none; color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.link-btn:hover { color: var(--accent-hover); }

/* ---------------------------------------------------------------- stats */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--gap); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 18px 20px; display: flex; flex-direction: column; gap: 6px;
}
.kpi-label { font-size: var(--fs-meta); color: var(--text-muted); }
.kpi-value { font-family: var(--font-display); font-size: 34px; font-weight: 700; }
.kpi-sub { font-size: var(--fs-meta); color: var(--text-dim); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr)); gap: 20px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 20px; display: flex; flex-direction: column; gap: 12px; min-width: 0;
}
.stat-card h2 { margin: 0; font-size: 16px; font-weight: 600; }
.stat-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.stat-head .muted { font-size: var(--fs-meta); }
.bar-row { display: grid; grid-template-columns: minmax(0, 180px) minmax(0, 1fr) 80px; align-items: center; gap: 12px; }
.bar-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 12px; background: var(--track); border-radius: 6px; overflow: hidden; }
.bar { height: 100%; border-radius: 6px; }
.bar-accent { background: var(--accent); }
.bar-blue { background: var(--shelf-backlog); }
.bar-value { text-align: right; color: var(--text-dim); white-space: nowrap; }
.link-name {
  min-height: 32px; padding: 0; border: 0; background: none; color: var(--text); text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.link-name:hover { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.stat-scroll { max-height: 420px; overflow-y: auto; }
.stat-list { list-style: none; margin: 0; padding: 0; }
.stat-list li { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 6px 0; border-top: 1px solid var(--border); }
.stat-list li .muted { white-space: nowrap; font-size: var(--fs-meta); }

/* ---------------------------------------------------------------- phone (under 720 px) */
.phone-only { display: none !important; }

@media (max-width: 719px) {
  :root { --page-pad: 20px; }
  .phone-only { display: revert !important; }
  .desktop-only, .nav, #synced { display: none !important; }
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

  .app-header { padding: 12px var(--page-pad); flex-wrap: nowrap; }
  .header-right { flex-wrap: nowrap; gap: 8px; }
  #refresh { width: var(--touch); padding: 0; }
  #refresh .btn-text { display: none; }
  .notice { margin: 12px var(--page-pad) 0; }

  .toolbar { padding: 14px var(--page-pad) 10px; gap: 12px; }
  .search { flex-basis: 100%; border-radius: var(--radius-card); }
  .search input { font-size: 16px; } /* 16px stops iOS zooming in on focus */
  .chips-row { display: flex !important; gap: 8px; overflow-x: auto; width: 100%; padding-bottom: 2px; scrollbar-width: none; }
  .chip {
    flex: none; min-height: var(--touch); padding: 0 14px; border-radius: 22px;
    border: 1px solid var(--border-strong); background: transparent; color: var(--text-soft);
  }
  .chip[aria-pressed="true"] { border-color: transparent; background: var(--accent); color: var(--on-accent); font-weight: 600; }

  .layout { padding: 0 var(--page-pad) 24px; gap: 0; }
  .main { flex-basis: 100%; gap: 8px; }
  .main-head h1 { font-size: 24px; }
  .main-head .muted { font-size: var(--fs-meta); }

  /* Filters become a bottom sheet. */
  .sheet {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; max-height: 85vh; overflow-y: auto;
    background: var(--panel); border-top: 1px solid var(--border-input); border-radius: 16px 16px 0 0;
    padding: 0 var(--page-pad) calc(24px + env(safe-area-inset-bottom));
    transform: translateY(105%); transition: transform 0.2s ease-out; visibility: hidden;
  }
  body.sheet-open .sheet { transform: none; visibility: visible; }
  .sheet { max-width: none; }
  body.sheet-open { overflow: hidden; }
  .sheet-backdrop { position: fixed; inset: 0; z-index: 29; background: var(--scrim); display: none !important; }
  body.sheet-open .sheet-backdrop { display: block !important; }
  .sheet-head {
    display: flex !important; justify-content: space-between; align-items: center;
    position: sticky; top: 0; background: var(--panel); padding: 16px 0 12px; z-index: 1;
  }
  .sheet-head h2 { margin: 0; font-family: var(--font-display); font-size: 20px; }
  .sheet-sort { display: flex !important; flex-direction: column; gap: 2px; margin-bottom: 20px; }
  .sheet-sort .select { width: 100%; }
  .sidebar { max-width: none; }
  .opt { min-height: var(--touch); }

  /* Cards become rows: thumbnail, name over "hours · last played", shelf. */
  .grid { display: flex; flex-direction: column; gap: 0; }
  .card {
    flex-direction: row; align-items: center; gap: 14px; min-height: 64px; padding: 8px 0;
    border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: transparent;
    contain-intrinsic-size: auto 64px;
  }
  .card:hover { border-color: var(--border); }
  .art-card { width: 88px; flex: none; border-radius: 6px; }
  .art-card .art-initials { font-size: 14px; left: 6px; bottom: 3px; }
  .art-card .art-badge { display: none; }
  .card-body { padding: 0; min-width: 0; gap: 3px; }
  .card-name { font-size: 14px; }

  /* Bottom tab bar. */
  .tabbar {
    display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr));
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--panel); border-top: 1px solid var(--border);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a, .tabbar button {
    min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    border: 0; background: none; color: var(--text-dim); text-decoration: none; font-size: var(--fs-label);
  }
  .tabbar a.active { color: var(--accent); font-weight: 600; }

  /* Detail panel goes full screen. */
  .panel { width: 100%; border-left: 0; padding: 20px var(--page-pad) calc(24px + env(safe-area-inset-bottom)); }
  .tiles { gap: 8px; }
  .tile-value { font-size: 16px; }
  .shelf-btn { font-size: 12px; }

  .stats { padding: 20px var(--page-pad) 32px; gap: 20px; }
  .stats h1 { font-size: 24px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 26px; }
  .bar-row { grid-template-columns: minmax(0, 1fr) 64px; row-gap: 4px; }
  .bar-row .bar-track { grid-column: 1 / -1; grid-row: 2; }
  .stat-card { padding: 16px; }
}
