/* ==========================================================================
   BrewNight · shared components — used by the dashboard AND Play.
   Tokens only (see tokens.css). Old dashboard class names are kept as
   aliases so existing markup keeps working; new code should use the first
   name in each selector list. Game-only pieces live in play/*.css.
   Load order: fonts.css → tokens.css → base.css → components.css → page css.
   Surfaces are quiet paper with a hairline border and small radii; depth is a soft shadow
   (--sh-1..4) reserved for things that float: menus, toasts, dialogs.
   ========================================================================== */

/* ── Layout utilities ───────────────────────────────────────────────────── */
.row { display: flex; align-items: center; gap: var(--sp-2h); }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.divider { height: 1px; background: var(--line); margin: var(--sp-5) 0; }

/* ── Text bits ──────────────────────────────────────────────────────────── */
.eyebrow { text-transform: uppercase; letter-spacing: var(--ls-caps); font-size: var(--fs-12); color: var(--gold); font-weight: var(--fw-bold); }
.subtle-link { font-size: var(--fs-12); }
.text-button { background: none; border: 0; padding: 0; color: var(--muted); font-size: var(--fs-12); }
.text-button:hover { background: none; color: var(--text); }
/* Keyboard hints are the one place 10px stays: they repeat an action that has a visible control. */
kbd { font: var(--fw-semibold) var(--fs-10)/1 var(--font-ui); padding: 2px 5px; border-radius: var(--r-1); border: 1px solid var(--line2); background: var(--panel2); color: inherit; letter-spacing: .04em; }

/* ── Badge · chip · status pill. Meaning colours are fixed: ok green, caution amber, danger red; the accent is selection only. ── */
.badge { font-size: var(--fs-12); line-height: 1.4; padding: 3px 7px; border-radius: var(--r-1); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.badge.gold { color: var(--gold); border-color: var(--gold-dim); background: var(--gold-a08); }
.badge.green { color: var(--green2); border-color: var(--green-a30); background: var(--green-a08); }
.badge.warn { color: var(--warn); border-color: var(--warn-a30); background: var(--warn-a08); }
.badge.danger { color: var(--danger); border-color: var(--danger-a30); background: var(--danger-a08); }
.badge.pill, .chip { border-radius: var(--r-pill); }
.chip { display: inline-flex; align-items: center; gap: var(--sp-1h); font-size: var(--fs-12); line-height: 1.2; padding: 3px 9px; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); white-space: nowrap; }
.chip.gold { color: var(--gold2); border-color: var(--gold-a50); background: var(--gold-a08); }
.chip.warn { color: var(--warn); border-color: var(--warn-a30); background: var(--warn-a08); }
.chip.danger { color: var(--danger); border-color: var(--danger-a30); background: var(--danger-a08); }
.status, .run-status { display: inline-flex; align-items: center; border: 1px solid var(--green-a30); background: var(--green-a08); color: var(--green2); padding: 3px 8px; border-radius: var(--r-2); font-size: var(--fs-12); text-transform: capitalize; white-space: nowrap; }
.status.live, .run-status.live { color: var(--gold); border-color: var(--gold-dim); background: var(--gold-a08); }
.status.warning, .run-status.warning { color: var(--warn); border-color: var(--warn-a30); background: var(--warn-a08); }
.status.danger, .run-status.danger { color: var(--danger); border-color: var(--danger-a30); background: var(--danger-a08); }
.status-dot { display: inline-block; height: 6px; width: 6px; background: var(--green); border-radius: var(--r-round); margin-right: var(--sp-1h); }

