/* Sticker Matchmaker. Values mirror design/tokens.tokens.json — change them there first. */
:root {
  --brand: #00843d;
  --brand-dark: #00612d;
  --accent: #1a3a6b;

  /* Blue and amber, not green/red: this app is for ten-year-old boys and red-green colour
     blindness affects roughly 8% of them. Both tints must hold contrast >= 3.0 against --bg. */
  --need: #1d6fd0;
  --need-surface: #dbeafe;
  --spare: #e07c00;
  --spare-surface: #fef0dc;

  --bg: #f4f6fb;
  --card: #fff;
  --line: #e6e9f0;
  --ink: #15181f;
  --muted: #6b7280;
  --danger: #d1242f;

  --radius: 18px;
  --radius-lg: 28px;
  --shadow: 0 4px 18px rgba(20, 24, 31, .08);
  --tap: 52px;
  --tabbar: 64px;
  --safe: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 17px; line-height: 1.4;
  overscroll-behavior-y: contain;
}
h1, h2, h3 { margin: 0 0 .4em; }
button { font-family: inherit; font-size: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-weight: 600; min-height: 1.4em; }

/* ---------- Login / redeem ---------- */
.entry-body {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: linear-gradient(160deg, var(--brand) 0%, var(--brand-dark) 55%, var(--accent) 100%);
}
.entry-card {
  background: var(--card); border-radius: var(--radius-lg); padding: 26px 22px;
  width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.entry-card h1 { color: var(--brand); font-size: 1.6rem; text-align: center; }
.entry-card .tagline { text-align: center; margin-top: -.3em; }

.who-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 10px; margin: 18px 0; }
.who {
  background: var(--bg); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 12px 6px; text-align: center; min-height: var(--tap);
}
.who[aria-pressed="true"] { border-color: var(--brand); background: #eaf7ef; }
.who .emoji { font-size: 2rem; display: block; line-height: 1.1; }
.who .name { font-weight: 600; font-size: .95rem; word-break: break-word; }

.code-input {
  font-size: 2rem; letter-spacing: .35em; text-align: center; font-variant-numeric: tabular-nums;
  padding: 14px; border: 2px solid var(--line); border-radius: 14px; width: 100%; background: #fff;
}
.code-input:focus { outline: none; border-color: var(--brand); }

.btn {
  border: none; border-radius: 14px; padding: 15px 18px; font-weight: 700;
  background: var(--brand); color: #fff; width: 100%; min-height: var(--tap);
}
.btn:disabled { opacity: .5; }
.btn.secondary { background: transparent; color: var(--brand); }
.btn.danger { background: var(--danger); }
.btn.small { width: auto; padding: 9px 14px; font-size: .9rem; min-height: 44px; }

/* auto-fill, not a fixed 8 columns: at 320px a fixed grid squeezed these to 28px wide, well under
   the 44px touch floor. Wrapping to fewer-per-row keeps every target thumb-sized. */
.avatar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; margin: 12px 0; }
.avatar-grid button {
  font-size: 1.5rem; padding: 8px 0; border: 2px solid var(--line);
  border-radius: 12px; background: var(--bg); min-height: 44px;
}
.avatar-grid button[aria-pressed="true"] { border-color: var(--brand); background: #eaf7ef; }

/* ---------- App shell ---------- */
/* The mode tint is applied to the page-level container, not a badge. Step 3's test asserts both
   the contrast ratio and that this element is the container — "loud" is a functional requirement. */
#app { min-height: 100vh; padding-bottom: calc(var(--tabbar) + var(--safe) + 8px); transition: background-color .15s; }
#app[data-mode="need"] { background: var(--need-surface); }
#app[data-mode="spare"] { background: var(--spare-surface); }

.topbar {
  position: sticky; top: 0; z-index: 5; background: inherit;
  padding: 10px 14px 8px; border-bottom: 1px solid var(--line);
}
.topbar h2 { font-size: 1.15rem; margin: 0; }
.topbar .sub { font-size: .85rem; color: var(--muted); }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }

