:root {
  color-scheme: dark;
  --bg: #0a0a0b;
  --ink: #dfdfdf;
  --bright: #ffffff;
  --muted: #888b8d;
  --accent: #e33434;
  --panel: rgba(255, 255, 255, 0.03);
  --line: #2a2a2e;
  --tile: #101012;
  --absent: #232326;
  --present: #b98a1d;
  --correct: #2f9560;
  --key: #1c1c1f;
  --key-hover: #2a2a2e;
  --danger: #e33434;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(ellipse 80% 40% at 50% -10%, rgba(227, 52, 52, 0.12), transparent);
}

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

.app {
  width: min(100%, 520px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 16px 18px 14px;
  display: grid;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.kicker {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: var(--bright);
  font-size: clamp(2rem, 10vw, 3.6rem);
  line-height: 0.9;
  letter-spacing: -0.02em;
}

h1 .cursor {
  display: inline-block;
  width: 0.5em;
  height: 0.74em;
  margin-left: 0.08em;
  background: var(--accent);
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  h1 .cursor { animation: none; }
}

.title-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.version {
  margin-top: 3px;
  padding: 3px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  line-height: 1;
  white-space: nowrap;
}

.topbar-controls {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.zoom-stack {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 30px;
  height: 44px;
}

.zoom-stack button {
  flex: 1;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1;
  display: grid;
  place-items: center;
  transition: border-color 160ms ease, color 160ms ease;
}

.zoom-stack button:hover,
.zoom-stack button:focus-visible {
  border-color: var(--accent);
  color: var(--bright);
}

.icon-button {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 1.45rem;
  display: grid;
  place-items: center;
  transition: border-color 160ms ease, color 160ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--accent);
  color: var(--bright);
}

.ts-link {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-decoration: none;
}

.status-panel {
  min-height: 56px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.status-panel p {
  margin: 0;
  font-weight: 750;
}

.answer-word {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  letter-spacing: 0.05em;
}

.stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  color: var(--muted);
  font-size: 0.86rem;
  white-space: nowrap;
}

.board {
  align-self: center;
  width: min(100%, 330px);
  margin: 0 auto;
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 7px;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
}

.tile {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--tile);
  color: var(--bright);
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: clamp(1.6rem, 8vw, 2.2rem);
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease, color 160ms ease;
}

.tile.filled {
  border-color: var(--muted);
  transform: scale(1.035);
}

.tile.copyable {
  border-color: rgba(47, 149, 96, 0.62);
  box-shadow: inset 0 0 0 2px rgba(47, 149, 96, 0.16);
}

.tile.copyable:hover,
.tile.copyable:focus-visible {
  background: rgba(47, 149, 96, 0.12);
  transform: scale(1.025);
}

.tile.correct,
.tile.present,
.tile.absent {
  color: #fff;
  border-color: transparent;
}

.tile.correct {
  background: var(--correct);
}

.tile.present {
  background: var(--present);
}

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

.tile.cursor-tile {
  border-color: var(--accent);
  background: rgba(227, 52, 52, 0.16);
  animation: tile-blink 1.1s steps(1) infinite;
}

@keyframes tile-blink {
  50% {
    border-color: var(--line);
    background: var(--tile);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile.cursor-tile { animation: none; }
}

.row.shake {
  animation: shake 260ms ease-in-out;
}

.keyboard {
  display: grid;
  gap: 7px;
  touch-action: manipulation;
}

.key-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.key {
  min-width: 0;
  width: 9%;
  height: 48px;
  border-radius: 6px;
  background: var(--key);
  font-size: 0.92rem;
  font-weight: 850;
  text-transform: uppercase;
  transition: background 160ms ease;
}

.key:hover,
.key:focus-visible {
  background: var(--key-hover);
}

.key.wide {
  width: 18%;
  font-size: 1.2rem;
}

.key.correct,
.key.present,
.key.absent {
  color: #fff;
}

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

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

.key.absent {
  background: #4b4b52;
  color: #17171a;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1.3fr auto;
  gap: 10px;
}

.actions button {
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: border-color 160ms ease, color 160ms ease;
}

.actions button:hover:not(:disabled),
.actions button:focus-visible:not(:disabled) {
  border-color: var(--accent);
  color: var(--bright);
}

.actions button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.actions #enter {
  border-color: var(--accent);
  color: var(--bright);
}

.actions #enter:hover,
.actions #enter:focus-visible {
  background: rgba(227, 52, 52, 0.12);
}

.actions #reveal {
  padding-inline: 12px;
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(227, 52, 52, 0.4);
  font-size: 0.7rem;
  font-weight: 750;
}

/* Reveal confirm dialog */
dialog {
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-mono, inherit);
  font: inherit;
  padding: 1.4rem 1.5rem;
  width: min(90vw, 22rem);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
}

dialog h3 {
  margin: 0 0 0.5rem;
  color: var(--bright);
  font-size: 1.05rem;
}

dialog p {
  margin: 0 0 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.dialog-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: flex-end;
}

.dialog-btn {
  padding: 0.55rem 1rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 750;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  transition: border-color 160ms ease, color 160ms ease;
}

.dialog-btn:hover,
.dialog-btn:focus-visible {
  border-color: var(--accent);
  color: var(--bright);
}

.dialog-btn.danger {
  background: transparent;
  color: var(--danger);
  border-color: rgba(227, 52, 52, 0.4);
}

@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  30%, 70% { transform: translateX(4px); }
  50% { transform: translateX(-5px); }
}

@media (max-width: 430px) {
  .app {
    gap: 12px;
    padding-inline: 10px;
  }

  .status-panel {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .stats {
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
  }

  .board,
  .row {
    gap: 6px;
  }

  .key-row {
    gap: 4px;
  }

  .key {
    height: 44px;
    border-radius: 5px;
    font-size: 0.78rem;
  }

  .key.wide {
    font-size: 1.05rem;
  }
}
