:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --border: #cbd5e1;
  --empty: #ffffff;
  --filled: #f8fafc;
  --absent: #64748b;
  --present: #d99f22;
  --correct: #2e7d32;
  --key: #e2e8f0;
  --key-text: #0f172a;
  --shadow: 0 24px 80px rgba(15, 23, 42, 0.18);
  --radius: 18px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #020617;
  --surface: #0f172a;
  --surface-2: #1e293b;
  --text: #f8fafc;
  --muted: #94a3b8;
  --border: #334155;
  --empty: #020617;
  --filled: #111827;
  --absent: #1c2431;
  --present: #b88920;
  --correct: #2f8f46;
  --key: #334155;
  --key-text: #f8fafc;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

:root[data-contrast="high"] {
  --present: #2563eb;
  --correct: #f97316;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at top, rgba(34, 197, 94, 0.14), transparent 28rem), var(--bg);
  color: var(--text);
  touch-action: manipulation;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, background 160ms ease;
}

button:active {
  transform: scale(0.94);
}

.app-shell {
  width: min(100%, 680px);
  height: 100%;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: max(12px, env(safe-area-inset-top)) 14px calc(10px + var(--safe-bottom));
}

.topbar {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 4px 0 10px;
  border-bottom: 1px solid var(--border);
}

.title-lockup {
  text-align: center;
  min-width: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1 {
  margin: -1px 0 0;
  font-size: clamp(1.45rem, 6vw, 2.25rem);
  line-height: 1;
  letter-spacing: -0.06em;
}

.header-actions {
  display: flex;
  gap: 6px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible {
  background: var(--surface-2);
  outline: none;
}

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

.game {
  flex: 1;
  display: grid;
  grid-template-rows: auto 1fr auto auto;
  gap: 12px;
  padding-top: 12px;
}

.status-card {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.status-card > div {
  min-width: 0;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.status-card strong {
  display: block;
  overflow: hidden;
  margin-top: 3px;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: clamp(0.78rem, 3vw, 0.98rem);
}

.board {
  align-self: stretch;
  justify-self: center;
  width: auto;
  min-width: 156px;
  min-height: 156px;
  max-width: min(100%, 390px);
  aspect-ratio: 1;
  margin: 0 auto;
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 7px;
  padding: 4px 0;
}

.board-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 7px;
  min-height: 0;
  perspective: 800px;
}

.tile {
  min-height: 0;
  display: grid;
  place-items: center;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--empty);
  color: var(--text);
  font-size: clamp(1.3rem, 8vw, 2.2rem);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

.tile-wide-letter {
  font-size: clamp(0.85rem, 5vw, 1.35rem);
  letter-spacing: -0.02em;
}

.tile[data-state="filled"] {
  border-color: color-mix(in srgb, var(--text) 60%, var(--border));
  background: var(--filled);
  animation: tilePop 160ms ease-out;
}

.tile[data-state="correct"],
.tile[data-state="present"],
.tile[data-state="absent"] {
  color: #ffffff;
  border-color: transparent;
}

.tile[data-state="correct"] { background: var(--correct); }
.tile[data-state="present"] { background: var(--present); }
.tile[data-state="absent"] { background: var(--absent); }

.tile.flip {
  animation: tileFlip 480ms ease-in-out backwards;
}

.tile.bounce {
  animation: tileBounce 620ms ease backwards;
}

@keyframes tilePop {
  0% { transform: scale(0.9); }
  45% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

@keyframes tileFlip {
  0% { transform: rotateX(0deg); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0deg); }
}

@keyframes tileBounce {
  0%, 100% { transform: translateY(0); }
  25% { transform: translateY(-22%); }
  50% { transform: translateY(6%); }
  75% { transform: translateY(-8%); }
}

.message {
  min-height: 34px;
  display: grid;
  place-items: center;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 140ms ease, transform 140ms ease;
  color: var(--text);
  font-weight: 800;
  text-align: center;
}

.message.show {
  opacity: 1;
  transform: translateY(0);
}

.keyboard {
  display: grid;
  gap: 7px;
  padding-bottom: calc(2px + var(--safe-bottom));
}

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

.key {
  min-width: 0;
  width: 9.2%;
  max-width: 44px;
  height: clamp(48px, 13vw, 58px);
  border: 0;
  border-radius: 10px;
  background: var(--key);
  color: var(--key-text);
  font-size: clamp(0.83rem, 3.5vw, 1rem);
  font-weight: 900;
  cursor: pointer;
  text-transform: uppercase;
}

.wide-key {
  width: 15.2%;
  max-width: 74px;
  font-size: clamp(0.64rem, 2.8vw, 0.8rem);
}

.double-key {
  width: 11.4%;
  max-width: 52px;
  font-size: clamp(0.66rem, 2.8vw, 0.82rem);
}

.key[data-state="correct"],
.key[data-state="present"],
.key[data-state="absent"] {
  color: #ffffff;
}

.key[data-state="correct"] { background: var(--correct); }
.key[data-state="present"] { background: var(--present); }
.key[data-state="absent"] { background: var(--absent); }

.key:active {
  transform: translateY(1px);
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding: 16px;
  background: rgba(2, 6, 23, 0.54);
  backdrop-filter: blur(10px);
  opacity: 1;
  transition: opacity 220ms ease, backdrop-filter 220ms ease;
}

.modal-root.hidden {
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(0px);
}

.modal-card {
  position: relative;
  width: min(100%, 520px);
  max-height: min(86dvh, 720px);
  overflow: auto;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateY(0) scale(1);
  opacity: 1;
  transition: transform 260ms cubic-bezier(.2, .8, .2, 1), opacity 220ms ease;
}

.modal-root.hidden .modal-card {
  transform: translateY(24px) scale(0.98);
  opacity: 0;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.modal-card h2,
.modal-card h3 {
  margin: 0 44px 14px 0;
}

.modal-card h2 {
  font-size: 1.55rem;
}

.modal-card h3 {
  margin-top: 22px;
  font-size: 1rem;
}

.modal-card p {
  color: var(--muted);
  line-height: 1.55;
}

.example-grid {
  display: grid;
  grid-template-columns: repeat(6, 38px);
  gap: 6px;
  margin-top: 14px;
}

.example-grid .tile {
  aspect-ratio: 1;
  border-radius: 9px;
  font-size: 1.1rem;
}

.example-grid .tile-wide-letter {
  font-size: 0.72rem;
}

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

.stats-grid div {
  padding: 12px 6px;
  border: 1px solid var(--border);
  border-radius: 14px;
  text-align: center;
  background: var(--surface-2);
}

.stats-grid strong {
  display: block;
  font-size: 1.55rem;
}

.stats-grid span {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
}

.distribution {
  display: grid;
  gap: 7px;
}

.distribution-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 8px;
  font-weight: 800;
}

.distribution-track {
  height: 25px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.distribution-bar {
  min-width: 0;
  width: 0;
  height: 100%;
  display: grid;
  place-items: center end;
  padding-right: 8px;
  border-radius: 999px;
  background: var(--correct);
  color: #ffffff;
  font-size: 0.78rem;
  transition: width 600ms cubic-bezier(.2, .8, .2, 1);
}

.result-line {
  color: var(--text) !important;
  font-weight: 800;
}

.word-meaning {
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text) !important;
  font-size: 0.85rem;
  line-height: 1.45;
}

.word-meaning strong {
  letter-spacing: 0.02em;
}

.setting-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid var(--border);
}

.setting-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
}

.setting-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--correct);
}