/* ── Mana pips (printed-symbol chips): <span class="pip W">W</span> ─────── */
.mana { display: inline-flex; gap: 3px; align-items: center; }
.pip { display: inline-flex; align-items: center; justify-content: center; border-radius: var(--r-round); height: 17px; min-width: 17px; padding: 0 3px; background: var(--pip-C); color: var(--pip-ink); font-size: var(--fs-10); font-weight: var(--fw-bold); box-shadow: var(--sh-1); letter-spacing: 0; }
.pip.W { background: var(--pip-W); } .pip.U { background: var(--pip-U); } .pip.B { background: var(--pip-B); }
.pip.R { background: var(--pip-R); } .pip.G { background: var(--pip-G); } .pip.C { background: var(--pip-C); }
.pip.lg { height: 24px; min-width: 24px; font-size: var(--fs-13); }
.pip.hy { background: linear-gradient(135deg, var(--ha, var(--pip-C)) 50%, var(--hb, var(--pip-C)) 50%); }
.pip.a-W { --ha: var(--pip-W); } .pip.a-U { --ha: var(--pip-U); } .pip.a-B { --ha: var(--pip-B); } .pip.a-R { --ha: var(--pip-R); } .pip.a-G { --ha: var(--pip-G); } .pip.a-C { --ha: var(--pip-C); }
.pip.b-W { --hb: var(--pip-W); } .pip.b-U { --hb: var(--pip-U); } .pip.b-B { --hb: var(--pip-B); } .pip.b-R { --hb: var(--pip-R); } .pip.b-G { --hb: var(--pip-G); } .pip.b-C { --hb: var(--pip-C); }
/* .in = inline cost glyph that scales with the surrounding text */
.pip.in { height: 1.45em; min-width: 1.45em; padding: 0; font-size: .78em; margin: 0 1px; vertical-align: -.2em; box-shadow: inset 0 0 0 1px var(--black-a25); }
/* A mana symbol is the printed art (ui/assets/mana/): the picture is the disc, so it takes no fill, letter, padding or ring of its own. */
.pip.sym, .pip.sym.in { background: none; padding: 0; box-shadow: none; overflow: visible; position: relative; }   /* position: the hidden token inside it is measured from the symbol, so a scrolling row clips it */
.pip.sym img { display: block; height: 100%; width: auto; aspect-ratio: 1; }

/* ── Panel · stat · progress · empty ────────────────────────────────────── */
.panel, .progress-panel { padding: 22px 25px; border: 1px solid var(--line); background: var(--panel); border-radius: var(--r-3); font-size: var(--fs-13); }
.panel.glass { background: var(--glass); backdrop-filter: blur(10px); border-color: var(--line2); box-shadow: var(--sh-3); }
.panel h2 { font-size: var(--fs-20); line-height: var(--lh-snug); }
.stat-inline { font-size: var(--fs-12); color: var(--muted); white-space: nowrap; }
.stat-inline strong { font-size: var(--fs-20); font-weight: var(--fw-medium); color: var(--text); margin-right: 5px; }
.progress, .progress-track { height: 5px; background: var(--panel3); border-radius: var(--r-1); overflow: hidden; margin: 16px 0 11px; }
.progress > div, .progress-track > div { height: 100%; background: var(--gold); transition: width var(--t-4); }
.empty, .empty-results { text-align: center; border: 1px solid var(--line); background: var(--panel); border-radius: var(--r-3); padding: 56px 25px; color: var(--muted); }
.loading { display: grid; place-items: center; height: 100vh; height: 100dvh; padding: var(--sp-5) var(--page-pad); text-align: center; text-wrap: balance; font: var(--fs-28) var(--font-display); color: var(--text); }
.error-state { padding: 50px; font-size: var(--fs-16); line-height: var(--lh-loose); }

/* ── Tabs / navigation underline ────────────────────────────────────────── */
.tabs, .study-tabs { display: flex; gap: var(--sp-6); border-bottom: 1px solid var(--line); }
.tabs button, .study-tabs button { border: 0; border-radius: 0; background: none; padding: var(--sp-3) 1px; min-height: var(--control-h); color: var(--muted); font-size: var(--fs-14); border-bottom: 2px solid transparent; box-shadow: none; }
.tabs button:hover, .study-tabs button:hover { background: none; color: var(--text); }
.tabs button.active, .study-tabs button.active { color: var(--text); border-bottom-color: var(--gold); }

