:root {
  --paper: #f1ede2;
  --paper-bright: #fbf8f0;
  --ink: #172321;
  --ink-soft: #263733;
  --muted: #66736d;
  --rule: rgba(23, 35, 33, 0.15);
  --accent: #f0643c;
  --accent-dark: #bd3f23;
  --teal: #08716b;
  --teal-bright: #30b6a3;
  --gold: #e1af43;
  --danger: #cf3f39;
  --card: rgba(255, 253, 247, 0.8);
  --shadow: 0 24px 70px rgba(44, 38, 28, 0.11);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  color: var(--ink);
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 92% -6%, rgba(240, 100, 60, 0.13), transparent 34rem),
    radial-gradient(circle at -5% 48%, rgba(8, 113, 107, 0.07), transparent 30rem),
    linear-gradient(rgba(23, 35, 33, 0.025) 1px, transparent 1px),
    var(--paper);
  background-size: auto, auto, 100% 28px, auto;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }

.page-shell {
  width: min(1160px, calc(100% - 40px));
  margin: 0 auto;
  padding: 56px 0 72px;
}

.site-nav {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 670px);
  margin: 0 auto 42px;
  padding: 6px;
  border: 1px solid var(--rule);
  border-radius: 15px;
  background: rgba(255,253,247,0.7);
  box-shadow: 0 10px 32px rgba(44,38,28,0.06);
}

.site-nav a {
  padding: 13px 18px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
  text-align: center;
  text-decoration: none;
  transition: color 150ms ease, background 150ms ease, transform 150ms ease;
}

.site-nav a:hover { color: var(--teal); background: rgba(8,113,107,0.055); transform: translateY(-1px); }
.site-nav a[aria-current="page"] { color: var(--paper-bright); background: var(--ink); box-shadow: 0 5px 15px rgba(23,35,33,0.17); }

.manual-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  align-items: end;
  gap: 50px;
  margin-bottom: 30px;
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--accent-dark);
  font: 700 0.68rem/1.2 var(--mono);
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.eyebrow { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.eyebrow::before { width: 34px; height: 2px; background: var(--accent); content: ""; }

h1, h2, p { margin-top: 0; }
h1 {
  max-width: 720px;
  margin-bottom: 0;
  font: 400 clamp(2.9rem, 6.8vw, 5.8rem)/0.92 Georgia, "Times New Roman", serif;
  letter-spacing: -0.055em;
}
h1 em { color: var(--teal); font-weight: 400; }
.intro { max-width: 700px; margin: 22px 0 0; color: var(--muted); font-size: 1rem; line-height: 1.65; }

.size-control {
  padding: 19px;
  border: 1px solid var(--rule);
  border-radius: 16px;
  background: rgba(255,253,247,0.72);
  box-shadow: 0 12px 38px rgba(44,38,28,0.07);
}
.size-control > label { color: var(--muted); font: 750 0.64rem/1.2 var(--mono); letter-spacing: 0.11em; text-transform: uppercase; }
.size-control > div { display: grid; grid-template-columns: auto 72px 1fr; align-items: center; gap: 9px; margin-top: 10px; }
.size-control span { color: var(--teal); font: 750 0.82rem var(--mono); }
.size-control input {
  width: 100%;
  min-width: 0;
  padding: 10px 8px;
  border: 1px solid var(--rule);
  border-radius: 9px;
  outline: none;
  color: var(--ink);
  background: var(--paper-bright);
  font: 750 0.9rem var(--mono);
  text-align: center;
}
.size-control input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(8,113,107,0.1); }
.size-control button {
  min-height: 40px;
  padding: 8px 11px;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  color: white;
  background: var(--teal);
  font-size: 0.72rem;
  font-weight: 760;
}
.size-control button:hover { filter: brightness(1.06); }
.size-control small { display: block; margin-top: 10px; color: var(--muted); font-size: 0.65rem; }

