/* =========================================================================
   Roast My Deck — static phone-shaped shell.  Dark WC-artefact vibe.
   THE MANDATE: a FIXED phone-shaped window; the body never grows taller than
   the window; ALL scrolling happens inside the phone's content region.
   ========================================================================= */
:root {
  --bg: #14110f;
  --panel: #1b1714;
  --tile: #211c19;
  --ink: #f3ede7;
  --muted: #b7a89c;
  --dim: #9c8f83;
  --accent: #ff5a3c;
  --accent2: #ff9e3d;
  --ring: #ff5a3c;
  --border: #3a322c;
  --bezel: #06050400;
  --phone-w: 400px;
  --phone-h: 860px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;                 /* body NEVER scrolls */
  background:
    radial-gradient(1200px 700px at 50% -10%, #241b16 0%, #0d0b09 55%, #070605 100%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Source Sans Pro", sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
}
body {
  display: flex; align-items: center; justify-content: center;
  height: 100dvh;
}

/* ------------------------------- PHONE ---------------------------------- */
.phone {
  width: var(--phone-w);
  height: var(--phone-h);
  max-height: 100dvh;
  flex: 0 0 auto;
}
.bezel {
  position: relative;
  width: 100%; height: 100%;
  background: #0a0806;
  border-radius: 44px;
  padding: 12px;
  box-shadow:
    0 0 0 2px #2a231d,
    0 30px 80px rgba(0,0,0,.7),
    0 8px 22px rgba(0,0,0,.55),
    inset 0 0 0 1px rgba(255,255,255,.03);
}
.notch {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  width: 132px; height: 26px;
  background: #0a0806;
  border-bottom-left-radius: 16px; border-bottom-right-radius: 16px;
  z-index: 20;
}
.notch::after {           /* speaker slit */
  content: ""; position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  width: 44px; height: 5px; border-radius: 3px; background: #1d1712;
}

/* ----------------------------- SCREEN ----------------------------------- */
.screen {
  position: relative;
  width: 100%; height: 100%;
  background: var(--bg);
  border-radius: 32px;
  overflow: hidden;                 /* clips content to the screen */
  display: flex; flex-direction: column;
}

/* fixed top navigation */
.topnav {
  flex: 0 0 auto;
  padding: 30px 14px 8px;           /* clears the notch */
  background: linear-gradient(180deg, #1a1512, var(--bg));
  z-index: 6;
}
.brand {
  font-size: 13px; font-weight: 800; letter-spacing: .3px;
  color: var(--ink); text-align: center; margin-bottom: 8px;
}
.brand .flame { filter: drop-shadow(0 0 6px rgba(255,90,60,.6)); }
.seg {
  display: flex; gap: 4px; padding: 4px;
  background: var(--tile); border: 1px solid var(--border); border-radius: 12px;
}
.segbtn {
  flex: 1 1 0; padding: 9px 4px; border: 0; border-radius: 9px;
  background: transparent; color: var(--muted);
  font-size: 13.5px; font-weight: 700; cursor: pointer; white-space: nowrap;
  transition: background .15s, color .15s;
}
.segbtn.active {
  background: linear-gradient(180deg, var(--accent), #e04a2f);
  color: #fff; box-shadow: 0 2px 8px rgba(255,90,60,.35);
}

/* ------------------------------- VIEWS ---------------------------------- */
.view { display: none; flex: 1 1 auto; min-height: 0; flex-direction: column; }
.view.active { display: flex; }

/* the ONE internally-scrolling region per view */
.scroll {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* sub-head under the topnav (search / count in build; back / toggle in roast) */
.subhead {
  flex: 0 0 auto;
  padding: 8px 12px 6px;
  background: var(--bg);
  z-index: 5;
}
.searchrow { display: flex; gap: 6px; align-items: center; }
#search {
  flex: 1 1 auto;
  background: var(--tile); border: 1px solid var(--border); border-radius: 10px;
  color: var(--ink); font-size: 15px; padding: 10px 12px; outline: none;
  -webkit-user-select: text; user-select: text;
}
#search:focus { border-color: var(--accent); }
#clearsearch {
  flex: 0 0 auto; width: 40px; height: 40px;
  background: var(--tile); border: 1px solid var(--border); border-radius: 10px;
  color: var(--muted); font-size: 16px; cursor: pointer;
}
.countrow {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 7px; font-size: 12.5px; color: var(--muted);
}
.countrow .sel b { color: var(--accent2); font-weight: 800; }
/* brief "12/12" pulse when a 13th playable is blocked */
.countrow .sel { transition: transform .12s ease; }
.countrow .sel.flash { animation: flash12 .5s ease; }
.countrow .sel.flash b { color: var(--accent); }
@keyframes flash12 {
  0%, 100% { transform: none; }
  40% { transform: scale(1.18); }
}
#clearsel {
  background: none; border: 0; color: var(--accent);
  font-size: 12.5px; font-weight: 700; cursor: pointer; text-decoration: underline;
}
#clearsel[hidden] { display: none; }

/* ------------------------------- GRID ----------------------------------- */
#grid-hero, #grid-play {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
  padding: 4px 12px 14px; align-content: start;
  touch-action: pan-y;
}
/* Square tiles via the PADDING-TOP hack, NOT aspect-ratio: aspect-ratio on a
   grid item makes Chromium size the auto row to min-content (tiny), so the tall
   square tiles overflow and fan/overlap ("stacked"). padding-top:100% creates
   real box height that the grid row respects → one card per cell, no overlap. */
