@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=DM+Serif+Display:ital@0;1&display=swap");

:root {
  color-scheme: light;
  --ink: #173127;
  --ink-soft: #627168;
  --paper: #f3efe2;
  --card: rgba(255, 253, 246, 0.9);
  --line: #d8d5c8;
  --leaf: #3d7358;
  --leaf-dark: #245340;
  --leaf-pale: #dbe6ce;
  --sun: #eea968;
  --danger: #a64a32;
  --shadow: 0 28px 80px rgba(49, 62, 49, 0.11);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "DM Sans", system-ui, sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--sun); outline-offset: 3px; }

.site-header {
  width: min(720px, calc(100% - 40px));
  height: 72px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  gap: 11px;
  align-items: center;
  color: var(--ink);
  font-family: "DM Serif Display", serif;
  font-size: 21px;
  text-decoration: none;
}
.brand-mark { position: relative; display: inline-block; width: 23px; height: 28px; }
.brand-mark::after { content: ""; position: absolute; width: 2px; height: 20px; background: var(--leaf); left: 11px; bottom: 0; transform: rotate(-5deg); }
.brand-mark span { position: absolute; width: 12px; height: 8px; background: var(--leaf); border-radius: 12px 2px 12px 2px; }
.brand-mark span:first-child { left: 1px; top: 7px; transform: rotate(22deg); }
.brand-mark span:last-child { right: 0; top: 2px; transform: scaleX(-1) rotate(19deg); }

.icon-button {
  width: 40px;
  height: 40px;
  border: 1px solid #c9c8ba;
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.45);
  font-weight: 700;
  cursor: pointer;
}

.page-shell { width: min(720px, calc(100% - 40px)); margin: 0 auto; padding: 24px 0 80px; }
.eyebrow { margin: 0 0 14px; color: var(--leaf); font-size: 11px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; }
.game-slogan {
  margin: 10px auto 24px;
  text-align: center;
  font: 400 clamp(26px, 5vw, 34px)/1.2 "DM Serif Display", serif;
  letter-spacing: -0.02em;
}
.game-slogan em { color: var(--leaf); font-weight: 400; }

.game-card {
  width: min(640px, 100%);
  margin: 0 auto;
  padding: 28px 30px 30px;
  border: 1px solid rgba(100, 110, 96, 0.22);
  border-radius: 28px;
  background: var(--card);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}