.score-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--rule);
  border-radius: 17px;
  background: rgba(255,253,247,0.7);
  box-shadow: 0 13px 40px rgba(44,38,28,0.065);
}
.score-strip article { min-width: 0; padding: 17px 20px; }
.score-strip article + article { border-left: 1px solid var(--rule); }
.score-strip span { display: block; color: var(--muted); font: 750 0.58rem/1.2 var(--mono); letter-spacing: 0.1em; text-transform: uppercase; }
.score-strip strong { display: block; margin-top: 7px; overflow: hidden; color: var(--ink); font: 400 clamp(1.45rem, 3vw, 2.25rem)/1 Georgia, "Times New Roman", serif; letter-spacing: -0.035em; text-overflow: ellipsis; white-space: nowrap; }
.score-strip article:nth-child(2) strong { color: var(--accent-dark); }
.score-strip article:nth-child(4) strong { color: var(--teal); }
.score-strip small { display: block; margin-top: 5px; color: var(--muted); font-size: 0.61rem; line-height: 1.35; }

.puzzle-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(285px, 0.68fr); gap: 12px; align-items: start; }
.board-card,
.coach-card { border: 1px solid var(--rule); border-radius: 20px; background: var(--card); box-shadow: var(--shadow); }
.board-card { padding: 24px; }
.coach-card { position: sticky; top: 18px; padding: 25px; }
.board-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.board-heading h2,
.coach-card h2 { margin: 5px 0 0; font: 400 1.55rem/1.1 Georgia, "Times New Roman", serif; letter-spacing: -0.025em; }
.board-state { flex: 0 0 auto; padding: 6px 9px; border-radius: 999px; color: var(--teal); background: rgba(8,113,107,0.08); font: 750 0.61rem/1 var(--mono); text-transform: uppercase; }
.board-state.bad { color: var(--danger); background: rgba(207,63,57,0.09); }
.board-state.solved { color: #71500b; background: rgba(225,175,67,0.17); }

.board-stage {
  position: relative;
  width: min(100%, 700px);
  aspect-ratio: 1;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  background: #111d1b;
  box-shadow: inset 0 0 60px rgba(0,0,0,0.3), 0 18px 35px rgba(24,32,29,0.13);
}
.board-stage::after {
  position: absolute;
  z-index: 1;
  inset: 0;
  opacity: 0.22;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, rgba(48,182,163,0.12), transparent 68%);
  content: "";
}
#manual-board { position: relative; z-index: 2; display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: manipulation; }
#manual-board:focus-visible { outline: 3px solid var(--gold); outline-offset: -5px; }
.board-card.line-warning .board-stage { animation: lineWarning 420ms ease; }

.board-message {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  margin-top: 12px;
  padding: 13px 15px;
  border-radius: 12px;
  color: var(--teal);
  background: rgba(8,113,107,0.07);
}
.board-message.warning { color: var(--danger); background: rgba(207,63,57,0.085); }
.board-message.success { color: #75520b; background: rgba(225,175,67,0.14); }
.message-mark { display: grid; place-items: center; width: 30px; height: 30px; border: 1px solid currentColor; border-radius: 50%; font-weight: 800; }
.board-message strong { display: block; font-size: 0.78rem; }
.board-message p { margin: 3px 0 0; color: var(--muted); font-size: 0.68rem; line-height: 1.4; }

.board-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 13px; }
.action-button { min-height: 40px; padding: 9px 14px; border: 1px solid var(--rule); border-radius: 10px; cursor: pointer; background: rgba(255,253,247,0.7); font-size: 0.71rem; font-weight: 750; }
.action-button:hover:not(:disabled) { color: var(--teal); border-color: rgba(8,113,107,0.33); }
.action-button.danger { color: var(--danger); }
.action-button:disabled { cursor: default; opacity: 0.42; }

.coach-intro { margin: 13px 0 23px; color: var(--muted); font-size: 0.74rem; line-height: 1.6; }
.placement-progress { padding: 16px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.placement-progress > div:first-child { display: flex; justify-content: space-between; gap: 15px; color: var(--muted); font: 720 0.65rem var(--mono); }
.placement-progress strong { color: var(--ink); }
.progress-track { height: 7px; margin-top: 11px; overflow: hidden; border-radius: 999px; background: rgba(23,35,33,0.09); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), var(--teal-bright)); transition: width 220ms ease; }