.tile {
  /* 5:7 portrait (140% = 7/5) via padding-hack — the card inside each square image
     is a 720x1008 (5:7) card with ~150px black bars L/R; a 5:7 tile + object-fit:cover
     crops those bars so the CARD fills the tile with no black border. padding-hack
     (not aspect-ratio) so the grid rows keep real height and don't overlap. */
  position: relative; width: 100%; padding-top: 140%; height: 0; overflow: hidden;
  border-radius: 10px; background: var(--tile); border: 2px solid transparent;
  cursor: pointer; transition: transform .08s ease, border-color .12s ease;
}
.tile:active { transform: scale(.96); }
/* Full square card fills the square tile → whole card, no crop. */
.tile img {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block;
  pointer-events: none; -webkit-user-drag: none; user-drag: none;
}
/* art-less placeholder: render as a legible "card back" so the NAME is always
   readable (≈175 cards have no art; a faint dashed box read as empty/broken). */
.ph {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; text-align: center; padding: 6px;
  border: 1px solid var(--border); border-radius: 8px;
  background:
    radial-gradient(120% 80% at 50% 0%, rgba(255,90,60,.14), transparent 60%),
    linear-gradient(160deg, #2a2320, #191512);
}
.ph .ico { font-size: 22px; opacity: .8; }
.ph .nm {
  font-size: 11px; line-height: 1.15; font-weight: 700;
  color: var(--ink); word-break: break-word;
}
.cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: 10.5px; line-height: 1.15; font-weight: 600; color: #fff;
  padding: 12px 4px 4px;
  background: linear-gradient(to top, rgba(0,0,0,.92), rgba(0,0,0,.55) 55%, rgba(0,0,0,0));
  text-align: center; word-break: break-word; pointer-events: none;
  text-shadow: 0 1px 2px rgba(0,0,0,.9);
}
.tile.sel { border-color: var(--ring); }
.tile.sel::after {
  content: "\2713"; position: absolute; top: 4px; right: 4px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
}
.tile.sel .cap { background: linear-gradient(to top, rgba(255,90,60,.9), rgba(255,90,60,0)); }
.grouphdr {
  grid-column: 1 / -1; position: sticky; top: -4px; z-index: 2;
  display: flex; align-items: center; gap: 8px; padding: 8px 2px 5px; margin-top: 2px;
  font-size: 11.5px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase;
  color: var(--accent2); background: var(--bg);
}
.grouphdr::after {
  content: ""; flex: 1 1 auto; height: 1px;
  background: linear-gradient(90deg, var(--border), transparent);
}
.empty {
  grid-column: 1 / -1; text-align: center; color: var(--dim);
  padding: 40px 16px; font-size: 13px; line-height: 1.5;
}

