@font-face {
  font-family: 'Inter';
  src: url('fonts/inter.woff2') format('woff2');
  font-weight: 100 900;
  font-display: block;
}

:root {
  /* Ink: a printed puzzle book at night, with one vermilion pen. */
  --bg: #171513;
  --text: #efe6d6;
  --muted: #8f857a;
  --line: #2c2824;
  --tile: #221f1b;
  --accent: #ff5b3a;
  --accent-dim: #a9483a;
  --low: #3a332d;
  --serif: ui-serif, Georgia, 'Times New Roman', serif;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

button {
  font: inherit;
}

/* ---------- header ---------- */

.top {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  height: 56px;
  padding: 0 8px;
}

.top h1 {
  margin: 0;
  padding-left: 4px;
  font-family: var(--serif);
  font-size: 26px;
  font-style: italic;
  font-weight: 400;
}

.icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--muted);
  cursor: pointer;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
}

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 48px;
  padding: 0 28px;
  border: 0;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.primary:active {
  transform: scale(0.98);
}

.meta,
.muted {
  color: var(--muted);
  font-size: 14px;
}

/* ---------- intro ---------- */

.intro {
  margin: auto 0;
  max-width: 360px;
  text-align: center;
}

.logo {
  display: inline-grid;
  grid-template-columns: repeat(3, 40px);
  gap: 4px;
  margin-bottom: 24px;
}

.logo span {
  position: relative;
  height: 40px;
  display: grid;
  place-items: center;
  font-size: 24px;
  color: var(--muted);
}

.logo .odd {
  color: var(--accent);
}

.logo .odd::after,
.cell.found::after,
.cell.missed::after {
  content: '';
  position: absolute;
  inset: 8%;
  border: 2px solid var(--accent);
  border-radius: 50% 46% 52% 44%;
  rotate: -8deg;
}

.intro h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 32px;
  font-style: italic;
  font-weight: 400;
}

.intro p {
  margin: 0 0 24px;
  line-height: 1.5;
}

.intro .primary {
  min-width: 160px;
}

.intro .meta {
  margin: 20px 0 0;
}

/* ---------- play ---------- */

.play {
  /* Fit the tallest grid on screen: header, steps, HUD and footer take about 300px. */
  width: min(460px, 100%, calc((100dvh - 300px) * var(--ratio)));
  min-width: 280px;
}

.steps {
  display: flex;
  gap: 6px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
}

/* Thin pills; the number or score inside stays for screen readers. */
.step {
  flex: 1;
  height: 6px;
  border-radius: 99px;
  background: var(--line);
  font-size: 0;
}

.step.current {
  background: var(--text);
}

.good {
  background: var(--accent);
}

.ok {
  background: var(--accent-dim);
}

.bad {
  background: var(--low);
}

.hud {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 8px;
}

.level {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.tier {
  font-family: var(--serif);
  font-size: 22px;
  font-style: italic;
}

.tier b {
  color: var(--muted);
  font-weight: 400;
}

.points {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-family: var(--serif);
  font-size: 36px;
  font-weight: 400;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.penalty {
  font-size: 14px;
  font-family: Inter, system-ui, sans-serif;
  font-weight: 700;
  color: var(--accent);
  opacity: 0;
}

.penalty.show {
  animation: fade 1s ease-out;
}

@keyframes fade {
  0%,
  50% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

.bar {
  height: 1px;
  margin-bottom: 12px;
  background: var(--line);
}

.fill {
  height: 100%;
  width: 100%;
  background: var(--text);
}

.urgent #pts {
  color: var(--accent);
}

.urgent .fill {
  background: var(--accent);
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  container-type: inline-size;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  position: relative;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--text);
  font-size: calc(100cqi / var(--cols) * 0.6);
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.cell span {
  display: block;
}

@media (hover: hover) {
  .board:not(.over) .cell:hover {
    background: var(--tile);
  }
}

.cell.wrong {
  animation: shake 0.3s;
  color: var(--accent);
}

@keyframes shake {
  25% {
    translate: -3px 0;
  }
  75% {
    translate: 3px 0;
  }
}

.board.over .cell {
  cursor: default;
  color: var(--muted);
  opacity: 0.45;
}

.board.over .cell.found,
.board.over .cell.missed {
  opacity: 1;
  color: var(--accent);
}

/* Missed answers get a dashed circle, in pencil rather than pen. */
.cell.missed {
  color: var(--text) !important;
}

.cell.missed::after {
  border: 2px dashed var(--muted);
}

.board.over .cell::after {
  animation: circle 0.35s ease-out;
}

@keyframes circle {
  from {
    scale: 1.6;
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .board.over .cell::after {
    animation: none;
  }
}

.footer {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.hint {
  width: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.outcome p {
  margin: 0;
}

.o-title {
  font-family: var(--serif);
  font-size: 22px;
  font-style: italic;
}

.o-sub {
  color: var(--muted);
  font-size: 14px;
}

.footer .primary {
  padding: 0 20px;
  background: none;
  color: var(--text);
  box-shadow: inset 0 0 0 1px #5a514a;
}

/* ---------- results ---------- */

.results {
  width: min(420px, 100%);
}

.results .meta {
  margin: 8px 0 0;
}

.final {
  margin: 4px 0 20px;
  font-family: var(--serif);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.final span {
  font-size: 80px;
  letter-spacing: -0.02em;
}

.final small {
  margin-left: 4px;
  font-size: 20px;
  color: var(--muted);
}

.breakdown {
  margin: 0 0 24px;
  padding: 0;
  list-style: none;
  text-align: left;
}

.breakdown li {
  display: grid;
  grid-template-columns: 110px 1fr 64px;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.b-name {
  font-weight: 500;
}

.b-name small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.b-bar {
  height: 2px;
  background: var(--line);
}

.b-bar i {
  display: block;
  height: 100%;
}

.b-score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.b-score em {
  margin-left: 4px;
  font-style: normal;
}

.share {
  width: 100%;
  background: var(--accent);
  color: var(--bg);
}

.stats {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin: 28px 0 0;
}

.stats b {
  display: block;
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.stats span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.next {
  margin: 28px 0 8px;
  color: var(--muted);
}

.next b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

/* ---------- modal, toast ---------- */

dialog {
  width: min(500px, calc(100vw - 32px));
  padding: 32px 24px 24px;
  border: 0;
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--line), 0 4px 23px rgba(0, 0, 0, 0.4);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

dialog h2 {
  margin: 0 0 12px;
  font-family: var(--serif);
  font-size: 28px;
  font-style: italic;
  font-weight: 400;
}

dialog p,
dialog li {
  line-height: 1.5;
}

dialog ul {
  padding-left: 20px;
}

.close {
  position: absolute;
  top: 12px;
  right: 12px;
}

#toast {
  position: fixed;
  top: 72px;
  left: 50%;
  translate: -50% 0;
  padding: 12px 16px;
  border-radius: 4px;
  background: var(--text);
  color: var(--bg);
  font-weight: 700;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

#toast.show {
  opacity: 1;
}

@media (max-width: 400px) {
  .stats b {
    font-size: 22px;
  }
  .breakdown li {
    grid-template-columns: 96px 1fr 58px;
  }
}