/* ── App shell: top bar, brand, primary navigation ──────────────────────── */
.topbar { --topbar-pad: 32px; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-5); min-height: 68px; padding: var(--sp-2h) max(var(--topbar-pad), env(safe-area-inset-right, 0px)) var(--sp-2h) max(var(--topbar-pad), env(safe-area-inset-left, 0px)); border-bottom: 1px solid var(--line); background: var(--bg); }
.brand { display: flex; align-items: center; gap: var(--sp-3); color: var(--text); text-decoration: none; font: var(--fw-heavy) var(--fs-24)/1 var(--font-display); letter-spacing: var(--ls-display); white-space: nowrap; }
.brand small { display: block; font: var(--fw-medium) var(--fs-12)/1.2 var(--font-ui); color: var(--muted); letter-spacing: var(--ls-caps); margin-top: var(--sp-1); }
.top-actions { display: flex; align-items: center; gap: var(--sp-2); }
.save-status { font-size: var(--fs-12); color: var(--muted); margin-right: 14px; }
.save-status::before { content: ''; display: inline-block; width: 6px; height: 6px; border-radius: var(--r-round); background: var(--green); margin-right: 7px; }
.main-nav { display: flex; align-items: center; gap: var(--sp-1); min-width: 0; min-height: var(--tap); overflow-x: auto; }
.main-nav button, .main-nav a { display: inline-flex; align-items: center; min-height: var(--control-h); background: none; border: 0; border-bottom: 2px solid transparent; border-radius: var(--r-2) var(--r-2) 0 0; color: var(--muted); padding: var(--sp-2) var(--sp-3); font-size: var(--fs-14); font-weight: var(--fw-semibold); text-decoration: none; box-shadow: none; flex-shrink: 0; white-space: nowrap; }
.main-nav button:hover, .main-nav a:hover { background: var(--panel2); color: var(--text); }
.main-nav button.active, .main-nav a.active { color: var(--text); border-bottom-color: var(--gold); }
.main-nav span { margin-left: 5px; background: var(--panel3); border-radius: var(--r-1); padding: 1px 5px; font-size: var(--fs-12); }
.main-nav .icon { display: none; }
.top-search { display: inline-flex; align-items: center; gap: var(--sp-2); height: var(--control-h); padding: 0 var(--sp-2h) 0 var(--sp-3); border: 1px solid var(--line2); border-radius: var(--r-2); background: var(--panel); color: var(--muted); font-size: var(--fs-13); }
.top-search:hover { color: var(--text); border-color: var(--line3); background: var(--panel2); }
.top-search .icon { width: 14px; height: 14px; }
.top-search kbd { margin-left: var(--sp-3); color: var(--muted); }
.engine-mini { display: flex; align-items: center; gap: var(--sp-2); margin-top: 22px; font-size: var(--fs-12); color: var(--green2); }

/* ── Dialog (modal) ─────────────────────────────────────────────────────── */
dialog { border: 1px solid var(--line2); border-radius: var(--r-4); background: var(--panel); color: var(--text); width: min(620px, calc(100vw - 32px)); max-height: 90vh; padding: 24px; box-shadow: var(--sh-4); }
dialog::backdrop { background: var(--scrim); backdrop-filter: blur(5px); }
@media (hover: none) { dialog::backdrop { backdrop-filter: none; } }
dialog.wide { width: min(960px, calc(100vw - 32px)); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h2 { font-size: var(--fs-24); }
.modal-head button { border: 0; background: transparent; font-size: var(--fs-20); padding: 0 5px; min-width: var(--control-h); min-height: var(--control-h); }
.modal-body { line-height: var(--lh-body); color: var(--text2); font-size: var(--fs-13); }
.modal-body p { margin-bottom: 13px; }
.modal-body label { margin-top: 14px; }
.modal-footer { display: flex; justify-content: end; gap: var(--sp-2); margin-top: 22px; }
.modal-error { color: var(--danger); line-height: 1.7; font-size: var(--fs-13); margin-top: var(--sp-3); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }

/* ── Toast: an inverse surface, so it reads over any page without borrowing a status colour ── */
.toast, #toast { position: fixed; bottom: 23px; left: 50%; transform: translate(-50%, 15px); background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: var(--r-2); box-shadow: var(--sh-3); z-index: var(--z-toast); opacity: 0; pointer-events: none; transition: opacity var(--t-3), transform var(--t-3); max-width: 90vw; font-size: var(--fs-13); }
.toast.show, #toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.show:has(button), #toast.show:has(button) { pointer-events: auto; }

/* ── Deck tile: art header + title block (dashboard grid and Play setup) ── */
.deck-tile { padding: 0; text-align: left; overflow: hidden; position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-3); min-width: 0; transition: border-color var(--t-2), box-shadow var(--t-3); }
.deck-tile:hover { border-color: var(--line2); box-shadow: var(--sh-2); }
.deck-tile.selected { border-color: var(--gold); box-shadow: var(--ring-soft); }
.deck-art { height: 130px; position: relative; background: linear-gradient(125deg, var(--panel3), var(--felt)); overflow: hidden; }
.deck-art img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 32%; transition: transform var(--t-4); }
.deck-tile:hover img { transform: scale(1.03); }
.tile-content { padding: 13px 15px 14px; }
.tile-content h3 { font-size: var(--fs-16); font-weight: var(--fw-bold); line-height: var(--lh-snug); margin-bottom: 5px; overflow-wrap: anywhere; }
.tile-content p { font-size: var(--fs-12); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-content .row { margin-top: 14px; font-size: var(--fs-12); color: var(--muted); }
.tile-content .arrow { margin-left: auto; color: var(--gold); font-size: var(--fs-18); }
.checkmark { position: absolute; right: 11px; top: 10px; border-radius: var(--r-round); width: 22px; height: 22px; background: var(--action-bg); border: 1px solid var(--edge); color: var(--ink); z-index: 1; text-align: center; line-height: 20px; }

/* ── Page frame: container, hero, section heads, deck grid ──────────────── */
.setup { max-width: 1376px; padding: 42px 52px; margin: auto; }
.intro { display: flex; justify-content: space-between; align-items: center; gap: 44px; margin-bottom: 35px; }
.intro .eyebrow { margin-bottom: 16px; }
.intro p { max-width: 450px; line-height: var(--lh-body); color: var(--muted); font-size: var(--fs-14); margin-top: 18px; }
.intro-note { width: 270px; border-left: 1px solid var(--line); padding-left: 28px; line-height: var(--lh-body); color: var(--muted); font-size: var(--fs-13); }
.intro-note strong { display: block; color: var(--text); font-size: var(--fs-13); margin-bottom: 7px; }
.section-head { display: flex; justify-content: space-between; align-items: center; margin: 25px 0 15px; }
.section-head h2 { font-size: var(--fs-20); }
.section-head span { color: var(--muted); font-size: var(--fs-12); }
.deck-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; }

