/* ==========================================================================
   Cluesmith — Flat Editorial & Tactile Print Design System
   Newsreader + Atkinson Hyperlegible Next, zero drop shadows,
   calm newsprint board + crisp flat-bordered tiles, ALL CAPS clues only
   ========================================================================== */

:root {
  --bg: #F4EFE6;
  --surface: #FCFBF7;
  --surface-hover: #F5F0E6;
  --surface-subtle: #EAE3D5;
  --ink: #1E1D1A;
  --ink-muted: #5F5A50;
  --ink-faint: #8F897D;
  --border: #1E1D1A;
  --hairline: #D7CFC0;
  --slot-empty-border: #BDB4A3;

  --btn-primary-bg: #1E1D1A;
  --btn-primary-hover: #35332D;
  --btn-primary-text: #FCFBF7;
  --accent-terracotta: #B8432E;
  --accent-terracotta-hover: #9C3624;
  --accent-teal: #2A6878;

  /* Feedback palette — sole saturated signal on the board */
  --exact-bg: #2D7A4F;
  --exact-tint: #DCEFE3;
  --exact-border: #1E5637;
  --exact-text: #FCFBF7;
  --exact-tint-text: #18472D;

  --misplaced-bg: #D48A1A;
  --misplaced-tint: #F8E8C6;
  --misplaced-border: #8C570A;
  --misplaced-text: #1E1D1A;
  --misplaced-tint-text: #6E4406;

  --elim-bg: #7A756C;
  --elim-tint: #E5DFD3;
  --elim-border: #B2AA9B;
  --elim-text: #FCFBF7;
  --elim-tint-text: #7A756C;
  --elim-hatch: rgba(30, 29, 26, 0.1);

  /* Live clue role underlines — calibrated print inks */
  --role-0: #255F85;
  --role-1: #C27614;
  --role-2: #2D7A4F;
  --role-3: #B8432E;
  --role-4: #6D5D4B;

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

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
}

html.dark-mode {
  --bg: #171614;
  --surface: #23211E;
  --surface-hover: #2C2925;
  --surface-subtle: #1E1C19;
  --ink: #F2EDE4;
  --ink-muted: #A9A296;
  --ink-faint: #736D63;
  --border: #4F4B42;
  --hairline: #312E29;
  --slot-empty-border: #4A463E;

  --btn-primary-bg: #EFE9DD;
  --btn-primary-hover: #FFFFFF;
  --btn-primary-text: #171614;
  --accent-terracotta: #D15B45;
  --accent-terracotta-hover: #DF6B55;
  --accent-teal: #4592A6;

  --exact-bg: #36935F;
  --exact-tint: #173323;
  --exact-border: #52B47D;
  --exact-text: #0C1F14;
  --exact-tint-text: #95DFB3;

  --misplaced-bg: #E09A2B;
  --misplaced-tint: #3D2B0D;
  --misplaced-border: #F0B654;
  --misplaced-text: #171614;
  --misplaced-tint-text: #F6CF88;

  --elim-bg: #4F4B45;
  --elim-tint: #252320;
  --elim-border: #57524A;
  --elim-text: #D6D0C6;
  --elim-tint-text: #868077;
  --elim-hatch: rgba(242, 237, 228, 0.08);

  --role-0: #6BA7CE;
  --role-1: #E3A042;
  --role-2: #5CC088;
  --role-3: #E0705B;
  --role-4: #B8A38B;
}

html.high-contrast {
  --exact-bg: #E85D04;
  --exact-tint: #FFE1CC;
  --exact-border: #9A3412;
  --exact-text: #FFFFFF;
  --exact-tint-text: #7C2D12;

  --misplaced-bg: #0066CC;
  --misplaced-tint: #CCE4FF;
  --misplaced-border: #1E3A8A;
  --misplaced-text: #FFFFFF;
  --misplaced-tint-text: #1E3A8A;

  --elim-hatch: rgba(30, 29, 26, 0.18);
}

