@layer reset, base, components, utilities;

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

  html {
    -webkit-text-size-adjust: 100%;
  }

  body,
  h1,
  h2,
  h3,
  p,
  blockquote,
  ul {
    margin: 0;
  }

  button,
  select,
  input {
    font: inherit;
  }

  button,
  a,
  select,
  input {
    -webkit-tap-highlight-color: transparent;
  }

  button {
    color: inherit;
  }

  svg {
    display: block;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
  }
}

@layer base {
  :root {
    color-scheme: light;
    --bg: oklch(1 0 0);
    --surface: oklch(0.972 0 0);
    --surface-strong: oklch(0.93 0.004 75);
    --surface-hover: oklch(0.9 0.008 75);
    --ink: oklch(0.19 0.014 65);
    --ink-soft: oklch(0.34 0.014 65);
    --muted: oklch(0.47 0.012 65);
    --faint: oklch(0.5 0.009 65);
    --line: oklch(0.86 0.006 75);
    --line-strong: oklch(0.72 0.009 75);
    --primary: oklch(0.68 0.146 74.6);
    --primary-deep: oklch(0.52 0.14 68);
    --primary-pale: oklch(0.94 0.055 82);
    --correct: oklch(0.5 0.125 145);
    --correct-pale: oklch(0.94 0.042 145);
    --present: oklch(0.62 0.14 75);
    --absent: oklch(0.43 0.018 252);
    --danger: oklch(0.54 0.19 25);
    --focus: oklch(0.55 0.18 252);
    --on-primary: oklch(0.16 0.014 65);
    --on-correct: oklch(1 0 0);
    --on-present: oklch(0.16 0.014 65);
    --on-absent: oklch(1 0 0);
    --backdrop: oklch(0.08 0 0 / 0.5);
    --shadow-dialog: 0 22px 55px oklch(0.08 0 0 / 0.2);
    --radius-sm: 7px;
    --radius-md: 11px;
    --radius-lg: 16px;
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
    --z-sticky: 20;
    --z-modal: 40;
    --z-toast: 60;
  }

  :root[data-theme="dark"] {
    color-scheme: dark;
    --bg: oklch(0.14 0.008 65);
    --surface: oklch(0.19 0.008 65);
    --surface-strong: oklch(0.24 0.009 65);
    --surface-hover: oklch(0.29 0.01 65);
    --ink: oklch(0.95 0.004 75);
    --ink-soft: oklch(0.83 0.006 75);
    --muted: oklch(0.72 0.007 75);
    --faint: oklch(0.68 0.008 75);
    --line: oklch(0.31 0.01 65);
    --line-strong: oklch(0.45 0.012 65);
    --primary: oklch(0.73 0.14 76);
    --primary-deep: oklch(0.8 0.12 79);
    --primary-pale: oklch(0.25 0.04 75);
    --correct: oklch(0.58 0.12 145);
    --correct-pale: oklch(0.23 0.035 145);
    --present: oklch(0.67 0.13 75);
    --absent: oklch(0.39 0.015 252);
    --danger: oklch(0.67 0.17 25);
    --focus: oklch(0.72 0.14 245);
    --on-correct: oklch(0.13 0.008 65);
    --backdrop: oklch(0.03 0 0 / 0.7);
    --shadow-dialog: 0 22px 55px oklch(0.02 0 0 / 0.55);
  }

  @media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
      color-scheme: dark;
      --bg: oklch(0.14 0.008 65);
      --surface: oklch(0.19 0.008 65);
      --surface-strong: oklch(0.24 0.009 65);
      --surface-hover: oklch(0.29 0.01 65);
      --ink: oklch(0.95 0.004 75);
      --ink-soft: oklch(0.83 0.006 75);
      --muted: oklch(0.72 0.007 75);
      --faint: oklch(0.68 0.008 75);
      --line: oklch(0.31 0.01 65);
      --line-strong: oklch(0.45 0.012 65);
      --primary: oklch(0.73 0.14 76);
      --primary-deep: oklch(0.8 0.12 79);
      --primary-pale: oklch(0.25 0.04 75);
      --correct: oklch(0.58 0.12 145);
      --correct-pale: oklch(0.23 0.035 145);
      --present: oklch(0.67 0.13 75);
      --absent: oklch(0.39 0.015 252);
      --danger: oklch(0.67 0.17 25);
      --focus: oklch(0.72 0.14 245);
      --on-correct: oklch(0.13 0.008 65);
      --backdrop: oklch(0.03 0 0 / 0.7);
      --shadow-dialog: 0 22px 55px oklch(0.02 0 0 / 0.55);
    }
  }

  html[data-contrast="high"] {
    --ink: oklch(0.08 0 0);
    --ink-soft: oklch(0.16 0 0);
    --muted: oklch(0.28 0 0);
    --line: oklch(0.48 0 0);
    --line-strong: oklch(0.3 0 0);
    --correct: oklch(0.39 0.16 145);
    --present: oklch(0.47 0.16 65);
    --absent: oklch(0.26 0 0);
  }

  html[data-theme="dark"][data-contrast="high"] {
    --ink: oklch(1 0 0);
    --ink-soft: oklch(0.94 0 0);
    --muted: oklch(0.86 0 0);
    --line: oklch(0.68 0 0);
    --line-strong: oklch(0.82 0 0);
    --correct: oklch(0.62 0.17 145);
    --present: oklch(0.72 0.16 75);
    --absent: oklch(0.5 0 0);
  }

  @media (prefers-color-scheme: dark) {
    html:not([data-theme])[data-contrast="high"] {
      --ink: oklch(1 0 0);
      --ink-soft: oklch(0.94 0 0);
      --muted: oklch(0.86 0 0);
      --line: oklch(0.68 0 0);
      --line-strong: oklch(0.82 0 0);
      --correct: oklch(0.62 0.17 145);
      --present: oklch(0.72 0.16 75);
      --absent: oklch(0.5 0 0);
    }
  }

  body {
    min-width: 320px;
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    background: var(--bg);
    color: var(--ink);
    font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
  }

  button,
  a,
  select,
  input {
    outline: none;
  }

  :where(button, a, select, input):focus-visible {
    box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--focus);
  }

  button:not(:disabled),
  select:not(:disabled),
  input:not(:disabled) {
    cursor: pointer;
  }

  button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
  }

  ::selection {
    background: var(--primary-pale);
    color: var(--ink);
  }
}

