/**
 * 汉字长城 · THE GREAT WALL — this island's own ink.
 *
 * Everything sits on the Realm's parchment (realm.css loads first and owns the
 * variables). This file adds only what stone, brick and brush need: the four gates,
 * the 田字格 writing grid, the wall of tiles, and Learn mode's stage.
 *
 * Chinese glyphs drawn from data are SVG; Chinese TEXT uses the device's own kai/song
 * fonts — no web fonts, no CDN, offline always.
 */

.wall-app { --brick: #b0876077; }

/* Chinese text reads best in a brush-style face where the device has one. */
.hanzi,
.dict-box,
.wall-tile,
.tile-glyph {
  font-family: 'Kaiti SC', 'KaiTi', 'STKaiti', 'DFKai-SB', 'AR PL UKai CN', 'PingFang SC', 'Noto Sans CJK SC', serif;
}

.sheet {
  position: relative;
  max-width: 900px;
  /* Fill the screen minus the body's own padding, so no needless scrollbar. */
  min-height: calc(100dvh - 2 * clamp(0.5rem, 2.5vw, 1.5rem));
  margin: 0 auto;
  /* The bottom padding clears iPhone Safari's tap-to-reveal toolbar zone: a button
     sitting in the last ~44px of the screen takes TWO taps (the first only summons
     the browser chrome), so the last control always floats well above the edge. */
  padding: clamp(1rem, 4vw, 2.25rem) clamp(0.9rem, 4vw, 2.25rem)
    calc(clamp(3rem, 7vw, 4rem) + 1.5rem + env(safe-area-inset-bottom, 0px));
  background-color: var(--parchment);
  background-image:
    radial-gradient(ellipse at 16% 10%, rgba(150, 108, 48, 0.2), transparent 45%),
    radial-gradient(ellipse at 86% 80%, rgba(132, 94, 42, 0.22), transparent 42%),
    radial-gradient(ellipse at 50% 45%, rgba(255, 248, 226, 0.55), transparent 68%),
    repeating-linear-gradient(102deg, rgba(120, 90, 40, 0.045) 0 2px, transparent 2px 6px);
  border: 2px solid var(--ink-faint);
  border-radius: 10px 4px 12px 5px / 5px 12px 4px 10px;
  box-shadow: 0 14px 26px rgba(0, 0, 0, 0.5);
}

/* Nothing hidden may ever intercept a tap or win a display: contest. */
.screen[hidden], [hidden] { display: none !important; }

.screen { flex: 1; padding-bottom: 2rem; }

.gw-title {
  margin-top: 0.5rem;
  text-align: center;
  font-family: 'Kaiti SC', 'KaiTi', 'STKaiti', serif;
  font-size: clamp(2.6rem, 11vw, 4.8rem);
  letter-spacing: 0.12em;
  color: var(--ink);
  text-shadow: 1px 1px 0 var(--parchment-lit), 3px 3px 0 rgba(139, 105, 48, 0.28);
}

.gw-subtitle {
  text-align: center;
  font-style: italic;
  font-size: clamp(1rem, 3.4vw, 1.3rem);
  color: var(--ink-soft);
  margin-bottom: 1rem;
}

.gw-h2 {
  font-size: clamp(1.5rem, 5vw, 2.1rem);
  margin: 0.75rem 0 0.5rem;
  text-align: center;
}

.lead { text-align: center; line-height: 1.5; max-width: 56ch; margin: 0.5rem auto; }

.back {
  display: inline-block;
  margin: 0.25rem 0 0.5rem;
  color: var(--ink-soft);
  text-decoration: none;
  font-style: italic;
  min-height: 44px;
  line-height: 44px;
}

.who { text-align: center; font-style: italic; color: var(--ink-soft); margin: 0.25rem 0 0.75rem; }

/* His standing — the wall he has built, in numbers he can watch grow. */
.standing {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.3rem 1.1rem;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto 1rem;
  padding: 0.45rem 1.1rem;
  font-size: 0.98rem;
  border: 2px solid var(--ink-soft);
  border-radius: 999px;
  background: rgba(255, 250, 235, 0.6);
}
.standing b { color: var(--gold-deep); font-variant-numeric: tabular-nums; }

.panel {
  max-width: 500px;
  margin: 1rem auto;
  padding: clamp(1rem, 4vw, 1.5rem);
  border: 2px solid var(--ink-soft);
  border-radius: 10px 4px 12px 5px / 5px 12px 4px 10px;
  background: rgba(255, 250, 235, 0.62);
  text-align: center;
}
.panel h2 { margin-bottom: 0.5rem; }
.panel p { margin: 0.5rem 0; line-height: 1.45; }

.gw-note { text-align: center; font-style: italic; color: var(--ink-soft); margin: 0.5rem 0; }

.buttons { display: flex; flex-wrap: wrap; gap: 0.6rem; justify-content: center; margin-top: 1rem; }

/* ── Home: the four gates ─────────────────────────────────────────────────── */

.list-chip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin: 0 auto 1rem;
  max-width: 560px;
  padding: 0.5rem 0.9rem;
  border: 2px dashed var(--ink-faint);
  border-radius: 10px;
  font-size: 0.98rem;
}
.list-chip .realm-btn--quiet { margin-top: 0; min-height: 44px; }