html.dark-mode.high-contrast {
  --exact-bg: #FF7A1A;
  --exact-tint: #4A2208;
  --exact-border: #FFA559;
  --exact-text: #171614;
  --exact-tint-text: #FFC18A;

  --misplaced-bg: #3898FF;
  --misplaced-tint: #102B52;
  --misplaced-border: #7CC0FF;
  --misplaced-text: #0A1529;
  --misplaced-tint-text: #A8D4FF;

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

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background-color: 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,
a:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

/* ==========================================================================
   App Shell & Editorial Header
   ========================================================================== */

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

.topbar {
  height: 48px;
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 10px;
  border-bottom: 1px solid var(--hairline);
  background: transparent;
}

.topbar-left {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.brand-title {
  margin: 0;
  text-align: center;
  line-height: 1;
}

.brand-title-btn {
  display: inline-flex;
  align-items: baseline;
  justify-content: center;
  padding: 4px 6px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: var(--font-serif);
  font-size: 1.48rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1;
  white-space: nowrap;
  color: var(--ink);
  user-select: none;
  transition: opacity 120ms ease;
}

.brand-title-btn:hover {
  opacity: 0.8;
}

.brand-letter {
  display: inline-block;
  will-change: transform;
}

.brand-space {
  display: inline-block;
  width: 0.26em;
}

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

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  transition: background 120ms ease, opacity 120ms ease;
}

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

.icon-btn:active {
  opacity: 0.65;
}

/* ==========================================================================
   Main Board Layout (Flat Canvas)
   ========================================================================== */

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

/* Unified Segmented Tier Switcher */
.tier-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  gap: 3px;
  border-radius: var(--radius-md);
  background: var(--surface-subtle);
  border: 1px solid var(--hairline);
}

.tier-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 31px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}

.tier-tab:hover:not(.tier-tab--active) {
  color: var(--ink);
}

.tier-tab--active {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--hairline);
}

.tier-tab-name {
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.tier-tab-badge {
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--ink-faint);
}

.tier-tab--active .tier-tab-badge {
  color: var(--ink-muted);
}

.tier-tab-badge--done {
  color: var(--exact-bg) !important;
  font-weight: 700;
}

.tier-tab-badge--lost {
  color: var(--accent-terracotta) !important;
  font-weight: 700;
}

/* Target Word Area (Flat, Unboxed) */
.target-banner {
  padding: 4px 0 8px;
  text-align: center;
  border-bottom: 1px solid var(--hairline);
}

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

.puzzle-tag {
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.meta-sep {
  color: var(--ink-faint);
  font-weight: 600;
}

/* Compact Attempt Pips */
.attempt-pips {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.attempt-pip {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid var(--ink-muted);
  background: transparent;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.attempt-pip--used {
  background: var(--ink-muted);
  border-color: var(--ink-muted);
}

.attempt-pip--won {
  background: var(--exact-bg);
  border-color: var(--exact-bg);
  transform: scale(1.15);
}

.back-daily-btn {
  border: 1px solid var(--hairline);
  background: var(--surface);
  color: var(--ink);
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 0.7rem;
  font-weight: 600;
}

.back-daily-btn:hover {
  background: var(--surface-subtle);
}

.target-word {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  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: 2px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 1.12rem;
  font-weight: 700;
  line-height: 1;
}

.target-letters--compact .target-letter {
  width: 25px;
  height: 28px;
  font-size: 0.98rem;
}

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

/* Dedicated Non-Overlapping Inline Status Line */
.status-line {
  min-height: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink-muted);
  margin: -3px 0;
  transition: color 140ms ease, opacity 140ms ease;
}

.status-line--hint {
  color: var(--ink-muted);
}

.status-line--active {
  color: var(--ink);
  font-weight: 600;
}

.status-line--win {
  color: var(--exact-bg);
}

.status-line--warn {
  color: var(--accent-terracotta);
}

/* Guess History Stack (Flat, No Outer Card) */
.history-section {
  padding: 2px 0 6px;
  border-bottom: 1px solid var(--hairline);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 142px;
  overflow-y: auto;
}

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

.history-row--mystery {
  grid-template-columns: 14px 1fr auto;
}

.history-num {
  font-variant-numeric: tabular-nums;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink-faint);
  text-align: right;
}

.history-pills {
  display: grid;
  gap: 4px;
}

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

.history-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3px;
  min-height: 26px;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.67rem;
  font-weight: 700;
  line-height: 1.1;
  overflow: hidden;
  border: 1.5px solid var(--border);
  text-transform: uppercase;
}

.history-pills--cols-5 .history-pill {
  padding: 2px 4px;
  font-size: 0.58rem;
}

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

.history-pill-mark {
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 700;
}

.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.13) 4px,
    rgba(255, 255, 255, 0.13) 8px
  );
  color: var(--elim-text);
  border-color: var(--elim-bg);
}

