/* Spellbinder — clean, modern, dark-first design.
   The signed-in user's profile colour drives --accent. */

/* The hidden attribute must always win over component display styles.
   (.auth-wrap sets display:grid, which otherwise kept the sign-in screen
   visible above the app after login.) */
[hidden] { display: none !important; }

:root {
  --accent: #8b7cf6;
  --bg: #14141c;
  --bg-soft: #1a1a24;
  --surface: #20202e;
  --surface-2: #2a2a3c;
  --border: #34344a;
  --text: #f2f2f7;
  --muted: #a5a5b8;
  --danger: #e5534b;
  --ok: #3fb68b;
  --gold: #f5c542;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
  /* Single source for the sticky tab bar's offset (A-10): the tab
     bar sits exactly under the header; if the header height ever
     changes, change it here only. */
  --header-h: 52px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f4f8;
    --bg-soft: #ececf2;
    --surface: #ffffff;
    --surface-2: #f0f0f6;
    --border: #d9d9e4;
    --text: #1c1c26;
    --muted: #5f5f72;
    --shadow: 0 6px 24px rgba(30, 30, 60, .12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* The site must fit the phone, never stretch sideways (Jakson's rule):
     components are built to wrap; these clip any stray overflow as a
     safety net (hidden for older engines, clip where supported — clip,
     unlike hidden, keeps position:sticky working). */
  overflow-x: hidden;
  overflow-x: clip;
}
img, video, canvas, svg { max-width: 100%; }

h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .6em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }
.empty { color: var(--muted); text-align: center; padding: 2rem 1rem; border: 1px dashed var(--border); border-radius: var(--radius); }
button { font: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--text); }
img { max-width: 100%; }

/* ---------- buttons ---------- */
.btn {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .42rem .72rem;
  font-size: .93rem;
  font-weight: 600;
}
.btn:hover { border-color: var(--accent); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { filter: brightness(1.1); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--border); }
.btn-danger { color: var(--danger); }
.btn-google {
  display: inline-flex; align-items: center; gap: .6rem;
  background: #fff; color: #1f1f1f; border: 1px solid #dadce0;
  padding: .7rem 1.2rem; border-radius: 999px; font-size: 1rem;
}
.btn-file { display: inline-block; }
.row-gap { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

/* ---------- notice ---------- */
.notice {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(1rem + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--surface); border: 1px solid var(--accent); color: var(--text);
  padding: .7rem 1.1rem; border-radius: 999px; box-shadow: var(--shadow);
  max-width: 92vw; text-align: center;
}

/* ---------- auth screen ---------- */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.auth-card {
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 20px;
  padding: 2.2rem 1.8rem; max-width: 420px; width: 100%; text-align: center; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 2rem; margin-bottom: .2em; }
.tagline { color: var(--muted); margin-bottom: 1.4rem; }
.auth-note { color: var(--muted); font-size: .85rem; margin-top: 1.2rem; }

/* ---------- app shell ---------- */
.app-header {
  position: sticky; top: 0; left: 0; right: 0; width: 100%; z-index: 40;
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  padding: .55rem max(.9rem, env(safe-area-inset-right)) .55rem max(.9rem, env(safe-area-inset-left));
  background: var(--bg-soft); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .5rem; background: none; border: 0; color: var(--text); font-weight: 800; font-size: 1.05rem; }
.header-user { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.header-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 38vw; }

.tabbar {
  position: sticky; top: var(--header-h); left: 0; right: 0; width: 100%; z-index: 39;
  display: flex; flex-wrap: wrap; gap: .3rem;
  padding: .45rem max(.7rem, env(safe-area-inset-right)) .45rem max(.7rem, env(safe-area-inset-left));
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.tab {
  background: var(--surface); color: var(--muted); border: 1px solid var(--border);
  border-radius: 999px; padding: .3rem .62rem; font-weight: 600; font-size: .86rem;
  white-space: nowrap;
}
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab-menu-wrap { position: relative; margin-left: auto; }
.tab-menu {
  position: absolute; right: 0; top: calc(100% + .45rem); z-index: 50;
  display: flex; flex-direction: column; gap: .3rem; min-width: 176px;
  background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px;
  padding: .45rem; box-shadow: var(--shadow);
}
.tab-menu[hidden] { display: none; }
.tab-menu-item { text-align: left; border-radius: 10px; }

/* Narrow phones: the header gives its room to the buttons, not the name. */
@media (max-width: 620px) {
  :root { --header-h: 50px; }
  .header-name { display: none; }
  .app-header { padding-top: .5rem; padding-bottom: .5rem; }
  .header-user { gap: .35rem; }
  .header-user .btn { padding: .32rem .5rem; font-size: .85rem; }
  .brand { font-size: .98rem; }
}

/* Very narrow phones, 320–360 px (A-10): brand + avatar + Share +
   Sign out (+ Install when offered) must stay reachable in the one
   header row — the body's overflow-x: clip would otherwise make an
   overflowing button unreachable instead of scrollable. The brand
   goes icon-only and the row's gaps/padding shrink so everything
   fits without wrapping or sideways overflow. */
@media (max-width: 380px) {
  .app-header {
    gap: .35rem;
    padding-left: max(.55rem, env(safe-area-inset-left));
    padding-right: max(.55rem, env(safe-area-inset-right));
  }
  .brand { gap: .3rem; flex: none; }
  .brand span { display: none; }
  .brand svg { width: 26px; height: 26px; }
  .header-user { gap: .25rem; flex: none; }
  .header-user .btn { padding: .3rem .42rem; font-size: .82rem; white-space: nowrap; }
  .header-user .avatar { width: 28px; height: 28px; }
}

.content { max-width: 1060px; margin: 0 auto; padding: 1rem .9rem 4rem; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin-bottom: .9rem; flex-wrap: wrap; }
.back-btn { margin-bottom: .6rem; padding-left: 0; }

/* ---------- avatars ---------- */
.avatar {
  display: inline-grid; place-items: center; flex: none;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: .9rem;
  overflow: hidden; border: 2px solid var(--accent);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.5rem; }

/* ---------- binder list ---------- */
.binder-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .8rem; }
.binder-card {
  text-align: left; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; color: var(--text); width: 100%;
}
.binder-card:hover { border-color: var(--accent); }
.binder-card h3 { margin-bottom: .25rem; display: flex; align-items: center; gap: .45rem; }
.binder-card .stats { color: var(--muted); font-size: .9rem; }
.binder-card .value { font-weight: 700; color: var(--ok); }
.badge {
  display: inline-block; font-size: .7rem; font-weight: 700; letter-spacing: .02em;
  padding: .12rem .5rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted);
  vertical-align: middle;
}
.badge-public { color: var(--ok); border-color: var(--ok); }
.badge-showcase { color: var(--gold); border-color: var(--gold); }

