:root {
  --bg: #f4f3ef;
  --ink: #141412;
  --green: #2f7d4f;
  --yellow: #c99424;
  --grey: #8a8983;
  --red: #b3261e;
  --muted: #5f5e58;
  --empty-border: #898883;
  --mark-ink: #141412;
  --mark-paper: #ffffff;
  --tile-fill: #fffcf6;
  --hatch: rgba(20, 20, 18, 0.22);
  --key-bg: #e4e1d8;
  --key-text: #141412;
  --tile: 36px;
  --tile-max: 38px;
  --gap: 8px;
  color-scheme: light;
  background: var(--bg);
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --ink: #f4f3ef;
    --red: #ff8f86;
    --muted: #b7b5ad;
    --empty-border: #7a7872;
    --tile-fill: #242320;
    --hatch: rgba(244, 243, 239, 0.2);
    --key-bg: #2e2c28;
    --key-text: #f4f3ef;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.3;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

:focus,
:focus-visible {
  outline: none;
  outline-offset: 0;
}

.app {
  width: min(440px, 100%);
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  padding:
    max(16px, env(safe-area-inset-top))
    max(18px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(18px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-x: hidden;
  overflow-y: auto;
}

.title {
  margin: 0;
  text-align: center;
  font-family: "Chivo", "Arial Black", sans-serif;
  font-weight: 800;
  font-size: clamp(26px, 7vw, 34px);
  letter-spacing: -0.045em;
  line-height: 0.95;
  user-select: none;
}

.rule {
  margin: 12px auto 0;
  max-width: 28em;
  text-align: center;
  font-size: 14px;
  line-height: 1.45;
}

.modebar {
  display: flex;
  justify-content: center;
  margin-top: 16px;
}

.tabs { display: flex; gap: 24px; }

.tab {
  border: none;
  border-bottom: 2px solid transparent;
  background: none;
  padding: 6px 2px 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
}

.tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--ink);
  font-weight: 700;
}

.message {
  flex: 0 0 auto;
  min-height: 1.25em;
  margin: 0;
  text-align: center;
  font-size: 14px;
  font-weight: 700;
}

.message.alert { color: var(--red); }

.message.plain { color: var(--ink); }

.board-wrap {
  flex: 0 0 auto;
  width: 100%;
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  grid-template-rows: repeat(var(--rows, 8), var(--tile));
  gap: var(--gap);
  width: calc(var(--tile) * 5 + var(--gap) * 4);
  user-select: none;
}

.row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile));
  gap: var(--gap);
  height: var(--tile);
}

.tile {
  width: var(--tile);
  height: var(--tile);
  padding: 0;
  border: 2px solid var(--empty-border);
  border-radius: 4px;
  background: transparent;
  color: var(--ink);
  font-family: "Chivo", "Arial Black", sans-serif;
  font-weight: 800;
  font-size: calc(var(--tile) * 0.52);
  line-height: 1;
  text-transform: uppercase;
  display: grid;
  place-items: center;
  cursor: default;
  user-select: none;
}

.tile.typed {
  background: var(--tile-fill);
  border-color: var(--ink);
}

.tile.covered,
.tile.pickable {
  background-color: var(--tile-fill);
  background-image: repeating-linear-gradient(
    -45deg,
    transparent 0 3px,
    var(--hatch) 3px 4.5px
  );
  color: var(--muted);
}

.tile.pickable {
  border-color: var(--ink);
  cursor: pointer;
}

@media (hover: hover) {
  .tile.pickable:hover {
    border-color: var(--red);
    color: var(--red);
  }
}

.tile.revealed {
  color: var(--mark-paper);
  border-color: transparent;
}

.tile.green { background: var(--green); }
.tile.yellow { background: var(--yellow); color: var(--mark-ink); }
.tile.grey { background: var(--grey); color: var(--mark-ink); }

.end {
  flex: 0 0 auto;
  text-align: center;
  padding: 4px 0 0;
}

.reaction {
  margin: 0;
  font-family: "Chivo", "Arial Black", sans-serif;
  font-weight: 800;
  font-size: 17px;
  line-height: 1.1;
}

.answer {
  margin: 8px 0 0;
  font-family: "Chivo", "Arial Black", sans-serif;
  font-weight: 800;
  font-size: clamp(18px, 5vw, 24px);
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  line-height: 1.1;
}

.end-line {
  margin: 6px 0 10px;
  font-size: 14px;
}

.end-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.end-actions button {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 6px;
  cursor: pointer;
}

.secondary {
  background: transparent;
  border: 2px solid var(--ink);
}

.primary {
  background: var(--ink);
  color: var(--bg);
  border: 2px solid var(--ink);
  font-weight: 700;
}

@media (hover: hover) {
  .primary:hover { filter: brightness(1.25); }
  .secondary:hover { background: var(--key-bg); }
}

.share-fallback {
  display: block;
  width: 100%;
  margin: 8px 0 0;
  height: 6.6em;
  min-height: 0;
  flex: 0 0 auto;
  padding: 8px;
  resize: vertical;
  border: 2px solid var(--empty-border);
  border-radius: 6px;
  background: var(--tile-fill);
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.keyboard {
  flex: 0 0 auto;
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  user-select: none;
}

.keyboard.dim { opacity: 0.4; }

.kb-row { display: grid; gap: 6px; }

.kb-row.top { grid-template-columns: repeat(10, 1fr); }

.kb-row.mid {
  width: 90%;
  margin: 0 auto;
  grid-template-columns: repeat(9, 1fr);
}

.kb-row.bot { grid-template-columns: 1.55fr repeat(7, 1fr) 1.55fr; }

.key {
  height: clamp(36px, 4.8dvh, 42px);
  min-width: 0;
  padding: 0 2px;
  border: 1px solid var(--empty-border);
  border-radius: 4px;
  background: var(--key-bg);
  color: var(--key-text);
  font-weight: 700;
  font-size: clamp(11px, 3.1vw, 15px);
  cursor: pointer;
}

.key.wide { font-size: clamp(10px, 2.6vw, 13px); }

.key.green { background: var(--green); color: var(--mark-paper); border-color: transparent; }
.key.yellow { background: var(--yellow); color: var(--mark-ink); border-color: transparent; }
.key.grey { background: var(--grey); color: var(--mark-ink); border-color: transparent; opacity: 0.35; }

.key:active { transform: scale(0.96); }

.app.ended .message:empty { display: none; }

.credit {
  flex: 0 0 auto;
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

@keyframes pop {
  0% { transform: scale(0.82); }
  55% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

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

@keyframes iris {
  from { clip-path: circle(0% at 50% 50%); }
  to { clip-path: circle(75% at 50% 50%); }
}

.tile.pop { animation: pop 0.12s ease; }
.row.shake { animation: shake 0.42s ease; }
.tile.iris { animation: iris 0.34s linear forwards; }

@media (prefers-reduced-motion: reduce) {
  .tile.pop,
  .row.shake,
  .tile.iris { animation: none !important; }
  .tile.iris { clip-path: none; }
  .key:active { transform: none; }
}

@media (max-height: 720px) {
  .app { gap: 10px; padding-top: 14px; padding-bottom: 14px; }
  .title { font-size: 26px; }
  .rule { margin-top: 8px; }
  .modebar { margin-top: 10px; }
  .keyboard { gap: 6px; margin-top: 16px; }
}