/* Mystery Length Hint Pill */
.length-hint-pill {
  flex-shrink: 0;
  padding: 3px 6px;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
  font-size: 0.66rem;
  font-weight: 700;
}

.length-hint--more {
  background: var(--accent-terracotta);
  color: #FCFBF7;
}

.length-hint--fewer {
  background: var(--accent-teal);
  color: #FCFBF7;
}

.length-hint--exact {
  background: var(--exact-bg);
  color: var(--exact-text);
}

/* ==========================================================================
   Active Clue Tray (Flat Section + Crisp Flat-Bordered Tiles)
   ========================================================================== */

.tray-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tray-slots {
  display: grid;
  gap: 6px;
}

.tray-slots--cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tray-slots--cols-4 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Mystery +2 Freeform Dropzone */
.tray-slots--freeform {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  align-content: center;
  gap: 6px;
  min-height: 82px;
  padding: 10px 10px;
  border: 1.5px dashed var(--slot-empty-border);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.28);
  transition: border-color 110ms ease, background 110ms ease;
}

html.dark-mode .tray-slots--freeform {
  background: rgba(255, 255, 255, 0.02);
}

.tray-slots--freeform.tray-slots--drop-hover {
  border-color: var(--ink);
  border-style: solid;
  background: var(--surface-subtle);
}

.freeform-placeholder {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-faint);
  user-select: none;
}

.freeform-tile {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 10px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.1;
  text-transform: uppercase;
  touch-action: none;
  user-select: none;
  transition: transform 80ms ease, background 110ms ease, border-color 110ms ease;
}

.freeform-tile:hover {
  background: var(--surface-hover);
}

.freeform-tile:active {
  transform: scale(0.97);
}

.freeform-tile.state--exact {
  background: var(--exact-tint);
  border-color: var(--exact-border);
  color: var(--exact-tint-text);
}

.freeform-tile.state--misplaced {
  background: var(--misplaced-tint);
  border-color: var(--misplaced-border);
  border-style: dashed;
  color: var(--misplaced-tint-text);
}

.freeform-tile--drop-before::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 2px;
  bottom: 2px;
  width: 2.5px;
  border-radius: 2px;
  background: var(--ink);
}

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

.tray-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 50px;
  padding: 5px 6px;
  border: 1.5px dashed var(--slot-empty-border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.28);
  text-align: center;
  touch-action: none;
  user-select: none;
  transition: transform 90ms ease, border-color 110ms ease, background 110ms ease;
}

html.dark-mode .tray-slot {
  background: rgba(255, 255, 255, 0.02);
}

.tray-slots--cols-4 .tray-slot {
  min-height: 42px;
  padding: 4px 5px;
}

.tray-slot--filled {
  border: 2px solid var(--border);
  background: var(--surface);
  opacity: 1;
}

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

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

.tray-slot--drop-hover {
  transform: scale(1.02);
  border-color: var(--ink);
  border-style: solid;
  background: var(--surface-subtle);
}

.slot-role {
  font-size: 0.64rem;
  font-weight: 500;
  color: var(--ink-muted);
}

.slot-role--empty {
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--ink-faint);
}

.slot-value {
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.12;
  letter-spacing: 0.02em;
  color: var(--ink);
  word-break: break-word;
  text-transform: uppercase;
}

/* Live Clue Preview — Unboxed typographic strip, keeping role underlines */
.live-preview-bar {
  padding: 7px 4px;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  text-align: center;
  line-height: 1.4;
}

.live-preview-text {
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink);
  text-transform: uppercase;
}

.preview-quote {
  color: var(--ink-faint);
  font-family: var(--font-serif);
  font-size: 1rem;
}

.preview-token--blank {
  color: var(--ink-faint);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 500;
}

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

.preview-token--role0 { text-decoration-color: var(--role-0); }
.preview-token--role1 { text-decoration-color: var(--role-1); }
.preview-token--role2 { text-decoration-color: var(--role-2); }
.preview-token--role3 { text-decoration-color: var(--role-3); }
.preview-token--role4 { text-decoration-color: var(--role-4); }

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

/* ==========================================================================
   Phrase Tile Bank (Crisp Flat-Bordered Tiles, Zero Drop Shadows)
   ========================================================================== */

