/* ==========================================================================
   Build-a-Cryptic — Editorial Newsprint Puzzle Design System
   Mobile baseline: 375x812px with ZERO vertical scrolling during active play
   ========================================================================== */

:root {
  --bg: #FAF8F3;
  --surface: #FFFFFF;
  --surface-subtle: #F2EFE7;
  --ink: #1A1917;
  --ink-muted: #5F5B53;
  --ink-faint: #918B80;
  --border: #D9D3C7;
  --border-strong: #B9B1A2;
  --accent: #1A1917;
  --accent-contrast: #FAF8F3;

  /* Feedback palette — Standard */
  --exact-bg: #2E7D4F;
  --exact-tint: #E7F4EC;
  --exact-border: #24633E;
  --exact-text: #FFFFFF;
  --exact-tint-text: #1B5232;

  --misplaced-bg: #C48315;
  --misplaced-tint: #FDF3DC;
  --misplaced-border: #9E670B;
  --misplaced-text: #FFFFFF;
  --misplaced-tint-text: #7A4E04;

  --elim-bg: #6C6F73;
  --elim-tint: #EAE7DF;
  --elim-border: #B8B3A8;
  --elim-text: #FFFFFF;
  --elim-tint-text: #7D7A73;
  --elim-hatch: rgba(26, 25, 23, 0.08);

  --role-def: #2B5D82;
  --role-ind: #8A4B1A;
  --role-fod: #5D3E7A;

  --font-serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-tile: 0 2px 0 rgba(26, 25, 23, 0.12);
  --shadow-float: 0 12px 28px rgba(26, 25, 23, 0.22);
}

html.dark-mode {
  --bg: #141518;
  --surface: #1E2025;
  --surface-subtle: #262930;
  --ink: #F2EEE6;
  --ink-muted: #ABA59A;
  --ink-faint: #757068;
  --border: #343841;
  --border-strong: #4C5260;
  --accent: #F2EEE6;
  --accent-contrast: #141518;

  --exact-bg: #358F5B;
  --exact-tint: #1B3325;
  --exact-border: #49B074;
  --exact-tint-text: #9CE0B8;

  --misplaced-bg: #C88A1E;
  --misplaced-tint: #362912;
  --misplaced-border: #E2A83B;
  --misplaced-tint-text: #F5CE7E;

  --elim-bg: #4A4E57;
  --elim-tint: #23262C;
  --elim-border: #3A3F4A;
  --elim-tint-text: #777B84;
  --elim-hatch: rgba(255, 255, 255, 0.07);

  --role-def: #6BAED6;
  --role-ind: #E8A464;
  --role-fod: #BA9CE0;

  --shadow-tile: 0 2px 0 rgba(0, 0, 0, 0.45);
  --shadow-float: 0 12px 30px rgba(0, 0, 0, 0.6);
}

html.high-contrast {
  --exact-bg: #D95F02;
  --exact-tint: #FDECE0;
  --exact-border: #A84700;
  --exact-text: #FFFFFF;
  --exact-tint-text: #8F3B00;

  --misplaced-bg: #1F6FEB;
  --misplaced-tint: #E2EEFF;
  --misplaced-border: #1450B2;
  --misplaced-text: #FFFFFF;
  --misplaced-tint-text: #0F4294;

  --elim-hatch: rgba(26, 25, 23, 0.15);
}

html.dark-mode.high-contrast {
  --exact-bg: #E86A0C;
  --exact-tint: #3A1F0C;
  --exact-border: #FF8B33;
  --exact-tint-text: #FFB57A;

  --misplaced-bg: #2E82FF;
  --misplaced-tint: #122847;
  --misplaced-border: #68A5FF;
  --misplaced-tint-text: #9BC4FF;

  --elim-hatch: rgba(255, 255, 255, 0.14);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--misplaced-bg);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* ==========================================================================
   App Shell & Masthead
   ========================================================================== */

.app-shell {
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.topbar {
  height: 46px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 4px;
  padding: 0 10px;
  border-bottom: 1.5px solid var(--border);
  background: var(--bg);
}

.brand-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 0.98rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: center;
  white-space: nowrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 32px;
  min-width: 30px;
  padding: 0 5px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  transition: background 120ms ease, border-color 120ms ease;
}

.icon-btn:hover {
  background: var(--surface-subtle);
  border-color: var(--border);
}

.icon-btn--labeled {
  justify-self: start;
  padding: 0 5px 0 3px;
}

.icon-glyph {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
}

