:root {
  --bg: #121417;
  --panel: #1c1f24;
  --text: #f2f2f2;
  --muted: #8b9099;
  --border: #3a3f47;
  --key: #565b63;
  --correct: #4a9d5b;
  --present: #c9a227;
  --absent: #2f333a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body { display: flex; flex-direction: column; }

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
}
.brand { text-align: center; }
.brand h1 { margin: 0; font-size: 1.8rem; letter-spacing: 0.06em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
}
.icon-btn:hover { background: var(--panel); }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 16px 8px;
  position: relative;
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
}

.board {
  display: grid;
  grid-template-rows: repeat(6, 1fr);
  gap: 6px;
  width: min(330px, 90vw);
  aspect-ratio: 5 / 6;
}
.row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.row.shake { animation: shake 0.4s; }

.tile {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  user-select: none;
}
.tile.filled { border-color: #6b717b; animation: pop 0.1s; }
.tile.correct, .tile.present, .tile.absent { border-color: transparent; }
.tile.correct { background: var(--correct); }
.tile.present { background: var(--present); }
.tile.absent  { background: var(--absent); }
.tile.flip { animation: flip 0.5s ease forwards; }
.tile.mini {
  display: inline-flex; width: 32px; height: 32px; font-size: 1rem; margin-right: 8px;
}

.keyboard { width: 100%; margin-top: 16px; }
.krow { display: flex; justify-content: center; gap: 6px; margin-bottom: 8px; }
.key {
  flex: 1;
  max-width: 44px;
  height: 56px;
  border: none;
  border-radius: 6px;
  background: var(--key);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  cursor: pointer;
}
.key.wide { max-width: 68px; font-size: 0.75rem; }
.key.correct { background: var(--correct); }
.key.present { background: var(--present); }
.key.absent  { background: var(--absent); color: var(--muted); }

.toast {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 5;
}
.toast.show { opacity: 1; }

dialog {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  width: min(420px, 92vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { margin-top: 0; }
.close {
  float: right;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.6rem;
  cursor: pointer;
}
.legend { list-style: none; padding: 0; }
.legend li { display: flex; align-items: center; margin: 8px 0; }

.answer-line { font-size: 1.1rem; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); text-align: center; }
.stats strong { display: block; font-size: 1.8rem; }
.stats span { font-size: 0.75rem; color: var(--muted); }

.dist { display: grid; gap: 4px; }
.bar-row { display: flex; align-items: center; gap: 6px; font-size: 0.9rem; }
.bar {
  background: var(--absent);
  padding: 2px 8px;
  text-align: right;
  min-width: 24px;
  font-weight: 700;
}
.bar.hl { background: var(--correct); }

.end-row {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  gap: 12px;
}
.end-row.show { display: flex; }
.small { font-size: 0.8rem; color: var(--muted); }
.countdown { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.share {
  background: var(--correct);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

@keyframes pop { 50% { transform: scale(1.08); } }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(90deg); }
  100% { transform: rotateX(0); }
}

@media (max-height: 640px) {
  .key { height: 46px; }
  .board { width: min(270px, 80vw); }
}