.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: 54px;
  padding: 8px 6px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--surface);
  text-align: center;
  touch-action: none;
  user-select: none;
  transition: transform 80ms ease, background 120ms ease, opacity 120ms ease, border-color 120ms ease;
}

.tile-bank--size-12 .bank-tile {
  min-height: 45px;
  padding: 6px 5px;
}

.bank-tile:not(:disabled):hover {
  background: var(--surface-hover);
}

.bank-tile:not(:disabled):active {
  transform: scale(0.975);
}

.tile-text {
  font-size: 0.77rem;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.025em;
  color: var(--ink);
  word-break: break-word;
  text-transform: uppercase;
}

.tile-bank--size-12 .tile-text {
  font-size: 0.72rem;
}

.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: 3px;
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 0.58rem;
  font-weight: 700;
  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);
}

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

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

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

.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);
  opacity: 0.54;
  cursor: not-allowed;
}

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

.bank-tile--in-tray {
  opacity: 0.34;
}

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

/* Floating Drag Ghost */
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 900;
  pointer-events: none;
  padding: 8px 13px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--border);
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ==========================================================================
   Action Controls Bar (Flat Crisp Buttons, Zero Drop Shadows)
   ========================================================================== */

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 600;
  border: 2px solid var(--border);
  transition: transform 80ms ease, opacity 120ms ease, background 120ms ease, border-color 120ms ease;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

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

.btn--primary {
  background: var(--btn-primary-bg);
  border-color: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

.btn--primary:hover:not(:disabled) {
  background: var(--btn-primary-hover);
  border-color: var(--btn-primary-hover);
}

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

.btn--secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

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

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

/* ==========================================================================
   Post-Solve X-Ray Breakdown Card (Quiet Editorial)
   ========================================================================== */

.xray-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  padding: 15px 14px;
  display: flex;
  flex-direction: column;
  gap: 11px;
  animation: xraySlideIn 260ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

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

.xray-verdict {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 1.12rem;
  color: var(--ink);
}

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

.xray-type-label {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.xray-clue-sentence {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 9px;
  padding: 4px 2px;
}

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

.xray-part-text {
  font-family: var(--font-sans);
  font-size: 0.94rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding-bottom: 2px;
  border-bottom: 2.5px solid var(--ink);
  text-transform: uppercase;
}

.xray-part--def .xray-part-text { border-color: var(--role-0); }
.xray-part--ind .xray-part-text { border-color: var(--role-1); }
.xray-part--fod .xray-part-text { border-color: var(--role-2); }
.xray-part--alt1 .xray-part-text { border-color: var(--role-3); }
.xray-part--alt2 .xray-part-text { border-color: var(--role-4); }

.xray-part-tag {
  font-size: 0.64rem;
  font-weight: 500;
  color: var(--ink-muted);
}

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

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

.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: 21px;
  height: 23px;
  padding: 0 3px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
}

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

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

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

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

.xray-space { width: 6px; }

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

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

.xray-word-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 3px;
  border: 1.5px solid var(--exact-border);
  background: var(--exact-bg);
  color: var(--exact-text);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.xray-word-pill--fodder {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--hairline);
}

.xray-soundwave {
  font-size: 1rem;
  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.72rem;
  color: var(--ink-muted);
}

.xray-charade-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  font-size: 0.68rem;
  font-weight: 700;
  animation: xrayPop 340ms 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.84rem;
  font-weight: 400;
  line-height: 1.48;
  color: var(--ink-muted);
  text-align: center;
}

/* Quiet Editorial Attribution */
.xray-source {
  text-align: center;
  font-family: var(--font-serif);
  font-size: 0.86rem;
  font-style: italic;
  font-weight: 400;
  color: var(--ink-muted);
  margin-top: -4px;
}

.btn--video {
  background: var(--accent-terracotta);
  border-color: var(--accent-terracotta);
  color: #FCFBF7;
  text-decoration: none;
  width: 100%;
}

.btn--video:hover {
  background: var(--accent-terracotta-hover);
  border-color: var(--accent-terracotta-hover);
}

.xray-actions {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 7px;
  margin-top: 2px;
}

.xray-countdown {
  text-align: center;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--ink-muted);
  padding-top: 8px;
  border-top: 1px solid var(--hairline);
}

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