.icon-label {
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
  white-space: nowrap;
}

@media (max-width: 400px) {
  .icon-label {
    display: none;
  }
}

/* ==========================================================================
   Main Board Layout (Zero-Scroll 375x812px Budget)
   ========================================================================== */

.board {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 10px 12px 12px;
}

.section-label {
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  color: var(--ink-muted);
  text-transform: uppercase;
}

.section-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 5px;
}

.section-hint {
  font-size: 0.65rem;
  color: var(--ink-faint);
}

/* Target Word Banner */
.target-banner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px 10px;
  text-align: center;
  box-shadow: 0 1px 2px rgba(26, 25, 23, 0.04);
}

.target-meta-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 6px;
}

.puzzle-tag {
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}

.back-daily-btn {
  border: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.64rem;
  font-weight: 600;
  color: var(--ink);
}

.target-word {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.target-letters {
  display: inline-flex;
  gap: 4px;
}

.target-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 32px;
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  background: var(--bg);
  font-family: var(--font-serif);
  font-size: 1.18rem;
  font-weight: 700;
  line-height: 1;
}

.target-enum {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink-muted);
}

/* Guess History Stack */
.history-section {
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 7px 9px;
  min-height: 54px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 5px;
}

.history-empty {
  font-size: 0.78rem;
  color: var(--ink-muted);
  text-align: center;
  padding: 6px 4px;
  font-style: italic;
  font-family: var(--font-serif);
}

.history-row {
  display: grid;
  grid-template-columns: 16px 1fr;
  align-items: center;
  gap: 5px;
}

.history-num {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--ink-faint);
}

.history-pills {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 5px;
}

.history-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3px;
  min-height: 26px;
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.15;
  overflow: hidden;
  border: 2px solid transparent;
}

.history-pill-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-pill-mark {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  opacity: 0.9;
}

.history-pill.state--exact {
  background: var(--exact-bg);
  color: var(--exact-text);
  border-color: var(--exact-border);
  border-style: solid;
}

.history-pill.state--misplaced {
  background: var(--misplaced-bg);
  color: var(--misplaced-text);
  border-color: var(--misplaced-border);
  border-style: dashed;
}

.history-pill.state--eliminated {
  background-color: var(--elim-bg);
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 4px,
    rgba(255, 255, 255, 0.12) 4px,
    rgba(255, 255, 255, 0.12) 8px
  );
  color: var(--elim-text);
  border-color: var(--elim-bg);
}

/* Active Clue Tray */
.tray-section {
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 8px 9px 9px;
}

.tray-slots {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 6px;
}

.tray-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 58px;
  padding: 6px 5px;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg);
  text-align: center;
  touch-action: none;
  user-select: none;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.tray-slot--filled {
  border-style: solid;
  border-color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow-tile);
}

.tray-slot--filled.state--exact {
  background: var(--exact-tint);
  border-color: var(--exact-bg);
  border-style: solid;
  border-width: 2px;
}

.tray-slot--filled.state--misplaced {
  background: var(--misplaced-tint);
  border-color: var(--misplaced-bg);
  border-style: dashed;
  border-width: 2px;
}

.tray-slot--drop-hover {
  transform: scale(1.03);
  border-color: var(--exact-bg);
  border-style: solid;
  background: var(--exact-tint);
}

.slot-role {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
}

.slot-value {
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--ink);
  word-break: break-word;
}

.slot-value--empty {
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--ink-faint);
  font-style: italic;
}

.live-preview-bar {
  margin-top: 7px;
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  line-height: 1.3;
  display: flex;
  align-items: baseline;
  gap: 5px;
  flex-wrap: wrap;
}

.preview-caption {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.live-preview-text {
  font-family: var(--font-serif);
  font-size: 0.94rem;
  font-weight: 600;
  color: var(--ink);
}

.preview-quote {
  color: var(--ink-faint);
}

.preview-token--blank {
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  letter-spacing: 0.02em;
}

.preview-token--filled {
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 2px;
}

.preview-token--definition {
  text-decoration-color: var(--role-def);
}

.preview-token--indicator {
  text-decoration-color: var(--role-ind);
}

.preview-token--fodder {
  text-decoration-color: var(--role-fod);
}

.preview-enum {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-muted);
  margin-left: 2px;
}

/* ==========================================================================
   3x3 Phrase Tile Bank
   ========================================================================== */

.bank-section {
  flex-shrink: 0;
}