@layer components {
  .skip-link {
    position: fixed;
    top: 8px;
    left: 8px;
    z-index: calc(var(--z-toast) + 1);
    padding: 9px 13px;
    border-radius: var(--radius-sm);
    background: var(--ink);
    color: var(--bg);
    font-weight: 750;
    text-decoration: none;
    transform: translateY(-160%);
    transition: transform 160ms var(--ease-out);
  }

  .skip-link:focus {
    transform: translateY(0);
  }

  .app {
    min-height: 100dvh;
  }

  .app-header {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    padding-top: env(safe-area-inset-top, 0px);
    border-bottom: 1px solid var(--line);
    background: color-mix(in oklch, var(--bg) 94%, transparent);
    backdrop-filter: blur(12px);
  }

  .header-inner {
    position: relative;
    width: min(calc(100% - 32px), 1020px);
    min-height: 62px;
    margin: 0 auto;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
  }

  .brand {
    position: absolute;
    left: 50%;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    justify-self: center;
    transform: translateX(-50%);
    color: var(--ink);
    font-size: 1.02rem;
    font-weight: 850;
    letter-spacing: 0.09em;
    line-height: 1;
    text-decoration: none;
  }

  .brand-mark {
    width: 29px;
    height: 29px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: var(--primary);
    color: var(--on-primary);
    font-size: 0.9rem;
    font-weight: 900;
    letter-spacing: 0;
  }

  .header-actions {
    display: flex;
    justify-self: end;
    gap: 2px;
  }

  .icon-button {
    position: relative;
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    transition: background-color 160ms var(--ease-standard), transform 120ms var(--ease-out);
  }

  .icon-button svg {
    width: 21px;
    height: 21px;
  }

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

  .icon-button:active {
    transform: scale(0.94);
  }

  .header-progress {
    position: absolute;
    right: 0;
    bottom: 1px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: var(--primary);
    color: var(--on-primary);
    font-size: 0.62rem;
    font-weight: 850;
    line-height: 1;
  }

  .game-shell {
    width: min(calc(100% - 32px), 980px);
    margin: 0 auto;
    padding: 28px 0 48px;
    display: grid;
    grid-template-columns: minmax(0, 590px) minmax(270px, 320px);
    gap: 46px;
    align-items: start;
  }

  .play-column {
    min-width: 0;
  }

  .mode-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--line);
  }

  .mode-tab {
    position: relative;
    min-height: 47px;
    padding: 0 18px 11px;
    display: flex;
    align-items: baseline;
    gap: 8px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-weight: 750;
    transition: color 160ms var(--ease-standard);
  }

  .mode-tab::after {
    content: "";
    position: absolute;
    right: 12px;
    bottom: -1px;
    left: 12px;
    height: 2px;
    border-radius: 999px;
    background: var(--primary-deep);
    opacity: 0;
    transform: scaleX(0.5);
    transition: opacity 160ms var(--ease-standard), transform 200ms var(--ease-out);
  }

  .mode-tab:hover {
    color: var(--ink);
  }

  .mode-tab.is-active {
    color: var(--ink);
  }

  .mode-tab.is-active::after {
    opacity: 1;
    transform: scaleX(1);
  }

  .mode-detail {
    color: var(--faint);
    font-size: 0.74rem;
    font-weight: 650;
  }

  .puzzle-heading {
    min-height: 72px;
    padding: 15px 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
  }

  .puzzle-kicker {
    color: var(--ink);
    font-size: 0.96rem;
    font-weight: 780;
    text-wrap: balance;
  }

  .puzzle-instruction {
    margin-top: 1px;
    color: var(--muted);
    font-size: 0.8rem;
  }

  .puzzle-tools {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  .tool-button {
    position: relative;
    min-height: 44px;
    padding: 0 11px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--bg);
    color: var(--ink-soft);
    font-size: 0.76rem;
    font-weight: 760;
    transition: border-color 160ms var(--ease-standard), background-color 160ms var(--ease-standard), color 160ms var(--ease-standard), transform 120ms var(--ease-out);
  }

  .tool-button svg {
    width: 17px;
    height: 17px;
  }

  .tool-button:hover:not(:disabled) {
    border-color: var(--line-strong);
    background: var(--surface);
  }

  .tool-button:active:not(:disabled) {
    transform: scale(0.97);
  }

  .tool-button[aria-pressed="true"] {
    border-color: var(--ink);
    background: var(--ink);
    color: var(--bg);
  }

  .tool-badge {
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: var(--surface-strong);
    color: var(--muted);
    font-size: 0.64rem;
  }

  .tool-button[aria-pressed="true"] .tool-badge {
    background: color-mix(in oklch, var(--bg) 16%, transparent);
    color: var(--bg);
  }

  .board-stage {
    position: relative;
    display: grid;
    place-items: center;
  }

  .board-stage:focus-visible {
    border-radius: var(--radius-md);
    outline: 3px solid var(--focus);
    outline-offset: 5px;
  }

  .board {
    --tile-size: min(60px, 13vw, 8.25dvh);
    --tile-gap: clamp(5px, 1.7vw, 8px);
    display: grid;
    grid-template-columns: repeat(5, var(--tile-size));
    grid-template-rows: repeat(6, var(--tile-size));
    gap: var(--tile-gap);
    touch-action: manipulation;
  }

  .board-row {
    display: contents;
  }

  .tile {
    position: relative;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: var(--bg);
    box-shadow: inset 0 0 0 1.5px var(--line);
    color: var(--ink);
    font-size: clamp(1.25rem, 5vw, 1.72rem);
    font-weight: 860;
    line-height: 1;
    text-transform: uppercase;
    user-select: none;
    transform-style: preserve-3d;
  }

  .tile-letter {
    display: block;
  }

  /* Digraphs keep the full single-letter cap height; the glyph pair is
     condensed horizontally so both letters fit inside the tile. */
  .tile.is-digraph .tile-letter {
    transform: scaleX(0.7);
    letter-spacing: -0.04em;
  }

  .tile.is-filled:not(.is-correct, .is-present, .is-absent) {
    box-shadow: inset 0 0 0 2px var(--ink-soft);
    animation: tile-pop 130ms var(--ease-out);
  }

  .tile.is-correct,
  .tile.is-present,
  .tile.is-absent {
    box-shadow: none;
  }

  .tile.is-correct {
    --tile-result-bg: var(--correct);
    --tile-result-ink: var(--on-correct);
    background: var(--correct);
    color: var(--on-correct);
  }

  .tile.is-present {
    --tile-result-bg: var(--present);
    --tile-result-ink: var(--on-present);
    background: var(--present);
    color: var(--on-present);
  }

  .tile.is-absent {
    --tile-result-bg: var(--absent);
    --tile-result-ink: var(--on-absent);
    background: var(--absent);
    color: var(--on-absent);
  }

  .tile-status {
    position: absolute;
    right: 4px;
    bottom: 3px;
    font-size: 0.58rem;
    font-weight: 900;
    line-height: 1;
  }

  .tile.is-revealing {
    animation: tile-reveal 360ms var(--ease-standard) both;
    animation-delay: var(--reveal-delay, 0ms);
  }

  .tile.is-revealing .tile-status {
    animation: status-in 360ms var(--ease-standard) both;
    animation-delay: var(--reveal-delay, 0ms);
  }

  .board.is-invalid .tile.is-current-row {
    animation: row-shake 320ms var(--ease-out);
  }

  .board.is-won {
    animation: board-win 420ms var(--ease-out);
  }

  .celebration {
    position: absolute;
    inset: 10% 12%;
    pointer-events: none;
  }

  .celebration-piece {
    position: absolute;
    top: 48%;
    left: 48%;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: var(--piece-color, var(--primary));
    animation: celebrate 700ms var(--ease-out) both;
    animation-delay: var(--piece-delay, 0ms);
  }

  .board-message {
    min-height: 38px;
    padding: 10px 8px 0;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
    text-align: center;
    text-wrap: pretty;
  }

  .board-message.is-error {
    color: var(--danger);
  }

  .board-message.is-success {
    color: var(--correct);
  }

  .keyboard-section {
    width: min(100%, 600px);
    margin: 13px auto 0;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .keyboard {
    display: flex;
    flex-direction: column;
    gap: 5px;
  }

  .keyboard-row {
    display: flex;
    justify-content: center;
    gap: 4px;
  }

  .key {
    min-width: 0;
    height: 48px;
    flex: 1 1 0;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: var(--radius-sm);
    background: var(--surface-strong);
    color: var(--ink);
    font-size: clamp(0.65rem, 2.3vw, 0.82rem);
    font-weight: 820;
    line-height: 1;
    text-transform: uppercase;
    user-select: none;
    transition: background-color 150ms var(--ease-standard), color 150ms var(--ease-standard), transform 90ms var(--ease-out);
  }

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

  .key:disabled {
    opacity: 1;
  }

  .key:active:not(:disabled),
  .key.is-pressed {
    transform: translateY(2px) scale(0.96);
  }

  .key.is-wide {
    flex-grow: 1.55;
  }

  .key svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.1;
  }

  .key.is-correct {
    background: var(--correct);
    color: var(--on-correct);
  }

  .key.is-present {
    background: var(--present);
    color: var(--on-present);
  }

  .key.is-absent {
    background: var(--absent);
    color: var(--on-absent);
  }

  .side-column {
    min-width: 0;
    padding-left: 32px;
    border-left: 1px solid var(--line);
  }

  .side-section {
    padding: 20px 0;
    border-bottom: 1px solid var(--line);
  }

  .side-section:first-child {
    padding-top: 5px;
  }

  .side-heading {
    display: flex;
    align-items: flex-start;
    gap: 12px;
  }

  .side-icon {
    width: 32px;
    height: 32px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--surface);
    color: var(--ink-soft);
  }

  .side-icon svg {
    width: 17px;
    height: 17px;
  }

  .side-heading h2,
  .passport-summary h2 {
    color: var(--ink);
    font-size: 0.92rem;
    font-weight: 790;
    line-height: 1.25;
    text-wrap: balance;
  }

  .side-heading p,
  .passport-summary p {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.76rem;
    line-height: 1.4;
    text-wrap: pretty;
  }

  .hint-copy,
  .besa-copy {
    margin: 12px 0 0 44px;
    color: var(--ink-soft);
    font-size: 0.8rem;
    line-height: 1.5;
    text-wrap: pretty;
  }

  .hint-section.is-revealed .side-icon {
    background: var(--primary-pale);
    color: var(--primary-deep);
  }

  .hint-section.is-revealed .hint-copy {
    color: var(--ink);
    font-weight: 650;
  }

  .besa-section.is-active .side-icon {
    background: var(--correct-pale);
    color: var(--correct);
  }

  .passport-summary {
    display: flex;
    align-items: center;
    gap: 13px;
  }

  .passport-ring {
    --progress: 0turn;
    position: relative;
    width: 49px;
    height: 49px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: conic-gradient(var(--primary) var(--progress), var(--surface-strong) 0);
  }

  .passport-ring::before {
    content: "";
    position: absolute;
    inset: 5px;
    border-radius: inherit;
    background: var(--bg);
  }

  .passport-ring span {
    position: relative;
    z-index: 1;
    font-size: 0.76rem;
    font-weight: 850;
  }

  .rare-letter-row {
    margin: 15px 0 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
  }

  .rare-letter {
    min-width: 26px;
    height: 25px;
    padding: 0 6px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: var(--surface);
    color: var(--faint);
    font-size: 0.65rem;
    font-weight: 820;
  }

  .rare-letter.is-collected {
    background: var(--primary);
    color: var(--on-primary);
  }

  .text-button {
    min-height: 44px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    border: 0;
    background: transparent;
    color: var(--primary-deep);
    font-size: 0.78rem;
    font-weight: 780;
  }

  .text-button svg {
    width: 16px;
    height: 16px;
    transition: transform 160ms var(--ease-out);
  }

  .text-button:hover svg {
    transform: translateX(2px);
  }

  .result-panel {
    padding: 20px 0 22px;
    border-bottom: 1px solid var(--line);
  }

  .result-panel:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 5px;
  }

  .result-panel[hidden] {
    display: none;
  }

  .result-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .result-label,
  .result-time {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 750;
  }

  .result-word {
    margin-top: 8px;
    color: var(--ink);
    font-size: 2rem;
    font-weight: 880;
    letter-spacing: -0.025em;
    line-height: 1.1;
    text-wrap: balance;
  }

  .result-meta {
    margin-top: 5px;
    color: var(--primary-deep);
    font-size: 0.74rem;
    font-weight: 740;
  }

  .result-definition {
    margin-top: 12px;
    color: var(--ink-soft);
    font-size: 0.85rem;
    line-height: 1.55;
    text-wrap: pretty;
  }

  .result-example {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-soft);
    font-size: 0.8rem;
    font-style: italic;
    line-height: 1.5;
  }

  .result-actions {
    margin-top: 17px;
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .primary-button,
  .secondary-button {
    min-height: 46px;
    padding: 0 17px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: var(--radius-sm);
    font-weight: 790;
    transition: background-color 160ms var(--ease-standard), color 160ms var(--ease-standard), transform 120ms var(--ease-out);
  }

  .primary-button {
    border: 0;
    background: var(--ink);
    color: var(--bg);
  }

  .primary-button:hover {
    background: var(--ink-soft);
  }

  .secondary-button {
    border: 1px solid var(--line-strong);
    background: transparent;
    color: var(--ink);
  }

  .secondary-button:hover {
    background: var(--surface);
  }

  .primary-button:active,
  .secondary-button:active {
    transform: scale(0.98);
  }

  .primary-button svg {
    width: 18px;
    height: 18px;
  }

  .result-replay {
    align-self: center;
  }

  .side-footnote {
    padding-top: 17px;
    color: var(--faint);
    font-size: 0.68rem;
    font-weight: 720;
    text-align: center;
  }

  .sheet-dialog {
    width: min(calc(100% - 28px), 520px);
    max-height: min(88dvh, 760px);
    padding: 0;
    overflow: hidden;
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--bg);
    color: var(--ink);
    box-shadow: var(--shadow-dialog);
  }

  .sheet-dialog::backdrop {
    background: var(--backdrop);
    backdrop-filter: blur(2px);
  }

  .sheet-dialog[open] {
    animation: dialog-in 210ms var(--ease-out);
  }

  .dialog-shell {
    max-height: inherit;
    display: flex;
    flex-direction: column;
  }

  .dialog-header {
    padding: 20px 20px 15px 24px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--line);
  }

  .dialog-overline {
    color: var(--primary-deep);
    font-size: 0.72rem;
    font-weight: 780;
  }

  .dialog-header h2 {
    margin-top: 2px;
    font-size: 1.35rem;
    font-weight: 840;
    letter-spacing: -0.02em;
    line-height: 1.2;
    text-wrap: balance;
  }

  .dialog-close {
    margin-top: -6px;
    margin-right: -8px;
    flex: 0 0 auto;
  }

  .dialog-content {
    padding: 21px 24px 25px;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .dialog-content > p {
    color: var(--ink-soft);
    font-size: 0.91rem;
    line-height: 1.58;
    text-wrap: pretty;
  }

  .example-row {
    margin: 22px 0 18px;
    display: flex;
    gap: 8px;
  }

  .example-tile {
    position: relative;
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    font-size: 1.25rem;
    font-weight: 850;
  }

  .example-tile small {
    position: absolute;
    right: 4px;
    bottom: 3px;
    font-size: 0.55rem;
  }

  .is-correct {
    background-color: var(--correct);
  }

  .is-present {
    background-color: var(--present);
  }

  .is-absent {
    background-color: var(--absent);
  }

  .legend-list {
    padding: 0;
    display: grid;
    gap: 12px;
    list-style: none;
  }

  .legend-list li {
    display: flex;
    align-items: center;
    gap: 11px;
    color: var(--ink-soft);
    font-size: 0.82rem;
    line-height: 1.4;
  }

  .legend-swatch {
    width: 28px;
    height: 28px;
    flex: 0 0 auto;
    display: grid;
    place-items: center;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 900;
  }

  :is(.example-tile, .legend-swatch).is-correct {
    color: var(--on-correct);
  }

  :is(.example-tile, .legend-swatch).is-present {
    color: var(--on-present);
  }

  :is(.example-tile, .legend-swatch).is-absent {
    color: var(--on-absent);
  }

  .alphabet-note {
    margin-top: 22px;
    padding: 14px 15px;
    border-radius: var(--radius-md);
    background: var(--primary-pale);
    color: var(--ink);
  }

  .alphabet-note strong {
    font-size: 0.85rem;
  }

  .alphabet-note p {
    margin-top: 4px;
    color: var(--ink-soft);
    font-size: 0.79rem;
    line-height: 1.55;
  }

  .alphabet-note span {
    font-weight: 820;
  }

  .dialog-primary {
    width: 100%;
    margin-top: 20px;
  }

  .passport-dialog-summary {
    display: flex;
    align-items: center;
    gap: 16px;
  }

  .passport-dialog-summary strong {
    flex: 0 0 auto;
    color: var(--primary-deep);
    font-size: 1.35rem;
    font-weight: 860;
  }

  .passport-dialog-summary p {
    color: var(--ink-soft);
    font-size: 0.8rem;
    line-height: 1.45;
  }

  .alphabet-grid {
    margin-top: 22px;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 7px;
  }

  .alphabet-stamp {
    position: relative;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--faint);
    font-size: 0.78rem;
    font-weight: 840;
  }

  .alphabet-stamp.is-digraph {
    font-size: 0.66rem;
  }

  .alphabet-stamp.is-collected {
    background: var(--primary);
    color: var(--on-primary);
  }

  .alphabet-stamp.is-collected::after {
    content: "✓";
    position: absolute;
    right: 3px;
    bottom: 2px;
    font-size: 0.52rem;
  }

  .passport-tip {
    margin-top: 17px;
    color: var(--muted);
    font-size: 0.76rem;
    text-align: center;
  }

  .stats-summary {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--line);
  }

  .stats-summary div {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .stats-summary strong {
    font-size: 1.45rem;
    font-weight: 850;
    line-height: 1.2;
  }

  .stats-summary span {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.69rem;
  }

  .dialog-content h3 {
    margin-top: 20px;
    font-size: 0.84rem;
    font-weight: 790;
  }

  .distribution {
    margin-top: 12px;
    display: grid;
    gap: 6px;
  }

  .distribution-row {
    display: grid;
    grid-template-columns: 16px 1fr;
    align-items: center;
    gap: 9px;
    font-size: 0.72rem;
    font-weight: 750;
  }

  .distribution-track {
    min-width: 0;
    height: 24px;
    border-radius: 5px;
    background: var(--surface);
    overflow: hidden;
  }

  .distribution-bar {
    width: var(--bar-width, 8%);
    min-width: 26px;
    height: 100%;
    padding: 0 7px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    border-radius: inherit;
    background: var(--absent);
    color: var(--on-absent);
  }

  .distribution-row.is-current .distribution-bar {
    background: var(--correct);
    color: var(--on-correct);
  }

  .stats-besa {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.78rem;
  }

  .stats-besa strong {
    color: var(--ink);
  }

  .result-countdown {
    margin-top: 14px;
    padding: 9px 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-soft);
    font-size: 0.8rem;
    font-weight: 760;
    font-variant-numeric: tabular-nums;
    text-align: center;
  }

  .result-countdown[hidden] {
    display: none;
  }

  .calendar {
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
  }

  .calendar-intro h3 {
    margin-top: 0;
  }

  .calendar-intro p {
    margin-top: 3px;
    color: var(--muted);
    font-size: 0.76rem;
    line-height: 1.4;
    text-wrap: pretty;
  }

  .calendar-nav {
    margin-top: 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .calendar-arrow {
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
  }

  .calendar-arrow svg {
    width: 18px;
    height: 18px;
  }

  .calendar-arrow:hover:not(:disabled) {
    background: var(--surface);
  }

  .calendar-title {
    flex: 1 1 auto;
    color: var(--ink);
    font-size: 0.92rem;
    font-weight: 800;
    text-align: center;
    text-transform: capitalize;
  }

  .calendar-table {
    width: 100%;
    margin-top: 12px;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 4px;
  }

  .calendar-weekday {
    padding: 0 0 4px;
    color: var(--faint);
    font-size: 0.64rem;
    font-weight: 780;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }

  .calendar-table td {
    padding: 0;
  }

  .calendar-cell {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink-soft);
    font: inherit;
  }

  .calendar-day {
    font-size: 0.78rem;
    font-weight: 760;
    line-height: 1;
  }

  .calendar-cell.is-inert {
    border-style: dashed;
    color: var(--faint);
    opacity: 0.7;
  }

  .calendar-cell.is-playable {
    cursor: pointer;
    border-color: var(--line-strong);
    color: var(--ink);
    transition: background-color 150ms var(--ease-standard), transform 100ms var(--ease-out);
  }

  .calendar-cell.is-playable:hover {
    background: var(--surface-hover);
  }

  .calendar-cell.is-playable::after {
    content: "";
    position: absolute;
    right: 5px;
    bottom: 5px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--primary);
  }

  .calendar-cell.is-playable:active {
    transform: scale(0.95);
  }

  .calendar-cell.is-won {
    border-color: transparent;
    background: var(--correct);
    color: var(--on-correct);
  }

  .calendar-cell.is-lost {
    border-color: transparent;
    background: var(--absent);
    color: var(--on-absent);
  }

  .calendar-badge {
    position: absolute;
    top: 3px;
    left: 5px;
    font-size: 0.6rem;
    font-weight: 850;
    line-height: 1;
  }

  .calendar-mark {
    position: absolute;
    right: 4px;
    bottom: 3px;
    font-size: 0.6rem;
    font-weight: 900;
    line-height: 1;
  }

  .calendar-cell.is-won .calendar-day,
  .calendar-cell.is-lost .calendar-day {
    font-size: 0.7rem;
    opacity: 0.85;
  }

  .calendar-cell.is-today {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
  }

  .settings-list {
    padding-top: 3px;
  }

  .setting-row {
    min-height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid var(--line);
  }

  .setting-row span {
    min-width: 0;
    display: flex;
    flex-direction: column;
  }

  .setting-row strong {
    font-size: 0.87rem;
  }

  .setting-row small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.72rem;
    line-height: 1.35;
  }

  .setting-row select {
    min-height: 38px;
    padding: 0 28px 0 10px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--ink);
    font-size: 0.78rem;
    font-weight: 700;
  }

  .switch-input {
    position: relative;
    width: 44px;
    height: 26px;
    flex: 0 0 auto;
    appearance: none;
    border: 0;
    border-radius: 999px;
    background: var(--surface-strong);
    transition: background-color 160ms var(--ease-standard);
  }

  .switch-input::after {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--bg);
    box-shadow: 0 1px 4px oklch(0.08 0 0 / 0.22);
    transition: transform 180ms var(--ease-out);
  }

  .switch-input:checked {
    background: var(--correct);
  }

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

  .settings-note {
    margin-top: 16px;
    color: var(--muted);
    font-size: 0.72rem;
  }

  .toast {
    position: fixed;
    top: calc(76px + env(safe-area-inset-top, 0px));
    left: 50%;
    z-index: var(--z-toast);
    max-width: min(calc(100% - 32px), 420px);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    background: var(--ink);
    color: var(--bg);
    font-size: 0.78rem;
    font-weight: 720;
    line-height: 1.4;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, -10px);
    transition: opacity 170ms var(--ease-standard), transform 200ms var(--ease-out);
  }

  .toast.is-visible {
    opacity: 1;
    transform: translate(-50%, 0);
  }

  noscript {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-toast) + 1);
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--bg);
    color: var(--ink);
    text-align: center;
  }
}

