@font-face {
  font-family: "DM Sans";
  src: url("./assets/dm-sans.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: Newsreader;
  src: url("./assets/newsreader.woff2") format("woff2");
  font-weight: 500 700;
  font-display: swap;
}

:root {
  color-scheme: light;
  --paper: #f7f4e8;
  --sheet: #fffcf2;
  --ink: #252b19;
  --muted: #53543d;
  --olive: #313b20;
  --moss: #43552e;
  --sprout: #e8edda;
  --gold: #efc44a;
  --gold-pale: #fae8a1;
  --rule: #c9c0a0;
  --error: #8a3627;
  --error-paper: #fae9df;
  --focus: #6d4a06;
  --radius: 16px;
  --ease: cubic-bezier(.2, .75, .2, 1);
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-synthesis: none;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; display: flex; flex-direction: column; }
body > main { flex: 1; }
h1, h2, p, figure { margin: 0; }
a { color: inherit; }
button, input { font: inherit; }
a[href], button, label[for] { cursor: pointer; }
button:disabled { cursor: not-allowed; }
button, a, input { -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
::selection { color: var(--ink); background: var(--gold-pale); }
[hidden] { display: none !important; }

.layout { width: min(100% - 40px, 1224px); margin-inline: auto; }
.site-footer { padding: 16px 20px 22px; color: var(--muted); font-size: .78rem; text-align: center; }
body:has(.home) .site-footer { display: none; }

.home {
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--gold);
}

.home-image {
  position: absolute;
  inset: 0;
  z-index: -2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 43%;
}

.home::after {
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(0deg, #272917bf, transparent 25%),
    radial-gradient(ellipse at 50% 40%, #f3cf691a 30%, #3f35117a 100%);
  content: "";
}

.home-top {
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: max(20px, env(safe-area-inset-top));
}

.leaf-button, .home-info {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid #29301952;
  border-radius: 50%;
  color: var(--ink);
  background: #f1d77c;
}

.home-info { font-size: 1.2rem; font-weight: 700; }
.leaf-button:hover, .home-info:hover { background: #fff0af; }
.leaf-button:active, .home-info:active { transform: translateY(1px); }
.leaf-button[data-showering] { background: #f8e5a0; }

.home-inner {
  z-index: 2;
  display: grid;
  align-content: center;
  width: min(100% - 40px, 744px);
  padding-block: clamp(26px, 5vh, 48px);
}

.home-brand { text-align: center; }

.home-brand h1 {
  font-family: Newsreader, Georgia, serif;
  font-size: clamp(4.2rem, 11vw, 7.95rem);
  font-weight: 600;
  line-height: .89;
  letter-spacing: -.04em;
}

.home-brand > p:not(.eco-tip) {
  margin-top: 7px;
  font-size: clamp(1rem, 1.65vw, 1.16rem);
  font-weight: 700;
  line-height: 1.4;
}

.eco-tip {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 8px;
  max-width: min(100%, 34rem);
  margin-top: 14px;
  padding: 7px 14px;
  border: 1px solid #55552a45;
  border-radius: 25px;
  background: #f8e5a0;
  color: var(--ink);
  font-size: .85rem;
  line-height: 1.35;
}

.eco-tip > :first-child { font-weight: 700; }

.game-menu {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(10px, 2.1vw, 20px);
  margin-top: clamp(21px, 4vw, 32px);
}

.game-choice {
  display: grid;
  min-height: 270px;
  grid-template-rows: auto auto 1fr auto auto;
  gap: 6px;
  padding: 15px clamp(14px, 2.4vw, 23px) 18px;
  border-radius: var(--radius);
  background: #f7f5eb;
  box-shadow: 0 9px 26px #42371133;
}
.game-choice h2 { font-size: clamp(1.05rem, 2.4vw, 1.55rem); line-height: 1.15; }
.game-choice p { color: var(--muted); font-size: .92rem; line-height: 1.4; }
.game-art { display: grid; place-items: center; }
.game-art svg { display: block; width: min(100%, 138px); height: auto; }

.choice-progress { display: grid; gap: 4px; margin-block: 6px; }
.choice-progress span { color: var(--muted); font-size: .81rem; font-weight: 700; }
.choice-progress progress {
  display: block;
  width: 100%;
  height: 5px;
  appearance: none;
  border: 0;
  border-radius: 5px;
  overflow: hidden;
  background: #dcd8c3;
  color: var(--moss);
}
.choice-progress progress::-webkit-progress-bar { background: #dcd8c3; }
.choice-progress progress::-webkit-progress-value { background: var(--moss); border-radius: 5px; }
.choice-progress progress::-moz-progress-bar { background: var(--moss); border-radius: 5px; }
.button.choice-play { justify-content: space-between; gap: 5px; text-decoration: none; }
.choice-play:hover { background: #465530; }
.choice-play:active { transform: translateY(1px); }

.leaf-shower {
  position: absolute;
  inset: 0;
  z-index: 1;
  overflow: hidden;
  pointer-events: none;
}
.falling-leaf {
  position: absolute;
  top: -23px;
  left: var(--leaf-x);
  width: var(--leaf-size);
  aspect-ratio: 1.55;
  border: 1px solid #493b245e;
  border-radius: 78% 12% 78% 12%;
  background: var(--leaf-color);
  animation: leaf-fall var(--leaf-time) linear var(--leaf-delay) both;
}
.falling-leaf::after {
  position: absolute;
  top: 50%;
  left: 12%;
  width: 78%;
  height: 1px;
  transform: rotate(-22deg);
  background: #493b2466;
  content: "";
}

@keyframes leaf-fall {
  0% { transform: translate3d(0, 0, 0) rotate(-30deg); opacity: 0; }
  6% { opacity: 1; }
  50% { transform: translate3d(calc(var(--leaf-drift) * .2), calc(var(--fall-distance) * .5), 0) rotate(calc(var(--leaf-turn) * .35)); }
  85% { opacity: .9; }
  100% { transform: translate3d(var(--leaf-drift), var(--fall-distance), 0) rotate(var(--leaf-turn)); opacity: 0; }
}

.about-dialog {
  width: min(100% - 32px, 430px);
  max-height: calc(100dvh - 32px);
  padding: 24px;
  border: 0;
  border-radius: var(--radius);
  background: var(--sheet);
  color: var(--ink);
  box-shadow: 0 16px 55px #2326144d;
}
.about-dialog::backdrop { background: #2326149e; }
.about-dialog h2 { font: 600 2rem/1.05 Newsreader, Georgia, serif; }
.about-dialog p { margin-top: 10px; color: var(--muted); line-height: 1.5; }
.about-dialog form { margin-top: 17px; }

.arrow {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
}
.arrow-right { transform: rotate(45deg); }
.arrow-left { transform: rotate(-135deg); }

.game-page { max-width: 1020px; padding-bottom: 22px; }
.game-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 64px; }
.back { display: inline-flex; min-height: 44px; align-items: center; gap: 9px; color: var(--ink); font-weight: 700; text-decoration: none; }
.back:hover { text-decoration: underline; text-underline-offset: 4px; }
.game-progress { color: var(--muted); font-size: .88rem; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }

.game-banner {
  display: flex;
  align-items: flex-end;
  min-height: 140px;
  padding: 18px clamp(16px, 4vw, 40px);
  border-radius: var(--radius);
  background: linear-gradient(90deg, #fad45b 9%, #fad45b05 96%), url("./assets/leaf.webp") center 48% / cover, var(--gold);
}
.game-banner h1 { max-width: 100%; font: 600 clamp(2.45rem, 6vw, 4.6rem)/1 Newsreader, Georgia, serif; letter-spacing: -.035em; }
.game-banner h1:focus { outline: none; }
.game-content { padding-top: clamp(14px, 2.7vw, 28px); }
.game-intro { max-width: 63ch; color: var(--muted); line-height: 1.52; }

.match-board {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  column-gap: clamp(28px, 12vw, 140px);
  row-gap: 9px;
  margin-top: 22px;
}
.board-label { color: var(--muted); font-size: .88rem; font-weight: 700; }
.tile {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 62px;
  width: 100%;
  padding: 12px 16px;
  text-align: left;
  line-height: 1.32;
  overflow-wrap: anywhere;
  border: 1px solid var(--rule);
  border-radius: 12px;
  color: var(--ink);
  background: var(--sheet);
  user-select: none;
}
.tile[data-side="clue"] { padding-right: 20px; }
.tile[data-side="term"] { padding-left: 20px; font-weight: 700; }
.tile:not(:disabled) { touch-action: none; cursor: grab; }
.tile:not(:disabled):active { cursor: grabbing; }
.tile:hover:enabled { border-color: var(--focus); }
.tile[aria-pressed="true"], .tile[data-hover] { border-color: var(--focus); background: var(--gold-pale); }
.tile[data-solved] { border-color: #95a37b; background: var(--sprout); }
.tile[data-wrong] { border-color: var(--error); background: var(--error-paper); }
.port {
  position: absolute;
  z-index: 2;
  top: calc(50% - 6px);
  width: 12px;
  height: 12px;
  border: 2px solid var(--moss);
  border-radius: 50%;
  pointer-events: none;
  background: var(--sheet);
}
.tile[data-side="clue"] .port { right: -6px; }
.tile[data-side="term"] .port { left: -6px; }
.tile[aria-pressed="true"] .port, .tile[data-hover] .port { background: var(--gold); }
.tile[data-solved] .port { background: var(--moss); }
.connections { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.connections path { fill: none; stroke: var(--moss); stroke-width: 3; stroke-linecap: round; }
.connections .preview { stroke: var(--focus); stroke-dasharray: 4 5; }
.connections .fresh { animation: draw-line 260ms var(--ease) both; }
@keyframes draw-line { from { stroke-dasharray: 1; stroke-dashoffset: 1; } to { stroke-dasharray: 1; stroke-dashoffset: 0; } }

.match-footer { display: flex; align-items: center; flex-wrap: wrap; gap: 10px 16px; margin-top: 12px; }
.match-footer .status { flex: 1 1 180px; }
.status { min-height: 1.5em; color: var(--moss); font-size: .9rem; font-weight: 700; line-height: 1.45; }
.status[data-tone="wrong"] { color: var(--error); }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 9px 17px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--sheet);
  background: var(--olive);
  font-weight: 700;
  line-height: 1.25;
}
.button:enabled:hover { background: #465530; }
.button:enabled:active { transform: translateY(1px); }
.button:disabled { color: var(--muted); background: #e8e4d3; }
.button.secondary { color: var(--ink); border-color: var(--rule); background: var(--sheet); }
.button.secondary:enabled:hover { background: var(--gold-pale); }

.crossword-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.18fr) minmax(0, 1fr);
  gap: clamp(24px, 5vw, 58px);
  align-items: start;
}
.crossword-board { min-width: 0; }
.crossword-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 4px 12px;
  flex-wrap: wrap;
}
.crossword-toolbar .game-intro { font-size: .91rem; }
.jump-clues {
  min-height: 44px;
  padding: 0 2px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 700;
  font-size: .88rem;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.jump-clues:hover { color: var(--focus); }
.board-clue {
  min-height: 92px;
  margin: 5px 0 10px;
  padding: 11px 14px;
  border-radius: 11px;
  background: var(--sheet);
}
.clue-label { color: var(--moss); font-size: .81rem; font-weight: 700; }
.active-clue { margin-top: 3px; font-size: clamp(.94rem, 1.65vw, 1.09rem); line-height: 1.43; }
.crossword-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-top: 11px; }
.crossword-actions .status { flex: 1 1 140px; }

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 2px;
  padding: 5px;
  border: 1px solid var(--rule);
  border-radius: 11px;
  background: #eee8d3;
}
.cell {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--sheet);
}
.cell input {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  border-radius: inherit;
  background: transparent;
  color: var(--ink);
  font-size: clamp(1rem, 1.7vw, 1.28rem);
  font-weight: 700;
  line-height: 1;
  text-align: center;
  caret-color: var(--focus);
}
.cell[data-active] { background: var(--gold-pale); }
.cell[data-feedback="correct"]:not([data-active]) { background: var(--sprout); }
.cell[data-feedback="wrong"] { background: var(--error-paper); }
.cell[data-feedback="wrong"] input { color: var(--error); text-decoration: underline; text-underline-offset: 2px; }
.cell[data-selected] { box-shadow: inset 0 0 0 2px var(--focus); }
.cell:focus-within { z-index: 1; }
.cell input:focus-visible { outline-offset: 0; outline-width: 2px; }
.cell-number {
  position: absolute;
  top: 1px;
  left: 2px;
  color: var(--muted);
  line-height: 1;
  font-size: clamp(.45rem, .87vw, .69rem);
  font-weight: 700;
  pointer-events: none;
}

.clue-list h2 {
  margin-bottom: 16px;
  font: 600 clamp(1.85rem, 3.7vw, 2.65rem)/1 Newsreader, Georgia, serif;
  letter-spacing: -.025em;
  scroll-margin-top: 16px;
}
.clue-groups { display: grid; gap: 18px; }
.clue-groups h3 { margin: 0 0 4px; font-size: .94rem; }
.clue-groups ol { margin: 0; padding: 0; list-style: none; }
.clue-groups li + li { border-top: 1px solid var(--rule); }
.clue-item {
  display: grid;
  width: 100%;
  min-height: 44px;
  grid-template-columns: 1.35em minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 8px;
  padding: 8px 9px;
  border: 0;
  border-radius: 5px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  font-size: .93rem;
  line-height: 1.38;
}
.clue-item:hover { background: var(--sheet); }
.clue-item[aria-pressed="true"] { background: var(--gold-pale); }
.clue-number, .clue-state { color: var(--moss); font-size: .8rem; font-weight: 700; }

.finish {
  display: grid;
  justify-items: start;
  gap: 10px;
  padding: clamp(22px, 5vw, 54px);
  border-radius: var(--radius);
  background: var(--sprout);
}
.finish-score { color: var(--moss); font-weight: 700; }
.finish h2 { font: 600 clamp(2rem, 5vw, 3.8rem)/1 Newsreader, Georgia, serif; letter-spacing: -.025em; }
.finish-detail { max-width: 55ch; color: var(--muted); line-height: 1.45; }
.finish .button { margin-top: 8px; }

@media (max-width: 720px) {
  .layout { width: min(100% - 28px, 520px); }
  .home-top { padding-top: max(12px, env(safe-area-inset-top)); }
  .home-inner { width: min(100% - 28px, 520px); }
  .home-image { object-position: 49% 50%; }
  .home-brand h1 { font-size: clamp(3.9rem, 15vw, 6rem); }
  .game-choice { min-height: 240px; padding: 12px 11px; }
  .game-art svg { width: min(100%, 112px); }
  .game-choice p { font-size: .81rem; }
  .choice-progress span { font-size: .74rem; }
  .choice-play { padding-inline: 10px; font-size: .9rem; }
  .game-top { min-height: 52px; }
  .game-banner { min-height: 87px; padding: 12px 14px; }
  .match-board { margin-top: 15px; column-gap: clamp(20px, 7vw, 36px); }
  .tile { min-height: 64px; padding-block: 10px; font-size: .87rem; }
  .tile[data-side="clue"] { padding-inline: 9px 12px; }
  .tile[data-side="term"] { padding-inline: 12px 8px; }
  .crossword-layout { grid-template-columns: minmax(0, 1fr); gap: 26px; }
  .puzzle-grid { gap: 1px; }
  .cell[data-filled] .cell-number { display: none; }
  .crossword-actions .status:empty { display: none; }
}

@media (max-width: 720px) and (max-height: 660px) {
  .home-inner { padding-block: 10px; }
  .eco-tip { margin-top: 10px; }
  .game-menu { margin-top: 13px; }
  .game-choice { gap: 5px; }
  .game-art svg { width: min(100%, 94px); }
}

@media (max-width: 350px) {
  .game-choice h2 { min-height: 2.3em; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .falling-leaf {
    top: var(--leaf-y);
    transform: rotate(calc(var(--leaf-turn) * .25));
    animation: none;
  }
}