/* ==========================================================================
   Modals (Calm Print Editorial, Zero Drop Shadows)
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 800;
  background: rgba(20, 19, 16, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-panel {
  width: 100%;
  max-width: 432px;
  max-height: 86dvh;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalFadeIn 160ms ease both;
}

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

.modal-title {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.18rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.modal-close {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 1.35rem;
  font-weight: 400;
  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.86rem;
  line-height: 1.5;
  color: var(--ink-muted);
}

.modal-subhead {
  margin: 4px 0 0;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
}

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

.howto-slot-card {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 0.82rem;
  line-height: 1.42;
}

.howto-slot-badge {
  flex-shrink: 0;
  width: 84px;
  text-align: center;
  padding: 3px 6px;
  border-radius: 4px;
  border: 1px solid var(--hairline);
  background: var(--surface-subtle);
  color: var(--ink);
  font-size: 0.72rem;
  font-weight: 600;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  line-height: 1.4;
}

.legend-chip {
  flex-shrink: 0;
  width: 82px;
  text-align: center;
  padding: 4px 5px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  border: 1.5px solid var(--border);
}

.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);
  border-color: var(--elim-bg);
}

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

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

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

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

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

kbd,
code {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--hairline);
  background: var(--surface-subtle);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
}

/* Stats Modal */
.stats-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--hairline);
}

.kpi-box {
  text-align: center;
  padding: 4px 2px;
}

.kpi-val {
  font-variant-numeric: tabular-nums;
  font-size: 1.4rem;
  font-weight: 700;
  line-height: 1.1;
}

.kpi-label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--ink-muted);
  margin-top: 4px;
}

.tier-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.tier-stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 7px 4px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.tier-stat-name { font-size: 0.72rem; font-weight: 600; color: var(--ink-muted); }
.tier-stat-val { font-variant-numeric: tabular-nums; font-size: 0.9rem; font-weight: 700; color: var(--ink); margin-top: 2px; }

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

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

.dist-num {
  font-variant-numeric: tabular-nums;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink-muted);
}

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

.dist-bar {
  background: var(--elim-bg);
  color: #FCFBF7;
  font-variant-numeric: tabular-nums;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 2px 7px;
  text-align: right;
  min-width: 24px;
}

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

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

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

.mastery-name { font-weight: 600; }
.mastery-score {
  font-variant-numeric: tabular-nums;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--ink-muted);
}

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

.mastery-fill {
  height: 100%;
  background: var(--exact-bg);
  transition: width 300ms ease;
}

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

/* 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(--hairline);
  border-radius: var(--radius-sm);
  background: var(--bg);
  text-align: left;
  transition: background 100ms ease, border-color 100ms ease;
}

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

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

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

.archive-today-pill {
  padding: 1px 6px;
  border-radius: 3px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.66rem;
  font-weight: 600;
}

.archive-item-sub {
  font-variant-numeric: tabular-nums;
  font-size: 0.74rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

.archive-status {
  flex-shrink: 0;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--hairline);
  font-variant-numeric: tabular-nums;
  font-size: 0.72rem;
  font-weight: 600;
}

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

.archive-status--lost {
  background: var(--elim-bg);
  border-color: var(--elim-bg);
  color: var(--elim-text);
}

.archive-status--playing {
  background: var(--surface);
  color: var(--ink);
}

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

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

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

.setting-name { font-size: 0.88rem; font-weight: 600; }
.setting-desc { font-size: 0.76rem; color: var(--ink-muted); line-height: 1.4; }

.toggle-input {
  appearance: none;
  flex-shrink: 0;
  width: 42px;
  height: 24px;
  border-radius: 12px;
  border: 1.5px solid var(--slot-empty-border);
  background: var(--surface-subtle);
  position: relative;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.toggle-input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--surface);
  transition: transform 140ms ease;
}

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

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

/* ==========================================================================
   Animations (Game-Native Motion, Zero Confetti)
   ========================================================================== */

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

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

@keyframes winJump {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-9px); }
  65% { transform: translateY(2px); }
}

.anim-win-jump {
  animation: winJump 420ms cubic-bezier(0.22, 1, 0.36, 1) 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 260ms ease; }

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

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

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

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

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

@media (max-height: 700px) {
  .board { gap: 6px; padding: 7px 10px 8px; }
  .target-letter { width: 25px; height: 27px; font-size: 0.98rem; }
  .bank-tile { min-height: 44px; }
  .tile-bank--size-12 .bank-tile { min-height: 37px; }
  .btn--control { height: 39px; }
}

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