:root {
  --paper: #ffffff;
  --card: #ffffff;
  --ink: #16233b;
  --muted: #56637a;
  --line: #c5cfdc;
  --correct: #1e8a6b;
  --present: #f0b429;
  --absent: #7c8798;
  --on-correct: #ffffff;
  --on-present: #16233b;
  --on-absent: #ffffff;
  --accent: #2f5fb3;
  --key: #e6eaf0;
  --gap: 4px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 1rem;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 30rem;
  margin: 0 auto;
  padding: 0 1rem env(safe-area-inset-bottom);
}

.top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-top: 1.75rem;
}

h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.link {
  border: 0;
  background: none;
  padding: 0.25rem 0;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.daynav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1.25rem;
  padding: 0.25rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
}

.daynav .when {
  text-align: center;
  line-height: 1.15;
}

.daynav .when strong {
  display: block;
  font-size: 1.0625rem;
  font-weight: 700;
}

.daynav .when span {
  font-size: 0.875rem;
  color: var(--muted);
}

.step {
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: var(--paper);
  font-size: 1.25rem;
  font-weight: 700;
}

.step:disabled {
  background: none;
  color: var(--line);
  cursor: default;
}

.clue {
  padding: 1.25rem 0 0.75rem;
}

.clue p {
  margin: 0;
}

.clue .what {
  /* Always two lines tall, so the board starts at the same height for every clue. */
  min-height: 2.8em;
  font-weight: 600;
}

/* Fixed-height row: the button and the hint text swap in place, count on the right. */
.clue .hintslot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  height: 2.5rem;
  margin-top: 0.25rem;
}

.clue .trip {
  min-width: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.clue .count {
  flex: none;
  margin-left: auto;
  white-space: nowrap;
  font-size: 0.875rem;
  color: var(--muted);
}

@media (max-width: 389px) {
  .clue .count .label {
    display: none;
  }
  .clue .trip {
    font-size: 0.8125rem;
  }
}

.pill {
  flex: none;
  padding: 0.35rem 0.9rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: none;
  font-weight: 700;
}

.board {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 0.25rem 0 0.75rem;
  --tile: min(3rem, calc((min(100vw, 30rem) - 2rem) / var(--cols, 5) - var(--gap)));
}

.row,
.line,
.word {
  display: flex;
}

.row {
  flex-direction: column;
  align-items: center;
  gap: var(--gap);
}

.line {
  gap: calc(var(--tile) * 0.6);
}

.word {
  gap: var(--gap);
}

.tile,
.fixed {
  display: grid;
  place-items: center;
  height: var(--tile);
  font-size: calc(var(--tile) * 0.56);
  font-weight: 800;
  line-height: 1;
}

.tile {
  width: var(--tile);
  border: 1px solid var(--line);
  border-radius: calc(var(--tile) * 0.16);
  background: var(--card);
}

.fixed {
  width: calc(var(--tile) * 0.5 - var(--gap));
  color: var(--muted);
}

.tile.filled {
  border-color: var(--ink);
}

.tile.cursor {
  border-color: var(--accent);
  box-shadow: inset 0 -3px 0 var(--accent);
}

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: var(--on-correct);
}

.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: var(--on-present);
}

.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: var(--on-absent);
}

.row.reveal .tile {
  animation: flip 420ms ease-in-out backwards;
  animation-delay: calc(var(--i) * var(--stagger));
}

.row.shake {
  animation: shake 320ms ease-in-out;
}

@keyframes flip {
  0%,
  49% {
    background: var(--card);
    border-color: var(--ink);
    color: var(--ink);
  }
  0% {
    transform: rotateX(0);
  }
  50% {
    transform: rotateX(90deg);
  }
  100% {
    transform: rotateX(0);
  }
}

@keyframes shake {
  20%,
  60% {
    transform: translateX(-6px);
  }
  40%,
  80% {
    transform: translateX(6px);
  }
}

.notice {
  margin: auto 0;
  text-align: center;
  font-size: 1.125rem;
  font-weight: 600;
}

.dock {
  padding-bottom: 0.75rem;
}

.keys {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.keys .krow {
  display: flex;
  justify-content: center;
  gap: 5px;
}

.key {
  flex: 1 1 0;
  min-width: 0;
  height: 3.25rem;
  border: 0;
  border-radius: 6px;
  background: var(--key);
  font-size: 1.0625rem;
  font-weight: 700;
  padding: 0;
}

.key.wide {
  flex: 1.6 1 0;
  font-size: 0.875rem;
}

.key.correct {
  background: var(--correct);
  color: var(--on-correct);
}

.key.present {
  background: var(--present);
  color: var(--on-present);
}

.key.absent {
  background: var(--absent);
  color: var(--on-absent);
  opacity: 0.55;
}

.krow.inset {
  padding: 0 5%;
}

.result {
  border: 1px solid var(--ink);
  border-radius: 14px;
  background: var(--card);
  overflow: hidden;
}

.result .body {
  padding: 0.875rem 1rem 1rem;
}

.result h2 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.result p {
  margin: 0.25rem 0 0;
}

.result .meta {
  color: var(--muted);
}

.result .note {
  font-weight: 600;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.875rem;
}

.btn {
  flex: 1 1 auto;
  padding: 0.7rem 1rem;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: none;
  font-weight: 700;
}

.btn.primary {
  background: var(--ink);
  color: var(--paper);
}

.days {
  width: min(28rem, calc(100vw - 2rem));
  max-height: calc(100dvh - 4rem);
  padding: 1rem;
  border: 1px solid var(--ink);
  border-radius: 14px;
  background: var(--paper);
  color: var(--ink);
}

.days::backdrop {
  background: rgb(22 35 59 / 0.4);
}

.days header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.days h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
}

.days p {
  margin: 0.25rem 0 0.75rem;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.25rem, 1fr));
  gap: 6px;
}

.daybtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  line-height: 1.1;
}

.daybtn strong {
  font-size: 1.0625rem;
  font-weight: 700;
}

.daybtn span {
  font-size: 0.75rem;
}

.daybtn.started {
  border-color: var(--present);
  box-shadow: inset 0 -5px 0 var(--present);
}

.daybtn.solved {
  background: var(--correct);
  border-color: var(--correct);
  color: var(--on-correct);
}

.daybtn.current {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

.toast {
  position: fixed;
  left: 50%;
  top: 5.5rem;
  transform: translateX(-50%);
  padding: 0.6rem 1rem;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 150ms;
}

.toast.show {
  opacity: 1;
}

@media (max-height: 640px) {
  .key {
    height: 2.75rem;
  }
  .board {
    --tile: min(2.5rem, calc((min(100vw, 30rem) - 2rem) / var(--cols, 5) - var(--gap)));
  }
}

@media (prefers-reduced-motion: reduce) {
  .row.reveal .tile,
  .row.shake {
    animation: none;
  }
  .toast {
    transition: none;
  }
}