.tile-bank {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.bank-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 10px 6px 8px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  box-shadow: var(--shadow-tile);
  text-align: center;
  touch-action: none;
  user-select: none;
  transition: transform 110ms ease, background 140ms ease, border-color 140ms ease, opacity 140ms ease;
}

.bank-tile:not(:disabled):hover {
  border-color: var(--ink);
  transform: translateY(-1px);
}

.bank-tile:not(:disabled):active {
  transform: translateY(1px);
}

.tile-text {
  font-size: 0.81rem;
  font-weight: 600;
  line-height: 1.18;
  color: var(--ink);
  word-break: break-word;
}

.tile-keycap {
  position: absolute;
  top: 3px;
  left: 5px;
  font-family: var(--font-mono);
  font-size: 0.56rem;
  font-weight: 600;
  color: var(--ink-faint);
  line-height: 1;
}

html.hide-key-hints .tile-keycap {
  display: none;
}

.tile-badge {
  position: absolute;
  top: 3px;
  right: 4px;
  padding: 1px 4px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.53rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.15;
}

.tile-badge--exact {
  background: var(--exact-bg);
  color: var(--exact-text);
}

.tile-badge--misplaced {
  background: var(--misplaced-bg);
  color: var(--misplaced-text);
}

.tile-badge--placed {
  background: var(--ink);
  color: var(--bg);
}

/* Bank Persistence States */
.bank-tile.state--exact {
  background: var(--exact-tint);
  border: 2px solid var(--exact-bg);
}

.bank-tile.state--exact .tile-text {
  color: var(--exact-tint-text);
}

.bank-tile.state--misplaced {
  background: var(--misplaced-tint);
  border: 2px dashed var(--misplaced-bg);
}

.bank-tile.state--misplaced .tile-text {
  color: var(--misplaced-tint-text);
}

.bank-tile.state--eliminated {
  background-color: var(--elim-tint);
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 5px,
    var(--elim-hatch) 5px,
    var(--elim-hatch) 10px
  );
  border: 1.5px solid var(--elim-border);
  box-shadow: none;
  opacity: 0.62;
  cursor: not-allowed;
}

.bank-tile.state--eliminated .tile-text {
  color: var(--elim-tint-text);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.bank-tile--in-tray {
  opacity: 0.45;
  box-shadow: none;
  transform: scale(0.97);
}

.is-dragging-source {
  opacity: 0.3 !important;
}

/* Floating Drag Ghost */
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 900;
  pointer-events: none;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--ink);
  color: var(--bg);
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: var(--shadow-float);
  white-space: nowrap;
}

/* ==========================================================================
   Action Controls Bar
   ========================================================================== */

.controls-bar {
  display: grid;
  grid-template-columns: 1fr 1.45fr;
  gap: 8px;
  margin-top: 2px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  border: 1.5px solid transparent;
  transition: transform 100ms ease, opacity 140ms ease, background 140ms ease;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.btn--secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border-strong);
}

.btn--control {
  height: 44px;
}

.btn--full {
  width: 100%;
}

/* ==========================================================================
   Post-Solve X-Ray Breakdown Card
   ========================================================================== */

.xray-card {
  background: var(--surface);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 13px 12px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  animation: xraySlideIn 320ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.xray-card--won {
  border-color: var(--exact-bg);
}

.xray-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.xray-verdict {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 0.88rem;
}

.xray-verdict-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--exact-bg);
}

.xray-card--lost .xray-verdict-dot {
  background: var(--misplaced-bg);
}

.xray-type-pill {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.xray-clue-sentence {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  padding: 9px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}

.xray-part {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.xray-part-text {
  font-family: var(--font-serif);
  font-size: 1.05rem;
  font-weight: 700;
  padding-bottom: 2px;
  border-bottom: 2.5px solid var(--ink);
}

.xray-part--def .xray-part-text { border-color: var(--role-def); }
.xray-part--ind .xray-part-text { border-color: var(--role-ind); }
.xray-part--fod .xray-part-text { border-color: var(--role-fod); }

.xray-part-tag {
  font-family: var(--font-mono);
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}

.xray-enum {
  font-family: var(--font-mono);
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--ink-muted);
  align-self: center;
  padding-bottom: 12px;
}

.xray-stage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  border: 1px dashed var(--border-strong);
}

.xray-letters,
.xray-hidden-phrase,
.xray-charade-parts {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
}

.xray-char {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 24px;
  padding: 0 3px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
}

.xray-char--fodder {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--ink);
  animation: xrayPop 360ms ease var(--delay, 0ms) both;
}

