/* Drewdle: dark Wordle-style board. */
:root {
  --bg: #121213;
  --panel: #1c1c1e;
  --panel2: #2a2a2c;
  --text: #d7dadc;
  --muted: #8f9397;
  --line: #3a3a3c;
  --c: #538d4e;
  --p: #b59f3b;
  --a: #3a3a3c;
  --key: #818384;
  --accent: #6aaa64;
  --bad: #ff6b6b;
}

* { box-sizing: border-box; }
html { background: var(--bg); color-scheme: dark; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

.app {
  height: 100vh;
  height: 100dvh;
  max-width: 620px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

/* ---------- header ---------- */
header.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}
header.top h1 { margin: 0; font-size: 1.6rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.top-side { display: flex; gap: 2px; }
.top-side.right { justify-content: flex-end; }
.icon-btn { background: none; border: 0; color: var(--text); width: 40px; height: 40px; border-radius: 8px; cursor: pointer; padding: 8px; }
.icon-btn:hover { background: var(--panel2); }
.icon-btn svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.sub { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 4px 14px; color: var(--muted); font-size: .85rem; min-height: 30px; }
.sub-actions { display: flex; gap: 12px; }
.link-btn { background: none; border: 0; color: var(--accent); font: inherit; font-size: .85rem; cursor: pointer; padding: 2px 0; text-decoration: underline; text-underline-offset: 3px; }
.link-btn:hover { color: #fff; }

/* ---------- board ---------- */
#board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px 10px; }
.board { --tile: 52px; display: grid; gap: 5px; }
.row { display: grid; grid-template-columns: repeat(var(--cols), var(--tile)); gap: 5px; }
.tile {
  width: var(--tile); height: var(--tile);
  border: 2px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: calc(var(--tile) * 0.55);
  font-weight: 700; text-transform: uppercase; line-height: 1;
  user-select: none;
  transition: transform .25s ease-in;
}
.tile[data-state="tbd"] { border-color: #565758; }
.tile[data-state="c"] { background: var(--c); border-color: var(--c); color: #fff; }
.tile[data-state="p"] { background: var(--p); border-color: var(--p); color: #fff; }
.tile[data-state="a"] { background: var(--a); border-color: var(--a); color: #fff; }
.tile.flip { transform: rotateX(90deg); }
.tile.pop { animation: pop .1s ease-in-out; }
.row.shake { animation: shake .5s; }
.row.bounce .tile { animation: bounce .8s; }
@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes shake { 10%, 90% { transform: translateX(-1px); } 20%, 80% { transform: translateX(2px); } 30%, 50%, 70% { transform: translateX(-4px); } 40%, 60% { transform: translateX(4px); } }
@keyframes bounce { 0%, 20% { transform: translateY(0); } 40% { transform: translateY(-14px); } 60% { transform: translateY(3px); } 80% { transform: translateY(-4px); } 100% { transform: translateY(0); } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: 90px; transform: translateX(-50%);
  background: #e7e8ea; color: #121213; font-weight: 700;
  padding: 10px 16px; border-radius: 6px; box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }

/* ---------- keyboard ---------- */
.keyboard { padding: 4px 6px 10px; }
.krow { display: flex; justify-content: center; gap: 6px; margin-bottom: 8px; }
.key {
  height: 56px; flex: 1; max-width: 44px;
  border: 0; border-radius: 4px; background: var(--key); color: #fff;
  font: inherit; font-weight: 700; text-transform: uppercase; font-size: .95rem;
  cursor: pointer; user-select: none; touch-action: manipulation;
}
.key.wide { max-width: 68px; flex: 1.6; font-size: .75rem; text-transform: none; }
.key[data-state="c"] { background: var(--c); }
.key[data-state="p"] { background: var(--p); }
.key[data-state="a"] { background: var(--a); }
.key:active { filter: brightness(1.2); }

/* ---------- buttons and dialogs ---------- */
button.btn, .dialog-actions button {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 14px; cursor: pointer;
}
.dialog-actions button:hover { background: #343437; }
.dialog-actions button.primary { background: var(--c); border-color: var(--c); color: #fff; }
.dialog-actions button.primary:hover { background: #5f9c59; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px;
  padding: 20px 22px; width: min(92vw, 480px); max-height: 90vh; box-shadow: 0 20px 60px rgba(0, 0, 0, .65);
}
dialog::backdrop { background: rgba(0, 0, 0, .6); }
dialog h2 { margin: 0 0 10px; font-size: 1.3rem; text-transform: uppercase; letter-spacing: .04em; }
dialog h3 { margin: 14px 0 6px; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
dialog p { margin: 8px 0; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
.note { color: var(--muted); font-size: .9em; }

.example { margin: 6px 0; }
.ex-row { display: flex; gap: 4px; margin-top: 10px; }
.ex-row .tile { width: 34px; height: 34px; font-size: 1.1rem; }

.chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.chip {
  font: inherit; color: var(--text); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; line-height: 1.15;
}
.chip b { font-size: 1.1rem; }
.chip small { color: var(--muted); font-size: .68rem; }
.chip.on { border-color: var(--accent); background: #23372a; }
.chip:disabled { opacity: .4; cursor: default; }

.choices { display: grid; gap: 6px; }
.choices.row { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.choice {
  display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg); cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: #1d2b20; }
.choice input { margin: 3px 0 0; }
.choice small { display: block; color: var(--muted); }

.end-word { font-size: 1.1rem; }
.end-word .word { font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #fff; text-decoration: underline dotted; text-underline-offset: 4px; }
#share-fallback { width: 100%; margin-top: 10px; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-family: inherit; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin: 8px 0 4px; }
.stat-grid b { display: block; font-size: 1.6rem; font-weight: 500; }
.stat-grid small { color: var(--muted); font-size: .72rem; }
.dist { margin-top: 8px; }
.dist-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; font-size: .85rem; }
.dist-row .n { width: 1.2em; text-align: right; color: var(--muted); }
.dist-row .bar { background: var(--a); color: #fff; padding: 1px 6px; min-width: 1.4em; text-align: right; font-weight: 700; border-radius: 2px; }
.dist-row .bar.mine { background: var(--c); }

@media (max-width: 420px) {
  header.top h1 { font-size: 1.3rem; }
  .key { height: 50px; font-size: .85rem; }
  .krow { gap: 4px; margin-bottom: 6px; }
  dialog { padding: 16px; }
  .chips { grid-template-columns: repeat(5, 1fr); }
}