/* Credits stay outside images and are readable at phone widths. */
.card-attribution { display: grid; gap: 2px; margin-block: 12px; font: var(--fw-regular) var(--fs-12)/1.5 var(--font-ui); color: var(--muted); overflow-wrap: anywhere; letter-spacing: 0; text-transform: none; }
.card-attribution a { color: var(--gold); text-underline-offset: 3px; }
.card-attribution.compact-credit { font-size: var(--fs-11); margin-block: 10px 0; }   /* under a small tile; the full credit is in the card reader */
.card-attribution a:focus-visible { outline: var(--focus); outline-offset: 3px; }

/* ── Utilities shared by the non-game pages ─────────────────────────────── */
.icon { flex-shrink: 0; vertical-align: -.15em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
/* A card face at its printed proportions; the name shows through until the picture arrives. */
.cimg { position: relative; display: block; aspect-ratio: var(--card-aspect); border-radius: var(--card-r); overflow: hidden; background: var(--panel2); }
.cimg img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.cimg .fb { position: absolute; inset: 0; display: grid; place-items: center; padding: 10%; text-align: center; font: var(--fw-semibold) var(--fs-14) var(--font-ui); color: var(--muted); line-height: var(--lh-snug); }
/* Artwork on its way: the placeholder moves (ui/art-loading.mjs adds .art-loading until the picture arrives or fails). The name stays readable on top. */
.cimg.art-loading, .stage.art-loading, .poster .stage.art-loading { background: linear-gradient(100deg, color-mix(in srgb, var(--line) 42%, var(--panel)) 30%, color-mix(in srgb, var(--line) 14%, var(--panel)) 50%, color-mix(in srgb, var(--line) 42%, var(--panel)) 70%) 0 0 / 240% 100%; animation: art-shimmer 1.6s linear infinite; }
.cimg.art-loading { box-shadow: inset 0 0 0 1px var(--line); }   /* a faint card edge, so an empty grid still reads as cards (table cards keep their own highlights) */
@keyframes art-shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
@media (prefers-reduced-motion: reduce) { .art-loading { animation: none !important; } }
/* Credits use spacing rather than another rule below bordered card lists and above action bars. */
.fine { color: var(--dim); font-size: var(--fs-12); line-height: var(--lh-body); }
.fine a { color: var(--muted); }
.credits { max-width: var(--page-max); margin: var(--sp-7) auto 0; padding: var(--sp-4) var(--page-pad) var(--sp-6); }
/* The account menu and the appearance picker live in ui/appearance.css (the public pages use them without the rest of this file). */
/* The Scan tab is for phones; wider screens reach the scanner from Collection. */
@media (min-width: 561px) { .main-nav .phone-only { display: none; } }

/* ── Responsive: shell, page frame, deck tiles ──────────────────────────── */
@media (max-width: 1120px) {
  .topbar { --topbar-pad: 22px; } .main-nav { gap: 0; }
  .setup { padding: 30px; } .intro h1 { font-size: var(--fs-40); } .intro-note { width: 220px; } .deck-art { height: 112px; }
}
@media (max-width: 850px) {
  .topbar { --topbar-pad: 20px; flex-wrap: wrap; gap: var(--sp-2); } .save-status { display: none; }
  .intro-note { display: none; } .deck-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .deck-art { height: 155px; }
  .top-search span, .top-search kbd { display: none; } .top-search { width: var(--control-h); padding: 0; justify-content: center; }
}

/* Phone shell: brand, search and avatar on one line; the navigation is a tab bar at the bottom. */
@media (max-width: 560px) {
  :root { --tabbar-h: calc(62px + env(safe-area-inset-bottom, 0px)); }   /* the bar, and the home indicator under it */
  .topbar { --topbar-pad: var(--sp-4); flex-wrap: nowrap; gap: var(--sp-2); min-height: 0; padding-block: var(--sp-2); }
  .topbar .brand { margin-right: auto; font-size: var(--fs-20); min-height: var(--tap); }
  .topbar .brand > span { display: none; }
  .topbar .top-actions { flex-wrap: nowrap; justify-content: flex-end; gap: var(--sp-2); }
  .top-actions .btn, .top-actions button { min-height: var(--tap); font-size: var(--fs-13); padding: 7px 10px; }
  .top-search { width: var(--tap); height: var(--tap); }
  .main-nav { position: fixed; z-index: var(--z-chrome); left: 0; right: 0; bottom: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 0; width: auto; min-height: var(--tabbar-h); margin: 0; padding: var(--sp-1) max(var(--sp-2), env(safe-area-inset-right, 0px)) calc(var(--sp-1) + env(safe-area-inset-bottom, 0px)) max(var(--sp-2), env(safe-area-inset-left, 0px)); overflow: visible; background: var(--bg); border-top: 1px solid var(--line); }
  .main-nav a, .main-nav button { flex-direction: column; justify-content: center; gap: var(--sp-0); min-height: 52px; padding: var(--sp-1) 0; border: 0; border-radius: var(--r-2); font-size: var(--fs-12); font-weight: var(--fw-medium); line-height: 1.2; text-align: center; }
  .main-nav a.active, .main-nav button.active { background: var(--action-bg); color: var(--ink); box-shadow: inset 0 0 0 1px var(--edge); }
  /* The action bar owns the upper edge of this combined bottom area. */
  body:has(.workbench-actions) .main-nav,
  body:has(.setup-actions) .main-nav,
  body:has(.room-actions) .main-nav { border-top: 0; }
  .main-nav .icon { display: block; width: 22px; height: 22px; }
  .main-nav span { margin: 0; }
  body:has(.main-nav) { padding-bottom: var(--tabbar-h); }
  body:has(.scan-page) { padding-bottom: 0; }
  .toast, #toast { bottom: calc(var(--tabbar-h) + var(--sp-3)); }
  .tabs, .study-tabs { gap: var(--sp-2); overflow-x: auto; }
  .setup { padding: 28px 18px; } .intro h1 { font-size: var(--fs-40); } .intro p { font-size: var(--fs-13); }
  .section-head h2 { font-size: var(--fs-16); }
  .deck-grid { gap: 10px; } .deck-art { height: 110px; } .tile-content { padding: 10px; }
}

/* Pages draw to the screen edge (viewport-fit=cover): the side gutter never falls inside a notch on a phone turned sideways. */
:root { --page-pad: max(32px, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px)); }

/* ── PWA install and update surfaces: a calm paper bar above the tab bar, never over a page's own action bar ── */
.pwa-banner { --pwa-bottom: calc(var(--sp-3) + env(safe-area-inset-bottom, 0px)); position: fixed; z-index: var(--z-toast); inset-inline: max(var(--sp-3), env(safe-area-inset-left, 0px)) max(var(--sp-3), env(safe-area-inset-right, 0px)); bottom: var(--pwa-bottom); max-width: 560px; margin-inline: auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--sp-2) var(--sp-4); padding: var(--sp-3) var(--sp-4); background: var(--panel); color: var(--text); border: 1px solid var(--line2); border-radius: var(--r-4); box-shadow: var(--sh-3); font-size: var(--fs-14); line-height: var(--lh-snug); text-align: center; }
.pwa-banner button { min-height: var(--tap); }
@media (max-width: 560px) { .pwa-banner { --pwa-bottom: calc(var(--tabbar-h) + var(--sp-3)); } }
body:has(.setup-actions, .workbench-actions, .room-actions) .pwa-banner { bottom: calc(var(--pwa-bottom) + 84px); }   /* 48px action + its padding and rule */