/* ---------- binder page ---------- */
.controls { display: flex; gap: 1rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.control { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; color: var(--muted); }
.control.check { flex-direction: row; align-items: center; gap: .45rem; color: var(--text); font-size: .95rem; padding-bottom: .35rem; }
.control select, .field input, .field select, .search-row input {
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: .45rem .6rem;
}
.add-card-box { background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1.2rem; }
.search-row { display: flex; gap: .5rem; }
.search-row input { flex: 1; min-width: 0; }
.search-results { display: grid; gap: .45rem; margin-top: .7rem; }
.search-hit {
  display: flex; gap: .7rem; align-items: center; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .45rem .6rem; color: var(--text);
}
.search-hit:hover { border-color: var(--accent); }
.search-hit img { width: 42px; height: 58px; object-fit: cover; border-radius: 5px; background: var(--surface-2); }
.search-hit .hit-name { font-weight: 600; }
.search-hit .hit-sub { color: var(--muted); font-size: .83rem; }
.search-hit .hit-owned { color: var(--accent); font-size: .83rem; font-weight: 600; }
.pick-panel { margin-top: .8rem; background: var(--surface); border: 1px solid var(--accent); border-radius: 10px; padding: .8rem; }
.pick-panel .pick-row { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }

/* ---------- card grid ---------- */
.set-group-title { margin: 1.3rem 0 .6rem; font-size: 1rem; color: var(--muted); border-bottom: 1px solid var(--border); padding-bottom: .3rem; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(150px, 100%), 1fr)); gap: .8rem; }
@media (min-width: 720px) { .card-grid { grid-template-columns: repeat(auto-fill, minmax(min(180px, 100%), 1fr)); } }
.search-hit .hit-name, .search-hit .hit-sub { overflow-wrap: anywhere; }
.card-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.card-tile img.card-img { width: 100%; aspect-ratio: 488 / 680; object-fit: cover; background: var(--surface-2); display: block; }
.card-body { padding: .55rem .65rem .7rem; display: flex; flex-direction: column; gap: .25rem; flex: 1; }
.card-name { font-weight: 600; font-size: .92rem; }
.card-sub { color: var(--muted); font-size: .78rem; }
.card-tags { display: flex; gap: .3rem; flex-wrap: wrap; }
.tag { font-size: .68rem; font-weight: 700; padding: .08rem .45rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.tag-foil { color: var(--gold); border-color: var(--gold); }
.card-price { font-size: .85rem; }
.card-price .src { color: var(--muted); font-size: .72rem; }
.qty-row { margin-top: auto; display: flex; align-items: center; gap: .5rem; }
.qty-btn { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); font-weight: 800; }
.qty-btn:hover { border-color: var(--accent); }
.qty-num { font-weight: 700; min-width: 2.2em; text-align: center; }

/* ---------- members ---------- */
.member-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .8rem; }
.member-card {
  display: flex; align-items: center; gap: .7rem; text-align: left; width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .8rem; color: var(--text); font-weight: 600;
}
.member-card:hover { border-color: var(--accent); }
.member-hero { display: flex; align-items: center; gap: .9rem; margin-bottom: 1rem; }
.member-hero h2 { margin: 0; }