/* --------------------------- ACTION BAR --------------------------------- */
.actionbar {
  flex: 0 0 auto; padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(0deg, var(--bg) 70%, transparent);
  border-top: 1px solid var(--border);
}
.primary {
  width: 100%; padding: 14px; border: 0; border-radius: 13px;
  background: linear-gradient(180deg, var(--accent), #e0492e); color: #fff;
  font-size: 16px; font-weight: 800; cursor: pointer;
  box-shadow: 0 4px 16px rgba(255,90,60,.35);
}
.primary:disabled {
  background: #2a2420; color: var(--dim); box-shadow: none; cursor: not-allowed;
}

/* ------------------------------ ROAST ----------------------------------- */
.roastsub { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.back {
  background: var(--tile); border: 1px solid var(--border); border-radius: 10px;
  color: var(--ink); font-size: 13px; font-weight: 700; padding: 8px 11px; cursor: pointer;
}
.mode { display: flex; gap: 3px; padding: 3px; background: var(--tile);
  border: 1px solid var(--border); border-radius: 10px; }
.modebtn {
  padding: 7px 9px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 12px; font-weight: 700; cursor: pointer; white-space: nowrap;
}
.modebtn.active { background: var(--accent2); color: #201107; }

#roastscroll { padding: 4px 12px 20px; }

/* headline + grade */
.headline {
  font-size: 17px; font-weight: 800; line-height: 1.3; margin: 8px 2px 12px;
  color: var(--ink);
}
.gradecard {
  display: flex; align-items: center; gap: 14px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 14px; margin-bottom: 12px;
}
.gradebadge {
  flex: 0 0 auto; width: 66px; height: 66px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 900; color: #fff;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.1);
}
.g-A { background: linear-gradient(135deg,#2fbf71,#1f8f52); }
.g-B { background: linear-gradient(135deg,#7cc243,#4f9a2c); }
.g-C { background: linear-gradient(135deg,#f2b134,#d1892a); }
.g-D { background: linear-gradient(135deg,#f2802e,#d1571f); }
.g-F { background: linear-gradient(135deg,#e0492e,#b32a1a); }
.gradeinfo .ov { font-size: 24px; font-weight: 900; }
.gradeinfo .ov small { font-size: 13px; color: var(--dim); font-weight: 700; }
.gradeinfo .lbl { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

/* 2x2 meters */
.meters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.meter { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 10px 11px; }
.meter .mtop { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.meter .mname { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.meter .mval { font-size: 14px; font-weight: 800; color: var(--ink); }
.bar { height: 7px; border-radius: 4px; background: #2a2420; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent2)); }

/* section titles */
.sec { margin: 16px 2px 8px; font-size: 12px; font-weight: 800; letter-spacing: .6px;
  text-transform: uppercase; color: var(--accent2); }

/* findings */
.finding { background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 12px; margin-bottom: 8px; }
.finding .fhead { display: flex; gap: 8px; align-items: flex-start; }
.finding .dot { flex: 0 0 auto; font-size: 12px; line-height: 1.4; }
.finding .fdetail { font-size: 13px; line-height: 1.4; color: var(--ink); }
.finding .fcat { font-size: 10px; color: var(--dim); text-transform: uppercase; letter-spacing: .5px; margin-top: 3px; }
.finding .fsnark {
  margin-top: 8px; padding: 8px 10px; border-left: 3px solid var(--accent);
  background: rgba(255,90,60,.08); border-radius: 0 8px 8px 0;
  font-size: 12.5px; line-height: 1.4; color: var(--accent2); font-style: italic;
}

/* swaps */
.swap { display: flex; align-items: center; gap: 8px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 12px; padding: 10px; margin-bottom: 8px; }
.swap .thumb { flex: 0 0 auto; width: 52px; }
.swap .thumb .art { width: 52px; aspect-ratio: 5/7; border-radius: 7px; overflow: hidden; background: var(--tile);
  border: 2px solid transparent; }
.swap .thumb.cut .art { border-color: #b32a1a; }
.swap .thumb.add .art { border-color: #2fbf71; }
.swap .thumb .art img { width: 100%; height: 100%; object-fit: cover; display: block; }
.swap .thumb .art .miniph { width: 100%; height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px; padding: 3px; text-align: center;
  border: 1px solid var(--border); border-radius: 5px;
  background: linear-gradient(160deg, #2a2320, #191512); }
.swap .thumb .art .miniph { font-size: 15px; }
.swap .thumb .art .miniph .mininm { font-size: 7.5px; line-height: 1.05; font-weight: 700;
  color: var(--ink); word-break: break-word; }
.swap .thumb .tlbl { font-size: 9px; text-align: center; margin-top: 3px; font-weight: 800; letter-spacing: .5px; }
.swap .thumb.cut .tlbl { color: #e0715c; }
.swap .thumb.add .tlbl { color: #6fd39a; }
.swap .arrow { flex: 0 0 auto; color: var(--dim); font-size: 18px; }
.swap .sreason { flex: 1 1 auto; font-size: 12px; line-height: 1.35; color: var(--muted); }
.swap .sreason .names { color: var(--ink); font-weight: 700; }

/* synergies */
.syn { background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; margin-bottom: 7px; font-size: 12.5px; line-height: 1.35; }
.syn .pair { font-weight: 800; color: var(--ink); }
.syn .why { color: var(--muted); }
.moresyn { font-size: 11.5px; color: var(--dim); text-align: center; padding: 4px; }

/* summary */
.summary { background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px; margin-bottom: 10px; }
.summary .row { display: flex; justify-content: space-between; font-size: 13px; padding: 5px 0;
  border-bottom: 1px solid #241f1b; }
.summary .row:last-child { border-bottom: 0; }
.summary .k { color: var(--muted); }
.summary .v { color: var(--ink); font-weight: 700; }
.collbar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; margin-top: 8px; background:#241f1b; }
.collbar > span { height: 100%; }
.colllegend { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 8px; }
.colllegend .ci { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.colllegend .sw { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 auto; }

.verdict {
  margin: 14px 2px 6px; padding: 14px; border-radius: 14px;
  background: linear-gradient(135deg, rgba(255,90,60,.18), rgba(255,158,61,.1));
  border: 1px solid var(--accent); color: var(--ink);
  font-size: 14px; font-weight: 700; line-height: 1.4; text-align: center;
}
.unknownbox { font-size: 12px; color: var(--dim); margin: 8px 2px; }

/* ---------------------------- PREVIEW ----------------------------------- */
#overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.82);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 14px;
  backdrop-filter: blur(3px);
}
#overlay.on { display: flex; }
.pv { width: 96%; max-width: 400px; max-height: 92%; background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; overflow: hidden; box-shadow: 0 18px 50px rgba(0,0,0,.7); }
/* keep the enlarged card within the viewport height (5:7 is tall) */
.pv .pvart { max-height: 92vh; }
.pv .pvart { width: 100%; aspect-ratio: 5/7; background: var(--tile); display: block; }
.pv .pvart img { width: 100%; height: 100%; object-fit: cover; display: block; }
.pv .pvph { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.pv .pvph .ico { font-size: 46px; opacity: .5; }
.pv .pvbody { padding: 12px 14px 15px; }
.pv .pvname { font-size: 19px; font-weight: 800; line-height: 1.15; }
.pv .pvmeta { font-size: 11.5px; color: var(--dim); margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }
.pv .pvstats { display: flex; gap: 8px; margin-top: 9px; }
.pv .chip { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  background: var(--tile); border: 1px solid var(--border); color: var(--ink); }
.pv .pvab { font-size: 12.5px; color: var(--muted); line-height: 1.4; margin-top: 10px; }
.pv .hint { font-size: 10.5px; color: var(--dim); text-align: center; margin-top: 10px; opacity: .75; }

/* ========================= MOBILE: FULL SCREEN ========================== */
@media (max-width: 500px) {
  body { display: block; }
  .phone { width: 100vw; height: 100dvh; max-height: none; }
  .bezel { border-radius: 0; padding: 0; box-shadow: none; }
  .bezel::after { display: none; }
  .notch { display: none; }
  .screen { border-radius: 0; }
  .topnav { padding-top: calc(10px + env(safe-area-inset-top)); }
}