.game-topbar, .trace-label-row { display: flex; align-items: center; justify-content: space-between; }
.puzzle-count { margin: 0 0 7px; color: var(--ink-soft); font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.puzzle-status { padding: 6px 10px; border-radius: 999px; color: var(--leaf-dark); background: var(--leaf-pale); font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.progress-dots { display: flex; gap: 7px; }
.progress-dot { width: 22px; height: 4px; border: 0; border-radius: 5px; background: #d8dacd; cursor: pointer; padding: 0; }
.progress-dot.complete { background: #94ae86; }
.progress-dot.active { background: var(--leaf-dark); }
.puzzle-heading { text-align: center; margin: 30px 0 23px; }
.puzzle-heading h2 { margin: 0; font: 400 clamp(24px, 5vw, 32px)/1.2 "DM Serif Display", serif; }
.beat-label { margin: 20px 0 9px; color: #879087; font-size: 9px; font-weight: 700; letter-spacing: 0.17em; text-transform: uppercase; }
.word-beats { display: flex; justify-content: center; flex-wrap: wrap; gap: 6px; }
.word-beats span { min-width: 29px; padding: 5px 8px; border: 1px solid #ccd2c7; border-radius: 999px; color: var(--leaf-dark); background: #f5f6ee; font-size: 11px; font-weight: 700; }

.board-wrap { position: relative; width: min(100%, 470px); margin: 0 auto; }
.board {
  --grid-size: 4;
  position: relative;
  isolation: isolate;
  display: grid;
  grid-template-columns: repeat(var(--grid-size), 1fr);
  gap: clamp(7px, 1.9vw, 11px);
  width: 100%;
  padding: clamp(12px, 3vw, 20px);
  border: 1px solid #ccd1c7;
  border-radius: 22px;
  background: #e7e9de;
  touch-action: none;
  user-select: none;
}
.path-layer { position: absolute; z-index: 1; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
.path-layer polyline { fill: none; stroke: var(--leaf); stroke-width: 9; stroke-linecap: round; stroke-linejoin: round; opacity: 0.72; }
.tile {
  position: relative;
  z-index: 2;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid #cfd2c8;
  border-radius: clamp(10px, 3vw, 18px);
  color: var(--ink);
  background: #fbfaf3;
  box-shadow: 0 2px 0 rgba(36, 72, 55, 0.08);
  font: 600 clamp(17px, calc(50px / var(--grid-size) * 2), 30px)/1 "DM Serif Display", serif;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease, color 150ms ease, border-color 150ms ease;
}
.tile:hover { transform: translateY(-2px); border-color: #a9b5a7; }
.tile.selected { color: #fff; background: var(--leaf); border-color: var(--leaf-dark); transform: scale(0.94); }
.tile.last { background: var(--leaf-dark); box-shadow: 0 0 0 4px rgba(61, 115, 88, 0.17); }
.tile.hinted:not(.selected)::after { content: ""; position: absolute; inset: 5px; border: 2px dashed #83a075; border-radius: inherit; animation: breathe 1.8s ease-in-out infinite; }
.tile.eliminated {
  border-style: dashed;
  border-color: #c8cbc1;
  color: transparent;
  background: transparent;
  box-shadow: none;
  cursor: default;
  opacity: 0.55;
  transform: none;
}
.tile-order { position: absolute; top: 5px; left: 7px; font: 700 8px/1 "DM Sans", sans-serif; font-style: normal; opacity: 0.8; }
.shake { animation: shake 360ms ease; }
.board.celebrating .path-layer polyline { animation: path-glow 720ms ease-out both; }
.board.celebrating .tile.selected {
  animation: tile-bloom 360ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  animation-delay: calc(var(--path-order) * 18ms);
}
.completion-bloom {
  position: absolute;
  z-index: 4;
  top: 3px;
  left: 50%;
  width: 34px;
  height: 34px;
  pointer-events: none;
  transform: translate(-50%, -70%) scale(0);
  animation: flower-grow 540ms cubic-bezier(0.2, 1.4, 0.4, 1) 380ms both;
}
.completion-bloom::before {
  content: "";
  position: absolute;
  left: 12px;
  top: 12px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff8df;
  box-shadow:
    0 -10px 0 -1px #f8f4df,
    10px -3px 0 -1px #f8f4df,
    6px 8px 0 -1px #f8f4df,
    -6px 8px 0 -1px #f8f4df,
    -10px -3px 0 -1px #f8f4df;
}
.completion-bloom::after {
  content: "";
  position: absolute;
  left: 15px;
  top: 15px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--sun);
  box-shadow: 0 15px 0 -1px #7f9d75;
}

.trace-panel { margin: 19px auto 0; width: min(100%, 470px); }
.trace-label-row { color: #7c877f; font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.trace-value { min-height: 31px; margin: 9px 0 0; overflow-wrap: anywhere; font: 400 clamp(20px, 5vw, 28px)/1.35 "DM Serif Display", serif; letter-spacing: 0.04em; }
.trace-value.empty { color: #9aa39c; font-style: italic; letter-spacing: 0; }
.feedback { min-height: 20px; margin: 5px 0 0; color: var(--ink-soft); font-size: 12px; }
.feedback[data-tone="warning"] { color: var(--danger); }
.feedback[data-tone="hint"] { color: var(--leaf); font-weight: 600; }

.game-actions { width: min(100%, 470px); margin: 20px auto 0; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.primary-button, .secondary-button, .hint-button, .text-button { border-radius: 999px; cursor: pointer; font-weight: 700; }
.primary-button, .secondary-button, .hint-button { min-height: 48px; padding: 0 20px; }
.primary-button { border: 1px solid var(--leaf-dark); color: #fff; background: var(--leaf-dark); box-shadow: 0 6px 16px rgba(36, 83, 64, 0.2); }
.primary-button:hover { background: #193f31; }
.secondary-button { border: 1px solid #c7cdc3; color: var(--ink); background: #f9f8f0; }
.primary-button:disabled, .secondary-button:disabled, .hint-button:disabled { opacity: 0.42; cursor: not-allowed; }
.hint-button { border: 1px solid #c7cdc3; color: var(--leaf); background: #f9f8f0; }
.hint-button:hover { border-color: #9eac9f; background: #f0f2e8; }
dialog { color: var(--ink); }
dialog::backdrop { background: rgba(19, 39, 31, 0.56); backdrop-filter: blur(6px); }
.result-dialog, .help-dialog { width: min(480px, calc(100% - 32px)); border: 1px solid #d1d3c8; border-radius: 26px; background: #fcfaf1; box-shadow: 0 34px 90px rgba(20, 38, 30, 0.3); }
.result-dialog { padding: 35px; text-align: center; }
.result-dialog h2 { margin: 0 0 22px; font: 400 34px/1.15 "DM Serif Display", serif; }
.result-art { position: relative; width: 70px; height: 58px; margin: 0 auto 10px; }
.result-art .stem { position: absolute; width: 3px; height: 45px; left: 34px; bottom: 0; background: var(--leaf); transform: rotate(-5deg); }
.result-art .leaf { position: absolute; width: 29px; height: 17px; background: var(--leaf); }
.result-art .left { left: 7px; top: 20px; border-radius: 25px 2px; transform: rotate(22deg); }
.result-art .right { right: 5px; top: 5px; border-radius: 2px 25px; transform: rotate(-18deg); }
.reading-card { padding: 19px; border-radius: 16px; text-align: left; background: #e8eddf; }
.reading-card span, .example-reading span { display: block; margin-bottom: 7px; color: var(--leaf); font-size: 9px; font-weight: 700; letter-spacing: 0.16em; text-transform: uppercase; }
.reading-card p { margin: 0; color: #42564a; font-size: 13px; line-height: 1.6; }
.result-dialog .primary-button { width: 100%; margin-top: 20px; }
.text-button { margin-top: 10px; border: 0; color: var(--leaf); background: transparent; }

.help-dialog { max-height: calc(100dvh - 32px); padding: 37px; overflow-y: auto; }
.help-dialog h2 { margin: 0 0 18px; font: 400 31px/1.12 "DM Serif Display", serif; }
.help-intro { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.65; }
.dialog-close { position: absolute; right: 18px; top: 16px; width: 34px; height: 34px; border: 0; border-radius: 50%; color: var(--ink); background: #ecece3; font-size: 23px; cursor: pointer; }
.trace-instructions { margin: 25px 0 0; }
.trace-instructions h3 { margin: 0 0 10px; color: var(--leaf); font-size: 10px; letter-spacing: 0.16em; text-transform: uppercase; }
.trace-instructions ul { margin: 0; padding: 0; list-style: none; border-top: 1px solid #d9dbd1; }
.trace-instructions li { position: relative; padding: 10px 0 10px 17px; border-bottom: 1px solid #d9dbd1; color: #42564a; font-size: 13px; line-height: 1.5; }
.trace-instructions li::before { content: ""; position: absolute; left: 1px; top: 18px; width: 5px; height: 5px; border-radius: 50%; background: var(--leaf); }
.example-reading { margin: 25px 0; padding: 18px; border-left: 3px solid var(--leaf); background: #e8eddf; }
.example-reading strong { display: block; font: 400 22px/1.2 "DM Serif Display", serif; }
.example-reading p { margin: 8px 0 0; color: var(--ink-soft); font-size: 12px; }
.help-dialog .primary-button { width: 100%; }

@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-7px); } 75% { transform: translateX(7px); } }
@keyframes breathe { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
@keyframes path-glow { 0% { stroke: var(--leaf); filter: none; } 45% { stroke: #7ba56f; filter: drop-shadow(0 0 7px rgba(123, 165, 111, 0.8)); } 100% { stroke: var(--leaf); filter: none; } }
@keyframes tile-bloom { 0%, 100% { transform: scale(0.94); } 55% { transform: scale(1.02); background: #568567; } }
@keyframes flower-grow { 0% { opacity: 0; transform: translate(-50%, 5%) scale(0) rotate(-12deg); } 70% { opacity: 1; transform: translate(-50%, -75%) scale(1.12) rotate(3deg); } 100% { opacity: 1; transform: translate(-50%, -70%) scale(1) rotate(0); } }

@media (max-width: 720px) {
  .page-shell { width: min(100% - 24px, 600px); padding-top: 18px; }
  .game-card { padding: 22px 16px 24px; border-radius: 22px; }
  .puzzle-heading { margin-top: 24px; }
}

@media (max-width: 390px) {
  .page-shell { width: calc(100% - 16px); }
  .game-card { padding-inline: 11px; }
  .board { gap: 6px; padding: 10px; }
  .game-actions { grid-template-columns: 1fr 1fr; }
  .primary-button, .secondary-button { padding-inline: 12px; font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
