/* Cryptogram — Playnesta (MIT). Dark slate shell, amber ink for the cipher. */

:root {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c2430;
  --line: #2b3442;
  --ink: #e8eef7;
  --muted: #92a1b5;
  --accent: #f5b83d;
  --accent-soft: #3a2f12;
  --good: #56d364;
  --bad: #f2777a;
  --cell: 34px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: 980px;
  padding: 14px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── top bar ─────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.title small {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-left: 6px;
}

.spacer {
  flex: 1;
}

.hud {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.hud b {
  color: var(--ink);
  font-weight: 600;
}

.hud .sep {
  opacity: 0.4;
}

#status {
  font-size: 13px;
  color: var(--muted);
  min-height: 18px;
}

/* ── controls ────────────────────────────────────────────────────────── */
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}

.btn:hover {
  border-color: #3d4a5c;
}

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

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #241a03;
  font-weight: 650;
}

.btn.chip {
  border-radius: 999px;
  padding: 6px 14px;
  color: var(--muted);
}

.btn.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 650;
}

/* ── board ───────────────────────────────────────────────────────────── */
#board {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px 16px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 12px 16px;
  min-height: 190px;
  max-height: 46vh;
  overflow: auto;
}

.word {
  display: flex;
  gap: 3px;
  align-items: flex-end;
}

.punct {
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  padding: 0 1px 6px;
}

.cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.cell .cipher {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 17px;
  font-weight: 650;
  color: var(--accent);
  width: var(--cell);
  text-align: center;
  line-height: 1.1;
}

.cell .slot {
  width: var(--cell);
  height: var(--cell);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 7px;
  background: #121821;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 650;
  color: var(--ink);
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.cell .slot.empty {
  color: transparent;
}

.cell.given .cipher {
  color: var(--muted);
  opacity: 0.75;
}

.cell.given .slot {
  background: #10161f;
  border-color: #222b38;
  color: #9fb0c4;
}

.cell.selected .slot {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(245, 184, 61, 0.22);
}

.cell.peek .slot {
  background: var(--accent-soft);
}

.cell.wrong .slot {
  border-color: var(--bad);
  color: var(--bad);
}

/* ── the wrong-letter flash ──────────────────────────────────────────── */
@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-2px);
  }
  75% {
    transform: translateX(2px);
  }
}

.cell.flash .slot {
  animation: shake 180ms ease;
}

/* ── keyboard ────────────────────────────────────────────────────────── */
.keyboard {
  display: grid;
  grid-template-columns: repeat(13, minmax(0, 1fr));
  gap: 6px;
}

.key {
  appearance: none;
  font: inherit;
  font-size: 14px;
  font-weight: 620;
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--ink);
  cursor: pointer;
  transition: background 110ms ease, color 110ms ease, border-color 110ms ease;
}

.key:hover {
  border-color: #3d4a5c;
}

.key.used {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.key.given {
  background: #12161d;
  border-color: #222b38;
  color: #5d6b7d;
}

.legend {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--muted);
}

/* ── win overlay ─────────────────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 12, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 30;
}

.overlay[hidden] {
  display: none;
}

.card {
  width: min(520px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.cracked {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--good);
  font-weight: 700;
}

.card h2 {
  margin: 6px 0 10px;
  font-size: 18px;
}

.card .quote {
  margin: 0 0 4px;
  font-size: 16px;
  line-height: 1.55;
  font-weight: 600;
}

.card .source {
  margin: 0 0 16px;
  font-size: 12px;
  color: var(--muted);
}

.stats {
  display: flex;
  gap: 18px;
  margin: 0 0 18px;
}

.stats div {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stats dt {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.stats dd {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ── toast ───────────────────────────────────────────────────────────── */
#toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(8px);
  background: #10161f;
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 12.5px;
  padding: 8px 14px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 40;
  max-width: min(90vw, 420px);
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── phones ──────────────────────────────────────────────────────────── */
@media (max-width: 620px) {
  :root {
    --cell: 30px;
  }

  #app {
    padding: 10px 12px 14px;
    gap: 9px;
  }

  .title {
    font-size: 17px;
  }

  .title small {
    display: none;
  }

  #board {
    min-height: 160px;
    max-height: 42vh;
    padding: 14px 12px;
    gap: 10px 12px;
  }

  .keyboard {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  .key {
    min-height: 40px;
  }

  .legend {
    display: none;
  }
}

@media (max-width: 380px) {
  .keyboard {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}