.xray-char--target,
.xray-char--highlight {
  background: var(--exact-bg);
  color: var(--exact-text);
  border: 1px solid var(--exact-border);
  animation: xrayPop 380ms cubic-bezier(0.2, 1.3, 0.4, 1) var(--delay, 0ms) both;
}

.xray-char--muted {
  min-width: 14px;
  padding: 0 1px;
  color: var(--ink-faint);
  font-weight: 500;
}

.xray-char--deleted {
  background: var(--elim-tint);
  color: var(--elim-tint-text);
  border: 1px dashed var(--elim-border);
  text-decoration: line-through;
  text-decoration-thickness: 2px;
  opacity: 0.55;
  animation: xrayStrike 420ms ease var(--delay, 0ms) both;
}

.xray-space {
  width: 6px;
}

.xray-op {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.xray-def-eq {
  font-family: var(--font-serif);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
}

.xray-word-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--exact-bg);
  color: var(--exact-text);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.xray-word-pill--fodder {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border-strong);
}

.xray-soundwave {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--misplaced-bg);
  animation: xrayPulse 1.4s ease-in-out infinite;
}

.xray-ipa {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--ink-muted);
}

.xray-charade-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 3px 6px;
  border-radius: 5px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  font-size: 0.72rem;
  animation: xrayPop 360ms ease var(--delay, 0ms) both;
}

.xray-charade-clue {
  color: var(--ink-muted);
}

.xray-charade-arrow {
  color: var(--ink-faint);
}

.xray-charade-res {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--exact-bg);
}

.xray-plus {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--ink-muted);
  margin: 0 2px;
}

.xray-explanation {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--ink-muted);
  text-align: center;
}

.xray-actions {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 6px;
}

.xray-countdown {
  text-align: center;
  font-size: 0.72rem;
  color: var(--ink-muted);
  padding-top: 2px;
  border-top: 1px solid var(--border);
}

.xray-countdown-value {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--ink);
}

/* ==========================================================================
   Modals
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: rgba(18, 17, 15, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(2px);
}

.modal-panel {
  width: 100%;
  max-width: 440px;
  max-height: 86dvh;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-float);
  animation: modalFadeIn 180ms ease both;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--ink-muted);
}

.modal-close:hover {
  background: var(--surface-subtle);
  color: var(--ink);
}

.modal-body {
  padding: 14px 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-lead {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--ink-muted);
}

.modal-subhead {
  margin: 4px 0 0;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.howto-slots,
.howto-legend,
.guide-archetype-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.howto-slot-card {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 0.8rem;
  line-height: 1.35;
}

.howto-slot-badge {
  flex-shrink: 0;
  width: 82px;
  text-align: center;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--surface-subtle);
  border: 1px solid var(--border-strong);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 700;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.8rem;
  line-height: 1.35;
}

.legend-chip {
  flex-shrink: 0;
  width: 78px;
  text-align: center;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  border: 2px solid transparent;
}

.legend-chip.state--exact {
  background: var(--exact-bg);
  color: var(--exact-text);
  border-color: var(--exact-border);
  border-style: solid;
}

.legend-chip.state--misplaced {
  background: var(--misplaced-bg);
  color: var(--misplaced-text);
  border-color: var(--misplaced-border);
  border-style: dashed;
}

.legend-chip.state--eliminated {
  background-color: var(--elim-bg);
  background-image: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 4px,
    rgba(255, 255, 255, 0.14) 4px,
    rgba(255, 255, 255, 0.14) 8px
  );
  color: var(--elim-text);
}

.guide-archetype {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  border: 1px solid var(--border);
}

.guide-archetype-title {
  font-size: 0.8rem;
  font-weight: 700;
}

.guide-archetype-mech {
  font-size: 0.75rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

.guide-archetype-ex {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink);
  margin-top: 4px;
}

.modal-footnote {
  margin: 2px 0 0;
  font-size: 0.76rem;
  color: var(--ink-muted);
  line-height: 1.45;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

/* Stats Modal */
.stats-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.kpi-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 4px;
  text-align: center;
}

.kpi-val {
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.1;
}

.kpi-label {
  font-size: 0.64rem;
  font-weight: 600;
  color: var(--ink-muted);
  margin-top: 3px;
}

.dist-chart,
.mastery-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.dist-row {
  display: grid;
  grid-template-columns: 16px 1fr;
  align-items: center;
  gap: 8px;
}

.dist-num {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--ink-muted);
}