.mode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: clamp(0.75rem, 2.5vw, 1.25rem);
  max-width: 720px;
  margin: 0 auto;
}

.mode-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  min-height: 132px;
  padding: 1rem;
  font: inherit;
  color: var(--ink);
  text-align: center;
  cursor: pointer;
  background: rgba(255, 250, 235, 0.55);
  border: 2px solid var(--ink-soft);
  border-radius: 12px 5px 10px 6px / 6px 10px 5px 12px;
  box-shadow: 0 4px 0 rgba(90, 65, 30, 0.25);
  transition: transform 0.12s ease;
}
.mode-card:active { transform: translateY(3px); box-shadow: none; }
.mode-card:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.mode-card__emoji { font-size: 1.9rem; }
.mode-card__name { font-weight: 700; font-size: 1.2rem; letter-spacing: 0.04em; }
.mode-card__blurb { font-size: 0.9rem; line-height: 1.35; color: #5b4526; max-width: 26ch; }
.mode-card__badge {
  position: absolute;
  top: -10px;
  right: -6px;
  min-width: 30px;
  padding: 0.25rem 0.5rem;
  font-weight: 700;
  color: #ffe9c9;
  background: linear-gradient(180deg, #b83a3a, var(--wax-dark));
  border-radius: 999px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}
.mode-card[disabled] { opacity: 0.55; cursor: default; }

.challenge-invite {
  max-width: 560px;
  margin: 1.25rem auto 0;
  padding: 0.9rem;
  text-align: center;
  border: 2px solid var(--gold-deep);
  border-radius: 10px;
  background: rgba(255, 244, 214, 0.7);
}
.challenge-invite p { margin-bottom: 0.6rem; line-height: 1.4; }

/* ── Lists ────────────────────────────────────────────────────────────────── */

#screen-lists .realm-btn { display: block; margin: 0.75rem auto; }

.list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.list-card {
  padding: 0.8rem 1rem;
  font: inherit;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
  background: rgba(255, 250, 235, 0.55);
  border: 2px solid var(--ink-soft);
  border-radius: 8px;
  min-height: 44px;
}
.list-card:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.list-slot { display: flex; flex-direction: column; }
.list-slot .list-card { flex: 1; }
.list-card__actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 0.35rem; }
.list-act {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.3rem 0.65rem;
  min-height: 44px;
  color: var(--ink);
  background: rgba(255, 250, 235, 0.55);
  border: 1.5px solid var(--ink-soft);
  border-radius: 8px;
  cursor: pointer;
}
.list-act:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.list-card--current { border-color: var(--gold-deep); box-shadow: 0 0 0 2px var(--gold); }
.list-card__title { font-weight: 700; font-size: 1.05rem; overflow-wrap: anywhere; }
.list-card__meta { font-size: 0.85rem; color: var(--ink-soft); margin-top: 0.2rem; }

/* ── Paste ────────────────────────────────────────────────────────────────── */

.paste-form { max-width: 560px; margin: 1rem auto; display: flex; flex-direction: column; gap: 0.8rem; }
.paste-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.paste-form input,
.paste-form textarea {
  font: inherit;
  font-size: 1.05rem; /* ≥16px or iOS zooms the page on focus */
  padding: 0.55rem 0.75rem;
  color: var(--ink);
  background: #fffaf0;
  border: 2px solid var(--ink-soft);
  border-radius: 7px;
  min-height: 48px;
}
.paste-form textarea { min-height: 8rem; resize: vertical; }
.paste-form input:focus-visible, .paste-form textarea:focus-visible { outline: 3px solid var(--gold); }
.paste-form .realm-btn { align-self: center; }

.paste-preview { border: 2px dashed var(--ink-faint); border-radius: 10px; padding: 0.75rem; }
.paste-preview h3 { font-size: 0.95rem; margin-bottom: 0.5rem; }
.paste-preview ul { list-style: none; display: flex; flex-wrap: wrap; gap: 0.45rem; }
.paste-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
  padding: 0.3rem 0.4rem 0.3rem 0.7rem;
  background: rgba(255, 250, 235, 0.8);
  border: 1.5px solid var(--ink-soft);
  border-radius: 999px;
  font-size: 1rem;
}
.paste-item span { overflow-wrap: anywhere; }
.paste-item--sentence, .paste-item--paragraph { border-radius: 10px; }
.paste-item button {
  font: inherit;
  min-width: 32px;
  min-height: 32px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--wax-dark);
  font-weight: 700;
  cursor: pointer;
}