.time-note {
  margin-top: 16px;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface-2);
}

.time-note p {
  margin: 4px 0 0;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}

.primary-button,
.text-button {
  min-height: 44px;
  border-radius: 999px;
  padding: 0 18px;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  border: 0;
  background: var(--correct);
  color: #ffffff;
}

.primary-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.text-button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
}

.text-button.danger {
  color: #dc2626;
}

.muted {
  color: var(--muted);
}

.credits {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
}

.credits p {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.credits a {
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.credits a:hover,
.credits a:focus-visible {
  text-decoration: underline;
}

.landing {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 24px 12px calc(24px + var(--safe-bottom));
  text-align: center;
}

.landing-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 380px;
}

.landing-preview {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  width: min(100%, 300px);
  margin-bottom: 6px;
}

.landing-preview .tile {
  aspect-ratio: 1;
  border-radius: 8px;
  font-size: 1.1rem;
  animation: tilePop 220ms ease-out backwards;
}

.landing-preview .tile-wide-letter {
  font-size: 0.68rem;
}

.landing-preview .tile:nth-child(1) { animation-delay: 0ms; }
.landing-preview .tile:nth-child(2) { animation-delay: 70ms; }
.landing-preview .tile:nth-child(3) { animation-delay: 140ms; }
.landing-preview .tile:nth-child(4) { animation-delay: 210ms; }
.landing-preview .tile:nth-child(5) { animation-delay: 280ms; }
.landing-preview .tile:nth-child(6) { animation-delay: 350ms; }

.landing-title {
  margin: 0;
  font-size: clamp(2.2rem, 10vw, 3.2rem);
  letter-spacing: -0.05em;
  line-height: 1.05;
}

.landing-tagline {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.98rem;
}

.landing-play {
  width: 100%;
  max-width: 220px;
  min-height: 52px;
  font-size: 1.05rem;
  margin-top: 10px;
}

.landing-meta {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.landing-credits {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.shake {
  animation: shake 420ms cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

@media (min-width: 720px) {
  .app-shell {
    padding-inline: 24px;
  }

  .game {
    gap: 18px;
  }

  .modal-root {
    place-items: center;
  }
}

@media (max-height: 690px) {
  .app-shell {
    padding-top: 8px;
  }

  .topbar {
    padding-bottom: 7px;
  }

  .status-card {
    display: none;
  }

  .game {
    gap: 7px;
  }

  .board {
    max-width: 330px;
    gap: 5px;
  }

  .board-row {
    gap: 5px;
  }

  .tile {
    border-radius: 10px;
  }

  .key {
    height: 45px;
  }
}

:root[data-motion="reduced"] *,
:root[data-motion="reduced"] *::before,
:root[data-motion="reduced"] *::after {
  animation: none !important;
  transition: none !important;
  scroll-behavior: auto !important;
}