@layer utilities {
  .sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }
}

@keyframes tile-pop {
  0% { transform: scale(0.86); }
  100% { transform: scale(1); }
}

@keyframes tile-reveal {
  0% {
    background: var(--bg);
    box-shadow: inset 0 0 0 2px var(--ink-soft);
    color: var(--ink);
    transform: rotateX(0);
  }
  49% {
    background: var(--bg);
    box-shadow: inset 0 0 0 2px var(--ink-soft);
    color: var(--ink);
    transform: rotateX(90deg);
  }
  50% {
    background: var(--tile-result-bg);
    box-shadow: none;
    color: var(--tile-result-ink);
    transform: rotateX(90deg);
  }
  100% {
    background: var(--tile-result-bg);
    box-shadow: none;
    color: var(--tile-result-ink);
    transform: rotateX(0);
  }
}

@keyframes status-in {
  0%, 54% { opacity: 0; }
  55%, 100% { opacity: 1; }
}

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

@keyframes board-win {
  0%, 100% { transform: scale(1); }
  45% { transform: scale(1.018); }
}

@keyframes celebrate {
  0% { opacity: 0; transform: translate(0, 0) rotate(0deg) scale(0.5); }
  18% { opacity: 1; }
  100% { opacity: 0; transform: translate(var(--piece-x), var(--piece-y)) rotate(var(--piece-rotate)) scale(1); }
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(10px) scale(0.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 880px) {
  .game-shell {
    width: min(calc(100% - 24px), 620px);
    padding-top: 18px;
    grid-template-columns: minmax(0, 1fr);
    gap: 28px;
  }

  .side-column {
    padding: 22px 0 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .side-column:has(.result-panel:not([hidden])) .result-panel {
    order: -1;
  }

  .side-column {
    display: flex;
    flex-direction: column;
  }

  .side-section:first-child {
    padding-top: 14px;
  }

  .side-footnote {
    padding-bottom: 18px;
  }
}

  @media (max-width: 600px) {
  .header-inner {
    width: calc(100% - 16px);
    min-height: 56px;
  }

  .header-actions {
    gap: 0;
  }

  .icon-button {
    width: 44px;
    height: 44px;
  }

  .header-actions .icon-button svg {
    width: 19px;
    height: 19px;
  }

  .game-shell {
    width: calc(100% - 18px);
    padding-top: 12px;
  }

  .mode-tab {
    flex: 1 1 0;
    justify-content: center;
    padding-inline: 8px;
  }

  .puzzle-heading {
    min-height: 62px;
    padding-top: 10px;
    gap: 8px;
  }

  .puzzle-instruction {
    font-size: 0.72rem;
  }

  .tool-button {
    width: 44px;
    min-height: 44px;
    padding: 0;
    justify-content: center;
  }

  .tool-button > span:not(.tool-badge) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .tool-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    font-size: 0.57rem;
  }

  .keyboard-section {
    margin-top: 8px;
  }

  .keyboard-row {
    gap: 3px;
  }

  .key {
    height: 44px;
    border-radius: 6px;
    font-size: clamp(0.58rem, 2.45vw, 0.7rem);
  }

  .key svg {
    width: 16px;
    height: 16px;
  }

  .board-message {
    min-height: 32px;
    padding-top: 7px;
    font-size: 0.7rem;
  }

  .side-column {
    padding-top: 8px;
  }

  .sheet-dialog {
    width: 100%;
    max-width: none;
    max-height: 91dvh;
    margin: auto 0 0;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .sheet-dialog[open] {
    animation-name: sheet-in;
  }

  .dialog-header {
    padding: 18px 14px 13px 20px;
  }

  .dialog-content {
    padding: 19px 20px calc(23px + env(safe-area-inset-bottom, 0px));
  }

  .alphabet-grid {
    gap: 6px;
  }
}

@media (max-width: 380px) {
  .brand > span:last-child {
    display: none;
  }

  .mode-detail {
    display: none;
  }

  .puzzle-kicker {
    font-size: 0.87rem;
  }

  .puzzle-instruction {
    max-width: 180px;
  }

  .board {
    --tile-gap: 5px;
  }

  .stats-summary strong {
    font-size: 1.2rem;
  }

  .stats-summary span {
    font-size: 0.62rem;
  }
}

@media (max-height: 700px) and (max-width: 880px) {
  .game-shell {
    padding-top: 8px;
  }

  .mode-tab {
    min-height: 40px;
    padding-bottom: 8px;
  }

  .puzzle-heading {
    min-height: 54px;
    padding-block: 7px;
  }

  .board {
    --tile-size: min(52px, 12vw, 7.4dvh);
    --tile-gap: 5px;
  }

  .board-message {
    min-height: 27px;
    padding-top: 5px;
  }

  .keyboard-section {
    margin-top: 5px;
  }

  .key {
    height: 40px;
  }
}

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 1ms !important;
    animation-delay: 0ms !important;
    transition-duration: 1ms !important;
  }

  .celebration {
    display: none;
  }
}