/* ── Session chrome ───────────────────────────────────────────────────────── */

.session-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0;
  background: linear-gradient(180deg, var(--parchment) 82%, transparent);
}
.session-bar .realm-btn--quiet { margin-top: 0; min-height: 44px; }
.session-bar__progress { font-style: italic; color: var(--ink-soft); text-align: center; }

/* ── Learn stage ──────────────────────────────────────────────────────────── */

.learn-stage { display: flex; flex-direction: column; align-items: center; gap: 0.6rem; padding-top: 0.5rem; }

.learn-say { font-size: clamp(1.2rem, 4.5vw, 1.6rem); text-align: center; min-height: 1.4em; }
.learn-say .py { color: var(--gold-deep); font-weight: 700; letter-spacing: 0.05em; }

.learn-glyph {
  width: min(76vw, 44dvh, 360px);
  aspect-ratio: 1;
}

/* During the build beat the glyph area is an empty square waiting for its parts —
   visible, so the parts have somewhere to land. */
.learn-glyph--frame {
  border: 2px dashed var(--ink-faint);
  border-radius: 8px;
  background:
    linear-gradient(to right, transparent calc(50% - 0.5px), rgba(157, 43, 43, 0.12) calc(50% - 0.5px) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), rgba(157, 43, 43, 0.12) calc(50% - 0.5px) calc(50% + 0.5px), transparent calc(50% + 0.5px));
}
.learn-glyph svg { width: 100%; height: 100%; display: block; }

.learn-caption {
  font-size: clamp(1.05rem, 3.6vw, 1.35rem);
  text-align: center;
  min-height: 1.4em;
  font-family: 'Kaiti SC', 'KaiTi', 'STKaiti', serif;
}

.learn-hint-line { font-style: italic; color: var(--ink-soft); text-align: center; max-width: 46ch; line-height: 1.4; min-height: 1.4em; }

.learn-parts {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  max-width: 640px;
}

.part-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.5rem 0.6rem 0.4rem;
  font: inherit;
  color: var(--ink);
  background: rgba(255, 250, 235, 0.7);
  border: 2px solid var(--ink-soft);
  border-radius: 9px;
  min-width: 84px;
  min-height: 44px;
}
.part-card svg { width: 56px; height: 56px; }
.part-card__py { font-weight: 700; color: var(--gold-deep); font-size: 0.9rem; }
.part-card__def { font-size: 0.78rem; color: #5b4526; max-width: 14ch; text-align: center; line-height: 1.25; }
button.part-card { cursor: pointer; }
button.part-card:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.part-card--used { opacity: 0.35; }
.part-card--wrong { animation: wiggle 0.3s ease 2; border-color: var(--wax); }

@keyframes wiggle {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px) rotate(-2deg); }
  75% { transform: translateX(5px) rotate(2deg); }
}