.dist-track {
  background: var(--surface-subtle);
  border-radius: 4px;
  overflow: hidden;
}

.dist-bar {
  background: var(--elim-bg);
  color: #FFFFFF;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 7px;
  text-align: right;
  border-radius: 4px;
  min-width: 24px;
}

.dist-bar--highlight {
  background: var(--exact-bg);
}

.mastery-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mastery-head {
  display: flex;
  justify-content: space-between;
  font-size: 0.76rem;
}

.mastery-name {
  font-weight: 600;
}

.mastery-score {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.mastery-track {
  height: 7px;
  border-radius: 999px;
  background: var(--surface-subtle);
  overflow: hidden;
}

.mastery-fill {
  height: 100%;
  background: var(--exact-bg);
  border-radius: 999px;
  transition: width 320ms ease;
}

.stats-share-footer {
  padding-top: 4px;
}

/* Archive Modal */
.archive-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.archive-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  text-align: left;
  transition: border-color 120ms ease, background 120ms ease;
}

.archive-item:hover {
  border-color: var(--ink);
  background: var(--surface-subtle);
}

.archive-item--active {
  border-color: var(--ink);
  border-width: 1.5px;
}

.archive-item-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.84rem;
  font-weight: 700;
}

.archive-today-pill {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-family: var(--font-mono);
  font-size: 0.56rem;
  font-weight: 700;
}

.archive-item-sub {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

.archive-status {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
}

.archive-status--won {
  background: var(--exact-tint);
  color: var(--exact-tint-text);
  border: 1px solid var(--exact-bg);
}

.archive-status--lost {
  background: var(--elim-tint);
  color: var(--elim-tint-text);
  border: 1px solid var(--elim-border);
}

.archive-status--playing {
  background: var(--surface);
  color: var(--ink-muted);
  border: 1px solid var(--border-strong);
}

/* Settings Modal */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.setting-row:last-child {
  border-bottom: none;
}

.setting-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-name {
  font-size: 0.86rem;
  font-weight: 600;
}

.setting-desc {
  font-size: 0.74rem;
  color: var(--ink-muted);
  line-height: 1.35;
}

.toggle-input {
  appearance: none;
  flex-shrink: 0;
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background 150ms ease;
}

.toggle-input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #FFFFFF;
  transition: transform 150ms ease;
}

.toggle-input:checked {
  background: var(--exact-bg);
}

.toggle-input:checked::after {
  transform: translateX(18px);
}

/* ==========================================================================
   Toast & Confetti
   ========================================================================== */

.toast-container {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 950;
  pointer-events: none;
}

.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  box-shadow: var(--shadow-float);
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 160ms ease, transform 160ms ease;
  white-space: nowrap;
}

.toast--visible {
  opacity: 1;
  transform: translateY(0);
}

.confetti-host {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 920;
}

.confetti-piece {
  position: absolute;
  top: 18%;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  animation: confettiDrop 1.3s cubic-bezier(0.2, 0.7, 0.3, 1) forwards;
}

/* ==========================================================================
   Animations
   ========================================================================== */

@keyframes tileFlip {
  0% { transform: perspective(360px) rotateX(0deg); }
  45% { transform: perspective(360px) rotateX(88deg); }
  100% { transform: perspective(360px) rotateX(0deg); }
}

.anim-flip {
  animation: tileFlip 420ms ease both;
}

@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(3px); }
}

.anim-shake {
  animation: shakeX 280ms ease;
}

@keyframes xraySlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes xrayPop {
  from { opacity: 0; transform: translateY(6px) scale(0.85); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes xrayStrike {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0.5; transform: scale(0.92); }
}

@keyframes xrayPulse {
  0%, 100% { transform: scale(1); opacity: 0.75; }
  50% { transform: scale(1.18); opacity: 1; }
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes confettiDrop {
  0% {
    opacity: 1;
    transform: translate3d(0, 0, 0) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--dx, 0px), 340px, 0) rotate(var(--rot, 360deg));
  }
}

/* Compact short-screen adaptation (e.g. 667px iPhone SE) */
@media (max-height: 700px) {
  .board {
    gap: 6px;
    padding: 7px 10px 9px;
  }
  .target-banner {
    padding: 6px 8px 7px;
  }
  .target-letter {
    width: 26px;
    height: 28px;
    font-size: 1.05rem;
  }
  .tray-slot {
    min-height: 50px;
  }
  .bank-tile {
    min-height: 48px;
    padding: 8px 5px 6px;
  }
  .btn--control {
    height: 40px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