.goal-list { display: grid; gap: 0; margin: 18px 0; padding: 0; list-style: none; }
.goal-list li { display: grid; grid-template-columns: 20px 1fr; gap: 10px; padding: 11px 0; border-bottom: 1px solid rgba(23,35,33,0.08); }
.goal-list i { width: 13px; height: 13px; margin-top: 2px; border: 1px solid rgba(23,35,33,0.25); border-radius: 50%; }
.goal-list li.complete i { border-color: var(--teal); background: var(--teal); box-shadow: inset 0 0 0 3px var(--paper-bright); }
.goal-list li.failed i { border-color: var(--danger); background: var(--danger); box-shadow: 0 0 0 3px rgba(207,63,57,0.08); }
.goal-list strong { display: block; font-size: 0.73rem; }
.goal-list small { display: block; margin-top: 3px; color: var(--muted); font-size: 0.64rem; line-height: 1.4; }
.scoring-note { padding: 14px; border-left: 3px solid var(--gold); background: rgba(225,175,67,0.075); }
.scoring-note strong { font-size: 0.7rem; }
.scoring-note p { margin: 5px 0 0; color: var(--muted); font-size: 0.65rem; line-height: 1.5; }

.victory {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: 25px;
  overflow: hidden;
  pointer-events: none;
  color: #fff8df;
  text-align: center;
  background: radial-gradient(circle, rgba(8,113,107,0.94), rgba(8,38,35,0.82) 52%, rgba(8,20,19,0.18));
  animation: victoryIn 3.3s ease both;
}
.victory[hidden] { display: none; }
.victory > span { position: relative; color: #ffe39b; font: 760 0.68rem var(--mono); letter-spacing: 0.18em; text-transform: uppercase; }
.victory > strong { position: relative; margin-top: 10px; font: 400 clamp(2.7rem, 6vw, 5rem)/0.95 Georgia, "Times New Roman", serif; }
.victory > small { position: relative; margin-top: 12px; color: rgba(255,248,223,0.76); font-size: 0.72rem; }
.victory-sparks { position: absolute; inset: 0; }
.victory-sparks i { position: absolute; top: 50%; left: 50%; width: var(--size); height: var(--size); border-radius: 50%; opacity: 0; background: var(--color); animation: victorySpark 1.5s var(--delay) ease-out both; }

@keyframes lineWarning {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  55% { transform: translateX(5px); }
  78% { transform: translateX(-2px); }
}
@keyframes victoryIn {
  0% { opacity: 0; }
  12%, 78% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes victorySpark {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--angle)) translateX(0) scale(0.2); }
  14% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) rotate(var(--angle)) translateX(var(--distance)) scale(0.1); }
}

@media (max-width: 900px) {
  .page-shell { width: min(100% - 28px, 720px); padding-top: 38px; }
  .manual-header { grid-template-columns: 1fr; align-items: start; gap: 24px; }
  .size-control { width: 100%; }
  .score-strip { grid-template-columns: 1fr 1fr; }
  .score-strip article:nth-child(3) { border-top: 1px solid var(--rule); border-left: 0; }
  .score-strip article:nth-child(4) { border-top: 1px solid var(--rule); }
  .puzzle-layout { grid-template-columns: 1fr; }
  .coach-card { position: static; }
}

@media (max-width: 560px) {
  .page-shell { width: min(100% - 18px, 480px); padding: 28px 0 52px; }
  .site-nav { gap: 3px; margin-bottom: 30px; padding: 4px; }
  .site-nav a { display: grid; place-items: center; min-width: 0; padding: 10px 5px; font-size: 0.68rem; line-height: 1.2; }
  h1 { font-size: clamp(2.7rem, 15vw, 4.5rem); }
  .intro { font-size: 0.87rem; }
  .size-control > div { grid-template-columns: auto 64px 1fr; }
  .score-strip article { padding: 14px 13px; }
  .score-strip strong { font-size: 1.48rem; }
  .score-strip small { font-size: 0.57rem; }
  .board-card, .coach-card { padding: 16px; border-radius: 16px; }
  .board-heading { align-items: start; }
  .board-heading h2 { font-size: 1.3rem; }
  .board-state { font-size: 0.55rem; }
  .board-message { grid-template-columns: 29px minmax(0, 1fr); padding: 11px; }
  .message-mark { width: 27px; height: 27px; }
  .board-actions { display: grid; grid-template-columns: 1fr 1fr; }
}

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