:root {
  --ink: #1c2421;
  --ink-soft: #3d4a45;
  --paper: #f3efe6;
  --paper-deep: #e4ddd0;
  --line: #c9c0b0;
  --accent: #0f6e56;
  --accent-ink: #f7faf8;
  --danger: #9b3b2e;
  --shadow: 0 18px 40px rgba(28, 36, 33, 0.08);

  --word-0: #c45c26;
  --word-1: #0f6e56;
  --word-2: #2f5d8c;
  --word-3: #8a6d1f;
  --word-4: #7a3e6c;

  --tile: #fbf8f1;
  --tile-used: #ddd6c8;
  --tile-active: #d8efe6;
  --radius: 10px;

  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;

  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, #dce9e2 0%, transparent 55%),
    radial-gradient(ellipse 70% 45% at 100% 0%, #efe2d0 0%, transparent 50%),
    linear-gradient(180deg, var(--paper) 0%, var(--paper-deep) 100%);
  line-height: 1.45;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.035;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.site-header,
main,
.site-footer {
  width: min(440px, calc(100% - 2rem));
  margin-inline: auto;
}

.site-header {
  padding: 1.75rem 0 0.75rem;
  text-align: center;
  animation: rise 0.7s ease both;
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 9vw, 3.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.puzzle-meta {
  margin: 0.35rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 600;
}

.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.35rem;
}

.date-nav time {
  min-width: 7.5rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.btn-nav {
  appearance: none;
  width: 2rem;
  height: 2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
}

.btn-nav:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.meta-sep {
  margin-inline: 0.35rem;
}

main {
  padding-bottom: 2.5rem;
}

.scoreboard {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0.5rem 0 1rem;
  animation: rise 0.7s ease 0.05s both;
}

.score-line {
  margin: 0;
  display: flex;
  gap: 0.55rem;
  align-items: baseline;
}

.score-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-soft);
}

.score-value {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.words-left {
  margin: 0;
  color: var(--ink-soft);
  font-weight: 600;
}

.board-section {
  animation: rise 0.7s ease 0.1s both;
}

.board-wrap {
  position: relative;
  background: color-mix(in srgb, var(--tile) 88%, white);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 6px);
  padding: 0.7rem;
  box-shadow: var(--shadow);
}

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.45rem;
  touch-action: none;
  user-select: none;
}

.path-layer {
  position: absolute;
  inset: 0.7rem;
  width: calc(100% - 1.4rem);
  height: calc(100% - 1.4rem);
  pointer-events: none;
  overflow: visible;
  z-index: 2;
}

.path-layer .word-path {
  fill: none;
  stroke-width: 4.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.9;
}

.path-layer .draft-path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.55;
  stroke-dasharray: 2 8;
}

.tile {
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  border-radius: var(--radius);
  aspect-ratio: 1;
  background: var(--tile);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 6vw, 1.7rem);
  font-weight: 700;
  cursor: pointer;
  position: relative;
  z-index: 1;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    transform 0.12s ease,
    opacity 0.2s ease;
}

.tile:hover:not(:disabled) {
  transform: translateY(-1px);
}

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

.tile.is-active {
  background: var(--tile-active);
  color: var(--accent);
}

.tile.is-used {
  opacity: 0.55;
  cursor: default;
}

.tile.is-found {
  background: color-mix(in srgb, var(--tile-color, var(--accent)) 24%, var(--tile));
  color: var(--tile-color, var(--accent));
}

.board.is-frozen .tile {
  cursor: default;
}

.board.is-frozen .tile:hover {
  transform: none;
}

.selection {
  min-height: 1.5rem;
  margin: 0.85rem 0 0.25rem;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.message {
  min-height: 1.25rem;
  margin: 0;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.95rem;
  font-weight: 600;
}

.message.is-error {
  color: var(--danger);
}

.message.is-success {
  color: var(--accent);
}

.found-section {
  margin-top: 1.25rem;
  animation: rise 0.7s ease 0.15s both;
}

.found-heading {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.found-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.found-list:empty::after {
  content: "No words yet — start tracing.";
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.found-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  background: color-mix(in srgb, var(--tile) 70%, transparent);
  border-left: 4px solid var(--item-color, var(--line));
  font-weight: 600;
}

.found-item .word {
  font-family: var(--font-display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--item-color, var(--ink));
}

.found-item .pts {
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-top: 1.1rem;
  animation: rise 0.7s ease 0.2s both;
}

.controls .btn[hidden] {
  display: none;
}

#btn-play,
body.is-reviewing #btn-lock {
  grid-column: 1 / -1;
}

.top-section {
  margin-top: 1.35rem;
}

.top-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.top-list:empty::after {
  content: "No saved tries yet.";
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.top-item {
  appearance: none;
  width: 100%;
  display: grid;
  grid-template-columns: 1.5rem 3.5rem 1fr;
  gap: 0.5rem;
  align-items: center;
  text-align: left;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--tile) 70%, transparent);
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.top-item.is-selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--tile));
}

.top-rank,
.top-score {
  font-variant-numeric: tabular-nums;
}

.top-score {
  font-family: var(--font-display);
  font-size: 1.15rem;
}

.top-detail {
  color: var(--ink-soft);
  font-size: 0.85rem;
  text-align: right;
}

.end-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.7rem 0.9rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  background: transparent;
  color: var(--ink);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--accent) 88%, black);
}

.btn-ghost:hover:not(:disabled) {
  background: color-mix(in srgb, var(--tile) 70%, white);
}

.end-panel {
  margin-top: 1.4rem;
  padding: 1.2rem 1rem 1.3rem;
  border-radius: calc(var(--radius) + 4px);
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--tile) 92%, white);
  text-align: center;
  box-shadow: var(--shadow);
  animation: rise 0.45s ease both;
}

.end-panel[hidden] {
  display: none;
}

.end-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.8rem;
}

.end-score {
  margin: 0.35rem 0 0.9rem;
  color: var(--ink-soft);
  font-weight: 600;
}

.end-score span {
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
}

.share-preview {
  margin: 0 auto 0.9rem;
  padding: 0.85rem 1rem;
  width: fit-content;
  max-width: 100%;
  text-align: left;
  background: var(--paper);
  border-radius: 8px;
  border: 1px dashed var(--line);
  font-family: ui-monospace, "Cascadia Code", "SF Mono", Menlo, monospace;
  font-size: 0.95rem;
  line-height: 1.55;
  white-space: pre-wrap;
}

.share-status {
  min-height: 1.2rem;
  margin: 0.55rem 0 0;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.92rem;
}

.how-to {
  margin-top: 1.75rem;
  color: var(--ink-soft);
  animation: rise 0.7s ease 0.25s both;
}

.how-to h2 {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.how-to p {
  margin: 0;
  font-size: 0.95rem;
}

.site-footer {
  padding: 0 0 2rem;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.site-footer p {
  margin: 0;
}

body.is-locked .controls {
  display: none;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 380px) {
  .top-item {
    grid-template-columns: 1.25rem 3rem 1fr;
  }
}