/* ---------- profile ---------- */
.profile-form { max-width: 560px; display: flex; flex-direction: column; gap: 1.1rem; }
.profile-top { display: flex; gap: 1rem; align-items: center; }
.field { display: flex; flex-direction: column; gap: .35rem; font-weight: 600; }
.field-row { flex-direction: row !important; align-items: flex-start; gap: .55rem; font-weight: 400; }
.palette { display: flex; gap: .45rem; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; padding: 0; }
.swatch.selected { border-color: var(--text); transform: scale(1.08); }
input[type="color"] { width: 44px; height: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); padding: 2px; }

/* ---------- dialog ---------- */
.dialog { background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); border-radius: 16px; padding: 1.2rem; width: min(440px, 92vw); }
.dialog::backdrop { background: rgba(0, 0, 0, .6); }
.dialog form { display: flex; flex-direction: column; gap: .9rem; }
.dialog-actions { justify-content: flex-end; margin-top: .2rem; }

@media (max-width: 560px) {
  .binder-head { align-items: flex-start; }
  .header-name { display: none; }
}

/* Auto set binders (Sets by release, mirrors of Main Collection) */
#set-area { margin-top: 1.8rem; }
.family-title { margin: 1.1rem 0 .45rem; font-size: 1.02rem; }

/* Phase 2 — trades, spares & wants, member search */
.search-input { width: 100%; padding: .55rem .7rem; margin-bottom: .8rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.member-actions { margin: .6rem 0 1rem; }
.mini-list { display: flex; flex-direction: column; gap: .4rem; }
.mini-row { display: flex; align-items: center; gap: .6rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .45rem .6rem; }
.mini-row img { width: 34px; height: 48px; object-fit: cover; border-radius: 4px; }
.mini-row .grow { flex: 1; min-width: 0; }
.mini-row .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-row .sub { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flag-want { color: var(--gold); font-weight: 700; }
.trade-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem .9rem; margin-bottom: .7rem; }
.trade-head { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.trade-head .avatar { width: 34px; height: 34px; }
.trade-sides { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; margin-top: .6rem; }
@media (max-width: 640px) { .trade-sides { grid-template-columns: 1fr; } }
.trade-side h4 { margin: 0 0 .4rem; font-size: .92rem; }
.chip { border: 1px solid var(--border); border-radius: 999px; padding: .08rem .55rem; font-size: .75rem; color: var(--muted); }
.chip-open { color: var(--gold); border-color: var(--gold); }
.chip-done { color: var(--ok); border-color: var(--ok); }
.trade-chat-wrap { margin-top: .6rem; }
.trade-chat { margin-top: .5rem; border: 1px solid var(--border); border-radius: 10px; padding: .6rem; background: var(--surface); }
.chat-log { max-height: 260px; overflow-y: auto; display: flex; flex-direction: column; gap: .45rem; }
.chat-msg { background: var(--surface-2); border-radius: 8px; padding: .4rem .55rem; max-width: 88%; align-self: flex-start; overflow-wrap: break-word; }
.chat-msg.chat-mine { align-self: flex-end; border: 1px solid var(--accent); }
.chat-meta { color: var(--muted); font-size: .75rem; margin-bottom: .15rem; }
.chat-form { display: flex; gap: .5rem; margin-top: .55rem; }
.chat-form input { flex: 1; min-width: 0; }
.compose-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 760px) { .compose-grid { grid-template-columns: 1fr; } }
.compose-balance { font-size: 1rem; }
.pick-list { display: flex; flex-direction: column; gap: .35rem; max-height: 55vh; overflow-y: auto; padding-right: .2rem; }
.pick-item { display: flex; align-items: center; gap: .55rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .35rem .5rem; }
.pick-item.picked { border-color: var(--accent); }
.pick-item img { width: 30px; height: 42px; object-fit: cover; border-radius: 4px; }
.pick-item .grow { flex: 1; min-width: 0; }
.pick-item .nm { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick-item .sub { color: var(--muted); font-size: .76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Phase 4 — decks */
.mini-row select { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: .3rem .4rem; }
.dialog textarea { width: 100%; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; font-family: inherit; }

/* Phase 7c — live scanner: camera stage + card-frame guide. Everything is
   fluid-width so the no-horizontal-scroll rule holds at any phone size. */
.live-box { margin-bottom: 1.1rem; }
.live-stage {
  position: relative; width: 100%; max-width: 560px; margin-top: .6rem;
  margin-left: auto; margin-right: auto;
  background: #000; border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
.live-stage video { display: block; width: 100%; height: 42dvh; object-fit: cover; }
.live-guide {
  position: absolute; pointer-events: none;
  left: 50%; top: 50%; transform: translate(-50%, -50%);
  height: 86%; aspect-ratio: 63 / 88;
  border: 2.5px solid var(--accent); border-radius: 10px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, .38);
}
/* Refreshed scanner (v14): candidate picks + in-panel presentation.
   The preview is capped at 42dvh by the video's CSS height, so
   stage + status + picks + presentation fit one phone screen. The
   guide is pure CSS (centred, card aspect); the sampler measures
   its real on-screen rect — no script sizing keeps them in sync. */
.live-box .search-results { margin-top: .6rem; }
.fp-art { width: 74px; height: 103px; object-fit: cover; border-radius: 6px; background: var(--surface-2); }
.saved-note { color: var(--accent); font-weight: 600; align-self: center; }
