:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #5d6772;
  --paper: #fffdf4;
  --panel: #ffffff;
  --line: #ded8bd;
  --yellow: #f4c430;
  --yellow-dark: #8a6500;
  --green: #397a48;
  --green-dark: #24542f;
  --red: #a33636;
  --shadow: 0 14px 35px rgba(63, 54, 20, 0.1);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; line-height: 1.55; }
button, input, select, textarea { font: inherit; }
a { color: #245f3c; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid #245f3c; outline-offset: 3px; }

.hero { max-width: 1160px; margin: 20px auto 0; padding: 36px; border-radius: 24px; background: linear-gradient(120deg, #f9d858, #fff4aa 55%, #cce8ae); box-shadow: var(--shadow); display: flex; align-items: center; justify-content: space-between; gap: 28px; }
.hero > div { max-width: 760px; }
.hero h1 { margin: 0 0 12px; font-size: clamp(2rem, 5vw, 3.6rem); line-height: 1.03; }
.hero p:last-child { margin-bottom: 0; font-size: 1.12rem; }
.eyebrow { margin: 0 0 8px; color: var(--green-dark); font-size: .78rem; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
.worksheet-link { flex: 0 0 250px; padding: 15px 18px; border: 2px solid var(--green-dark); border-radius: 14px; color: var(--green-dark); background: rgba(255,255,255,.65); font-weight: 800; text-align: center; text-decoration: none; }
.worksheet-link:hover { background: white; }

.app-shell, .learning-section { max-width: 1160px; margin: 28px auto; padding: 0 16px; }
.panel, .learning-section { border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.panel { padding: 24px; }
.learning-section { padding: 28px; }
.setup { max-width: 920px; margin: 0 auto; }
.setup h2, .panel h2, .learning-section h2 { margin-top: 0; }
.intro { color: var(--muted); }
.setup-grid, .game-grid, .learning-grid, .challenge-grid, .metric-grid { display: grid; gap: 16px; }
.setup-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 20px 0; }
.setup label, .controls label { display: grid; gap: 7px; font-weight: 750; }
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid #bcb596; border-radius: 9px; background: white; color: var(--ink); }
input[type="range"] { padding: 5px 0; accent-color: var(--green); }
fieldset { margin: 22px 0; padding: 0; border: 0; }
legend { margin-bottom: 9px; font-size: 1.05rem; font-weight: 800; }
.challenge-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.challenge-card { display: grid; grid-template-columns: auto 1fr; gap: 2px 9px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #fffef8; cursor: pointer; }
.challenge-card input { width: auto; grid-row: span 2; accent-color: var(--green); }
.challenge-card span { color: var(--muted); font-size: .9rem; }
.rules { margin-bottom: 18px; padding: 14px; border-left: 5px solid var(--yellow); background: #fff8d7; }

button { padding: 11px 16px; border: 0; border-radius: 10px; cursor: pointer; font-weight: 800; }
button:disabled { opacity: .55; cursor: not-allowed; }
.primary { background: var(--green); color: white; }
.primary:hover { background: var(--green-dark); }
.secondary { border: 1px solid var(--green); background: white; color: var(--green-dark); }
.hidden { display: none !important; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.topbar h2 { margin-bottom: 4px; }
.top-actions, .final-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.forecast { margin: 0; color: var(--muted); font-weight: 700; }
.metric-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); margin-bottom: 16px; }
.metric-grid article, .final-stats article { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.metric-grid span { display: block; color: var(--muted); font-size: .8rem; font-weight: 750; text-transform: uppercase; }
.metric-grid strong { display: block; margin-top: 3px; font-size: 1.3rem; }
.game-grid { grid-template-columns: minmax(280px, .72fr) minmax(420px, 1.28fr); }
.controls { display: grid; gap: 15px; }
.controls h2, .controls p { margin-bottom: 0; }
.controls output { float: right; color: var(--green-dark); }
.estimate { display: grid; gap: 4px; padding: 12px; border-radius: 10px; background: #eef7e8; }
.estimate span { display: flex; justify-content: space-between; gap: 12px; }
.validation { min-height: 1.5em; margin: 0; color: var(--red); font-weight: 750; }

.latest-result { margin-bottom: 18px; padding: 16px; border-radius: 12px; background: #f7f4e8; }
.latest-result strong { color: var(--green-dark); }
.latest-result.loss strong { color: var(--red); }
.empty-state { color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: 9px 7px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2) { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
.positive { color: var(--green-dark); font-weight: 800; }
.negative { color: var(--red); font-weight: 800; }
.coach { margin-top: 16px; }
.coach ul { margin-bottom: 0; }
.final-results { margin-top: 16px; }
.final-results textarea { min-height: 110px; margin: 8px 0 14px; resize: vertical; }
.result-links { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.result-links a { padding: 12px; border-radius: 9px; background: #eef7e8; font-weight: 750; text-align: center; }
.learning-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.learning-grid article { padding: 15px; border-radius: 12px; background: #fff9dc; }
.learning-grid h3 { margin-top: 0; }
.faq details { padding: 13px 0; border-bottom: 1px solid var(--line); }
.faq details:last-child { border-bottom: 0; }
.faq summary { cursor: pointer; font-weight: 800; }
.faq details p { margin-bottom: 0; }

@media (max-width: 900px) {
  .hero { margin: 12px; padding: 25px; align-items: stretch; flex-direction: column; }
  .worksheet-link { flex-basis: auto; }
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .game-grid { grid-template-columns: 1fr; }
  .learning-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 620px) {
  .setup-grid, .challenge-grid, .learning-grid, .result-links { grid-template-columns: 1fr; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { align-items: stretch; flex-direction: column; }
  .top-actions button { flex: 1; }
}