.learn-next { margin-top: 0.4rem; }

/* Colours for the parts inside the glyph. Ink-compatible, distinguishable, AA on parchment. */
.part-c0 { fill: #2b1d0e; }
.part-c1 { fill: #8a4a1f; }
.part-c2 { fill: #1f5f4e; }
.part-c3 { fill: #6a3b8f; }
.part-c4 { fill: #a03535; }
.part-c5 { fill: #2f5d8a; }

/* ── The write screen: the 田字格 and the brush ───────────────────────────── */

.dictation { text-align: center; }
.dictation__pinyin { font-size: clamp(1.3rem, 5vw, 1.7rem); font-weight: 700; color: var(--gold-deep); letter-spacing: 0.06em; min-height: 1.3em; }
.dictation__meaning { font-style: italic; color: var(--ink-soft); min-height: 1.3em; margin-top: 0.15rem; overflow-wrap: anywhere; }
.dictation__story { font-size: 0.9rem; color: var(--ink-soft); margin-top: 0.15rem; overflow-wrap: anywhere; }

.dictation__boxes {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.3rem;
  margin: 0.4rem auto;
  max-width: 620px;
}

.dict-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 2.6rem;
  border: 1.5px solid var(--ink-faint);
  border-radius: 4px;
  background: rgba(255, 250, 235, 0.5);
}
.dict-box__py { font-size: 0.62rem; color: var(--gold-deep); min-height: 0.95rem; line-height: 0.95rem; font-family: inherit; }
.dict-box__ch { font-size: 1.5rem; line-height: 1.9rem; min-height: 1.9rem; }
.dict-box--current { border-color: var(--gold-deep); box-shadow: 0 0 0 2px var(--gold); background: #fff8e3; }
.dict-box--done .dict-box__ch { color: var(--ink); }
.dict-box--missed .dict-box__ch { color: var(--wax-dark); }
.dict-box--punct { border-color: transparent; background: transparent; width: 1.5rem; }
.dict-box--given { opacity: 0.75; }

.grid-box {
  position: relative;
  width: min(84vw, 46dvh, 420px);
  aspect-ratio: 1;
  margin: 0.5rem auto;
  background: #fffdf5;
  border: 3px solid var(--ink);
  border-radius: 6px;
  /* The 田字格: the dashed cross every Chinese exercise book rules into each square.
     Children are taught to PLACE strokes by it — it is also what makes stroke position
     fair for the judge. */
  background-image:
    linear-gradient(to right, transparent calc(50% - 1px), rgba(157, 43, 43, 0.28) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(to bottom, transparent calc(50% - 1px), rgba(157, 43, 43, 0.28) calc(50% - 1px) calc(50% + 1px), transparent calc(50% + 1px)),
    linear-gradient(45deg, transparent calc(50% - 0.5px), rgba(157, 43, 43, 0.14) calc(50% - 0.5px) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(-45deg, transparent calc(50% - 0.5px), rgba(157, 43, 43, 0.14) calc(50% - 0.5px) calc(50% + 0.5px), transparent calc(50% + 0.5px));
  touch-action: none; /* the finger draws; the page must not scroll out from under it */
}

.grid-box__ink { position: absolute; inset: 0; width: 100%; height: 100%; }

/* His ink, the ghost's ink, and the answer's ink. */
.ink-user { fill: none; stroke: var(--ink); stroke-width: 46; stroke-linecap: round; stroke-linejoin: round; }
.ink-live { stroke: #3a2a14; opacity: 0.9; }
.ink-bad { stroke: var(--wax); animation: fadeout 0.6s ease forwards; }
.ink-ghost { fill: rgba(43, 29, 14, 0.16); }
.ink-ghost-stroke { fill: rgba(157, 43, 43, 0.30); }
.ink-done { fill: var(--ink); }

@keyframes fadeout { to { opacity: 0; } }

.write-feedback { text-align: center; min-height: 1.5em; font-weight: 700; }
.write-feedback--good { color: #1f5f34; }
.write-feedback--bad { color: var(--wax-dark); }

.write-controls { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; }
.write-controls .realm-btn--quiet { margin-top: 0; }
.write-hint-cost { text-align: center; font-size: 0.85rem; font-style: italic; color: var(--ink-soft); margin-top: 0.4rem; }

/* Stroke-by-stroke reveal: the median, drawn fat, clipped inside the true stroke
   outline — the way a brush actually fills a stroke in. */
.anim-stroke {
  fill: none;
  stroke: var(--ink);
  stroke-linecap: round;
  stroke-linejoin: round;
  animation: draw-stroke var(--dur, 0.5s) ease-out forwards;
  animation-delay: var(--delay, 0s);
  stroke-dasharray: var(--len) var(--len);
  stroke-dashoffset: var(--len);
  opacity: 0;
}
@keyframes draw-stroke {
  0% { opacity: 1; stroke-dashoffset: var(--len); }
  100% { opacity: 1; stroke-dashoffset: 0; }
}

/* ── Rest card ────────────────────────────────────────────────────────────── */

.rest-panel .realm-btn { margin: 0.5rem 0.3rem 0; }
.rest-progress { display: flex; justify-content: center; gap: 0.35rem; margin: 0.75rem 0; flex-wrap: wrap; }
.rest-progress span {
  width: 26px; height: 14px;
  border: 1.5px solid var(--ink-soft);
  border-radius: 3px;
  background: transparent;
}
.rest-progress span.laid { background: var(--gold); border-color: var(--gold-deep); }

/* ── Summary ──────────────────────────────────────────────────────────────── */

.summary-tiles { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; max-width: 640px; margin: 1rem auto; }
.summary-tile {
  display: flex; flex-direction: column; align-items: center; gap: 0.1rem;
  padding: 0.5rem 0.7rem;
  border: 2px solid var(--ink-soft); border-radius: 9px;
  background: rgba(255, 250, 235, 0.7);
  min-width: 74px;
}
.summary-tile .hanzi { font-size: 1.9rem; }
.summary-tile__note { font-size: 0.78rem; color: #5b4526; text-align: center; max-width: 16ch; }
.summary-tile--up {
  border-color: var(--gold-deep);
  box-shadow: 0 0 0 2px var(--gold);
  animation: brick-pop 0.55s ease;
}

@keyframes brick-pop {
  0% { transform: scale(0.4) rotate(-6deg); }
  65% { transform: scale(1.15) rotate(2deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ── The wall ─────────────────────────────────────────────────────────────── */

.wall-tabs { display: flex; justify-content: center; gap: 0.4rem; margin: 0.6rem 0 0.8rem; flex-wrap: wrap; }
.wall-tab {
  font: inherit;
  min-height: 44px;
  padding: 0.5rem 1rem;
  cursor: pointer;
  color: var(--ink);
  background: transparent;
  border: 2px solid var(--ink-soft);
  border-radius: 999px;
}
.wall-tab[aria-selected='true'] { background: var(--ink); color: var(--parchment-lit); border-color: var(--ink); }
.wall-tab:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.wall-legend { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.7rem; font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 0.5rem; }
.wall-legend__item { display: inline-flex; align-items: center; gap: 0.3rem; }
.tile-swatch {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px;
  font-size: 0.95rem;
  border-radius: 4px;
  border: 1px solid rgba(43, 29, 14, 0.4);
}

.wall-section { margin-bottom: 1rem; }
.wall-section__bar {
  flex-basis: 100%;
  height: 7px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.wall-section__bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--gold-deep), var(--gold));
  border-radius: 4px;
  transition: width 0.6s ease;
}
.wall-section__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.3rem;
  padding: 0.35rem 0.6rem;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
  color: var(--parchment-lit);
  background: linear-gradient(180deg, #6b5330, #4a3820);
  border-radius: 6px;
}
.wall-section__head strong { letter-spacing: 0.05em; }

.wall-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); /* 44px = a finger */
  gap: 4px;
  min-height: 46px; /* lazy sections keep their height before they render */
}

.wall-tile {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  font: inherit;
  font-size: clamp(1.05rem, 4vw, 1.4rem);
  cursor: pointer;
  border-radius: 4px;
  border: 1px solid rgba(43, 29, 14, 0.35);
  padding: 0;
}
.wall-tile:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px; z-index: 1; }

/* Brick states. Grey face-down bricks NEVER show their glyph — that is what keeps
   the blind Challenge honest. The legend's swatches share these exact colours, so
   the legend can never drift out of truth with the wall. */
.wall-tile--unmet, .tile-swatch--unmet { background: #d8cdb4; color: #6f6146; }
.wall-tile--met, .tile-swatch--met { background: #e4dcc6; color: #4f4126; }
.wall-tile--climbing, .tile-swatch--climbing { background: linear-gradient(180deg, #d3a06b, var(--brick)); color: var(--ink); }
.wall-tile--claimed, .tile-swatch--claimed { background: linear-gradient(180deg, #e8e6e0, #b9b7ae); color: var(--ink); border-color: #8f8d84; }
.wall-tile--conquered, .tile-swatch--conquered { background: linear-gradient(180deg, #eec95c, var(--gold-deep)); color: var(--ink); border-color: var(--gold-deep); }
.wall-tile--slipping, .tile-swatch--slipping { animation: slip-pulse 2.2s ease-in-out infinite; }

@keyframes slip-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.wall-tile__flag { position: absolute; top: -4px; right: -2px; font-size: 0.7rem; }
.wall-tile__medal { position: absolute; bottom: -3px; right: -2px; font-size: 0.62rem; }

/* ── Compare ──────────────────────────────────────────────────────────────── */

.compare-picker { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.5rem; margin: 0.75rem 0; }

/* One rival, achievements on the card — the same chips the home screen shows for YOU. */
.rival-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.55rem 0.9rem;
  border: 2px solid var(--ink-soft);
  border-radius: 10px;
  background: rgba(255, 250, 235, 0.55);
  font: inherit;
  cursor: pointer;
}
.rival-card__name { font-weight: 700; font-size: 1.02rem; }
.rival-card__chips { font-size: 0.82rem; color: var(--ink-soft); white-space: nowrap; }
.rival-card__chips b { color: var(--gold-deep); font-variant-numeric: tabular-nums; }
.rival-card[aria-pressed='true'] { background: var(--ink); border-color: var(--ink); }
.rival-card[aria-pressed='true'] .rival-card__name,
.rival-card[aria-pressed='true'] .rival-card__chips { color: var(--parchment-lit); }
.rival-card[aria-pressed='true'] .rival-card__chips b { color: var(--gold); }
.rival-card:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.hit-list { margin-top: 0.75rem; }
.hit-list h3 { text-align: center; margin-bottom: 0.5rem; }
.hit-list__tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 4px;
}

/* The rival's whole climb, below the hit list. Their rung colours the brick; your
   medal sits top-left when you hold it too — the race, on one tile. */
.rival-wall { margin-top: 1.1rem; }
.rival-wall__title { text-align: center; margin-bottom: 0.35rem; }
.rival-group { margin-top: 0.75rem; }
.rival-group h4 { font-size: 0.92rem; margin-bottom: 0.35rem; }
.rival-group h4 span { font-weight: 400; color: var(--ink-soft); font-size: 0.82rem; margin-left: 0.35rem; }
.wall-tile__mine { position: absolute; top: -3px; left: -2px; font-size: 0.62rem; }

/* ── The Seek gate ────────────────────────────────────────────────────────── */

.seek-form { display: flex; gap: 0.5rem; justify-content: center; margin: 0.75rem 0; }
.seek-form input {
  flex: 1;
  max-width: 320px;
  min-width: 0;
  padding: 0.55rem 0.75rem;
  border: 2px solid var(--ink-soft);
  border-radius: 10px;
  background: rgba(255, 250, 235, 0.8);
  font: inherit;
  font-size: 1.05rem;
}
.seek-form input:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px; }
.seek-form .realm-btn { margin-top: 0; }

.seek-results { display: flex; flex-direction: column; gap: 0.5rem; max-width: 560px; margin: 0.5rem auto 0; }
.seek-card {
  display: flex;
  flex-wrap: wrap; /* a 320px phone drops the button to its own row rather than starve the words */
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border: 2px solid var(--ink-faint);
  border-radius: 10px;
  background: rgba(255, 250, 235, 0.55);
}
.seek-card__glyph {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  border: 1px solid rgba(63, 48, 26, 0.25);
  font-size: 1.9rem;
}
.seek-card__glyph--hidden { background: #d8cdb4; font-size: 1.15rem; }
.seek-card__body { flex: 1 1 150px; min-width: 0; line-height: 1.35; }
.seek-card__body small { display: block; color: var(--ink-soft); }
.seek-card .realm-btn--quiet { margin-top: 0; flex: 0 0 auto; white-space: nowrap; margin-left: auto; }

/* ── The board ────────────────────────────────────────────────────────────── */

.board__scroll { overflow-x: auto; }
.board { width: 100%; border-collapse: collapse; min-width: 420px; }
.board th, .board td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--ink-faint); }
.board th { font-size: 0.78rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-soft); }
.board td.num, .board th.num { text-align: right; font-variant-numeric: tabular-nums; }
.board tr.me td { background: rgba(201, 150, 46, 0.18); font-weight: 700; }

.board-rules {
  max-width: 620px;
  margin: 1.25rem auto 0;
  padding: 0.9rem 1.1rem;
  border: 2px solid var(--ink-soft);
  border-radius: 10px;
  background: rgba(255, 250, 235, 0.55);
}
.board-rules h3 { font-size: 1rem; margin-bottom: 0.5rem; }
.board-rules ul { padding-left: 1.1rem; }
.board-rules li { margin: 0.35rem 0; line-height: 1.45; font-size: 0.95rem; }

/* ── Tile sheet ───────────────────────────────────────────────────────────── */

.tile-sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(36, 26, 16, 0.55);
}
.tile-sheet__card {
  position: relative;
  width: min(100%, 560px);
  max-height: 82dvh;
  overflow-y: auto;
  /* This sheet sits ON the bottom edge — exactly where iPhone Safari steals the first
     tap to reveal its toolbar. The extra bottom padding keeps both buttons above that. */
  padding: 1.1rem 1.2rem calc(2.2rem + env(safe-area-inset-bottom, 0px));
  background: var(--parchment-lit);
  border: 2px solid var(--ink);
  border-radius: 14px 14px 0 0;
}
.tile-sheet__close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  min-width: 44px;
  min-height: 44px;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: transparent;
  border: none;
  cursor: pointer;
}
.tile-glyph { font-size: 3.2rem; text-align: center; }
.tile-mystery { font-size: 2.2rem; text-align: center; }
.tile-facts { list-style: none; margin: 0.6rem 0; }
.tile-facts li { padding: 0.3rem 0; border-bottom: 1px dashed var(--ink-faint); font-size: 0.98rem; display: flex; justify-content: space-between; gap: 1rem; }
.tile-facts li span:last-child { text-align: right; }
.tile-sheet .buttons { margin-top: 0.75rem; }
.tile-warn { font-size: 0.88rem; font-style: italic; color: var(--wax-dark); text-align: center; margin-top: 0.5rem; }

/* Everyone's grip on this one brick: a name, five rungs, a badge. */
.tile-builders { margin-top: 1rem; }
.tile-builders__title { font-size: 0.95rem; margin-bottom: 0.4rem; }
.tile-builders__list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 30dvh;
  overflow-y: auto;
}
.tile-builder {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.3rem 0.5rem;
  border-radius: 7px;
  font-size: 0.95rem;
}
.tile-builder--me { background: rgba(201, 150, 46, 0.2); font-weight: 700; }
.tile-builder__name { flex: 1; overflow-wrap: anywhere; }
.tile-builder__ladder { display: inline-flex; gap: 3px; }
.rung {
  width: 15px;
  height: 11px;
  border: 1px solid var(--ink-soft);
  border-radius: 2px;
  background: transparent;
}
.rung--on { background: linear-gradient(180deg, #d3a06b, #b08760); border-color: #7c5c38; }
.rung--top.rung--on { background: linear-gradient(180deg, #eec95c, var(--gold-deep)); border-color: var(--gold-deep); }
.tile-builder__badge { min-width: 1.4em; text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .anim-stroke { animation-duration: 0.01s !important; }
  .wall-tile--slipping, .tile-swatch--slipping { animation: none; opacity: 0.6; }
  .summary-tile--up { animation: none; }
}