/* The mode switch. Pinned in the topbar so it never scrolls out of view. */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.mode {
  border: 3px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 14px; padding: 12px 8px; font-weight: 800; min-height: var(--tap);
}
.mode[aria-pressed="true"] { color: #fff; }
.mode.need[aria-pressed="true"] { background: var(--need); border-color: var(--need); }
.mode.spare[aria-pressed="true"] { background: var(--spare); border-color: var(--spare); }

/* Sits in the mode switch's slot on My Stickers, and matches its weight: this is the one control
   standing between a scrolling thumb and a deleted sticker, so it reads as loudly as the modes do. */
.editbar { margin-top: 10px; }
.editbar button {
  width: 100%; border: 3px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 14px; padding: 12px 8px; font-weight: 800; min-height: var(--tap);
}
.editbar button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

.content { padding: 12px 14px 20px; }

/* ---------- Crest grid ---------- */
.team-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.team {
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 10px 8px; text-align: left; box-shadow: var(--shadow); min-height: var(--tap);
}
.team .code { font-weight: 800; font-size: 1.15rem; }
.team .name { font-size: .82rem; color: var(--muted); display: block; line-height: 1.2; }
.team .page { font-size: .75rem; color: var(--muted); }
.team .marks { margin-top: 6px; display: flex; gap: 6px; font-size: .78rem; font-weight: 700; }
.pill { border-radius: 999px; padding: 1px 7px; }
.pill.need { background: var(--need-surface); color: var(--need); }
.pill.spare { background: var(--spare-surface); color: #a35a00; }

/* ---------- Sticker tiles: 20 must fit one phone screen ---------- */
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.sticker {
  position: relative; aspect-ratio: 1; border-radius: 14px; border: 3px solid var(--line);
  background: var(--card); font-weight: 800; font-size: 1.25rem; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: var(--tap);
}
.sticker .kindmark { font-size: .62rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.sticker[data-state="need"]  { background: var(--need);  border-color: var(--need);  color: #fff; }
.sticker[data-state="spare"] { background: var(--spare); border-color: var(--spare); color: #fff; }
.sticker[data-state] .kindmark { color: rgba(255,255,255,.85); }
.sticker .qty {
  position: absolute; top: -6px; right: -6px; background: var(--ink); color: #fff;
  border-radius: 999px; min-width: 24px; height: 24px; font-size: .82rem;
  display: grid; place-items: center; padding: 0 5px;
}

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 6px; font-size: 1.02rem; }
.codes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  border: 2px solid var(--line); background: var(--bg); border-radius: 10px;
  padding: 7px 10px; font-weight: 700; font-size: .92rem; min-height: 40px;
}
.chip.need { border-color: var(--need); color: var(--need); }
.chip.spare { border-color: var(--spare); color: #a35a00; }
/* Only in Edit mode, and only then is a chip a button at all. */
.chip.editable { display: inline-flex; align-items: center; gap: 7px; }
.chip.editable .x { font-size: .78rem; opacity: .7; }
.section-label { font-size: .82rem; font-weight: 800; text-transform: uppercase; color: var(--muted); margin: 16px 0 8px; letter-spacing: .04em; }
.empty { color: var(--muted); padding: 18px 4px; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: var(--safe); height: calc(var(--tabbar) + var(--safe));
}
.tabbar button {
  border: none; background: none; color: var(--muted); font-weight: 700; font-size: .78rem;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tabbar button .ico { font-size: 1.3rem; }
.tabbar button[aria-current="page"] { color: var(--brand); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar) + var(--safe) + 14px); z-index: 20;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px;
  font-weight: 600; font-size: .9rem; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px; max-width: calc(100vw - 28px);
}
.toast.has-action { padding: 6px 6px 6px 16px; }
.toast-action {
  background: #fff; color: var(--ink); border: none; border-radius: 999px;
  padding: 0 16px; min-height: 44px; font-weight: 800; font-size: .88rem;
  text-transform: uppercase; letter-spacing: .04em; flex: none;
}


/* ---------- Short screens (iPhone SE and anything landscape) ----------
   At 320x568 the header, the pinned mode switch, twenty square tiles and the tab bar came to a few
   pixels more than the viewport, so the grid spilled under the tab bar. Twenty tiles visible at
   once is the whole reason marking a pile of dupes is bearable, so the header gives up the space
   rather than the grid. */
@media (max-height: 700px) {
  :root { --tabbar: 56px; }
  .topbar { padding: 6px 12px 6px; }
  .topbar h2 { font-size: 1rem; }
  .topbar .sub { font-size: .75rem; }
  .modes { gap: 6px; margin-top: 6px; }
  .mode { padding: 8px 6px; min-height: 44px; font-size: .92rem; }
  .editbar { margin-top: 6px; }
  .editbar button { padding: 8px 6px; min-height: 44px; font-size: .92rem; }
  .content { padding: 8px 12px 12px; }
  .sticker-grid { gap: 6px; }
  /* Slightly wider than tall: buys the vertical room without shrinking the tap target. */
  .sticker { aspect-ratio: 1 / 0.82; font-size: 1.1rem; }
  .tabbar button { font-size: .7rem; }
  .tabbar button .ico { font-size: 1.1rem; }
}

/* ---------- Tablets ----------
   Wide screens got very stretched tiles. Cap the column so a sticker stays sticker-shaped. */
@media (min-width: 700px) {
  .content, .topbar { max-width: 720px; margin-left: auto; margin-right: auto; }
  .sticker-grid { grid-template-columns: repeat(5, 1fr); }
}


/* ---------- Landscape phones ----------
   Must come after the tablet rule: a sideways phone is 844px wide and would otherwise pick up the
   5-column tablet layout, which needs four rows and does not fit in 390px of height. Going wide
   instead trades rows for columns, so twenty tiles still land on one screen. */
@media (max-height: 480px) and (orientation: landscape) {
  .content, .topbar { max-width: none; }
  .sticker-grid { grid-template-columns: repeat(10, 1fr); gap: 5px; }
  .sticker { aspect-ratio: 1 / 0.9; font-size: .95rem; min-height: 44px; }
  .sticker .kindmark { font-size: .55rem; }
  /* The mode switch shares the header row rather than stacking under it. */
  .topbar { padding: 5px 12px; }
  .modes { margin-top: 5px; }
  .mode { padding: 6px; min-height: 44px; font-size: .85rem; }
  .editbar { margin-top: 5px; }
  .editbar button { padding: 6px; min-height: 44px; font-size: .85rem; }
}
