:root {
  --ink: #102a1c;
  --muted: #4b6357;
  --card: #ffffff;
  --brand: #15803d;
  --brand-2: #0369a1;
  --sel: #f0fdf4;
  --sel-border: #16a34a;
  --play: #ea580c;
  --play-dark: #9a3412;
  --good: #16a34a;
  --bad: #dc2626;
  --bg-1: #a3e635;
  --bg-2: #22c55e;
  --bg-3: #0ea5e9;
  --wicker: #b45309;
  --radius: 22px;
  --font: 'Fredoka', ui-rounded, 'SF Pro Rounded', 'Segoe UI', system-ui, sans-serif;
  --emoji: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  font-family: var(--font); color: var(--ink);
  background: linear-gradient(160deg, var(--bg-1), var(--bg-2) 50%, var(--bg-3)) fixed var(--bg-2);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.screen { display: none; }
.screen.active { display: block; }

/* ---------- Home & results ---------- */
#home, #results {
  min-height: 100dvh;
  padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l));
}
.inner { max-width: 820px; margin: 0 auto; display: grid; gap: 16px; }
.back { color: #fff; font-weight: 600; text-decoration: none; justify-self: start; padding: 10px 2px; text-shadow: 0 1px 2px rgba(5, 46, 22, .35); }
.brand { text-align: center; color: #fff; }
.brand .logo { font-size: clamp(40px, 10vw, 64px); line-height: 1.1; font-family: var(--emoji); }
.brand h1 { margin: 2px 0 0; font-size: clamp(34px, 8vw, 56px); text-shadow: 0 3px 0 rgba(5, 46, 22, .3); }
.brand p { margin: 4px 0 0; font-size: clamp(16px, 4vw, 20px); font-weight: 500; text-shadow: 0 1px 2px rgba(5, 46, 22, .3); }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: 0 10px 30px rgba(5, 46, 22, .2); }
.card h2 { margin: 0 0 12px; font-size: 20px; display: flex; align-items: center; gap: 8px; }
.step { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 16px; flex: none; }

.years { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 640px) { .years { grid-template-columns: repeat(6, 1fr); } }
.year { border: 3px solid #e5e7eb; background: #fafaf9; border-radius: 18px; min-height: 76px; display: grid; place-content: center; padding: 6px; }
.year b { font-size: 28px; line-height: 1; }
.year small { color: var(--muted); font-size: 13px; }
.year[aria-checked="true"] { border-color: var(--sel-border); background: var(--sel); box-shadow: 0 0 0 3px rgba(22, 163, 74, .2); }

.dskp { margin-top: 12px; background: #f7fdf9; border-radius: 14px; padding: 10px 12px; }
.dskp summary { cursor: pointer; font-weight: 600; color: var(--brand); min-height: 28px; }
.dskp ul { margin: 10px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.dskp li { display: grid; grid-template-columns: auto 1fr; gap: 8px; font-size: 14px; line-height: 1.35; }
.dskp .code { font-weight: 700; color: var(--brand); white-space: nowrap; }
.dskp .note { margin: 10px 0 0; font-size: 12px; color: var(--muted); }

.option { display: grid; gap: 6px; margin-bottom: 12px; }
.option-label { font-weight: 600; color: var(--muted); font-size: 14px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; min-height: 44px; padding: 8px 12px; border-radius: 14px; border: 2px solid #e5e7eb; background: #fafaf9; font-weight: 500; font-size: 15px; }
.seg button[aria-pressed="true"] { border-color: var(--sel-border); background: var(--sel); font-weight: 600; }
.level-seg button { min-height: 56px; font-size: 17px; }
.level-note { margin: 8px 0 0; font-size: 14px; color: var(--muted); line-height: 1.35; }
.tip { margin: 4px 0 0; font-size: 14px; color: var(--muted); line-height: 1.4; }

.sets { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.set {
  min-height: 64px; padding: 8px 10px; border-radius: 16px; border: 2px solid #e5e7eb; background: #fafaf9;
  display: grid; gap: 2px; justify-items: center; align-content: center; text-align: center; font-size: 15px; font-weight: 500; line-height: 1.2;
}
.set-icons { font-family: var(--emoji); font-size: 22px; line-height: 1.2; letter-spacing: 2px; }
.set[aria-pressed="true"] { border-color: var(--sel-border); background: var(--sel); font-weight: 600; box-shadow: 0 0 0 3px rgba(22, 163, 74, .2); }

.btn { border: 0; border-radius: 999px; min-height: 52px; padding: 10px 26px; font-weight: 700; font-size: 20px; transition: transform .1s; }
.btn:active { transform: translateY(2px); }
.btn-play { background: var(--play); color: #fff; box-shadow: 0 5px 0 var(--play-dark); }
.btn-ghost { background: #fff; color: var(--brand); box-shadow: 0 5px 0 #bbf7d0; }
.btn-small { border: 2px solid #bbf7d0; background: #fff; border-radius: 999px; padding: 6px 16px; font-weight: 600; font-size: 16px; min-height: 44px; }
#playBtn { font-size: 28px; min-height: 68px; justify-self: center; width: min(100%, 360px); }
.install { display: grid; justify-items: center; gap: 6px; color: #fff; font-size: 14px; text-align: center; }
.install p { margin: 0; }

/* ---------- Game ---------- */
#game.active { position: fixed; inset: 0; overflow-y: auto; overflow-x: hidden; display: block; user-select: none; -webkit-user-select: none; }
.layout {
  min-height: 100%; max-width: 1000px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 10px;
  padding: calc(10px + var(--safe-t)) calc(12px + var(--safe-r)) calc(14px + var(--safe-b)) calc(12px + var(--safe-l));
}
.hud { display: flex; gap: 8px; align-items: center; }
.pill { background: rgba(255,255,255,.95); border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: clamp(15px, 2.4vw, 22px); box-shadow: 0 4px 12px rgba(0,0,0,.12); white-space: nowrap; }
.hud-year { margin-left: auto; background: var(--brand); color: #fff; }
.hud-pause { min-width: 48px; min-height: 44px; }
.set-name { margin: 0; text-align: center; color: #fff; font-size: clamp(19px, 3.4vw, 28px); text-shadow: 0 2px 0 rgba(5, 46, 22, .3); line-height: 1.2; }

.stage { flex: 1 0 auto; display: grid; justify-items: center; align-content: center; gap: 10px; }
.wcard {
  position: relative; width: min(100%, 560px); min-height: clamp(150px, 26vh, 240px);
  background: #fff; border-radius: 26px; padding: 30px 18px 18px; box-shadow: 0 8px 0 rgba(5, 46, 22, .15), 0 14px 30px rgba(0,0,0,.15);
  display: grid; justify-items: center; align-content: center; gap: 6px; text-align: center;
  transition: transform .55s cubic-bezier(.5, -0.3, .7, 1), opacity .55s ease-in;
}
.wcard.enter { animation: pop .35s ease-out; }
.wcard.shake { animation: shake .45s; }
.std { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 600; color: var(--brand); background: var(--sel); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.cpic { font-family: var(--emoji); font-size: clamp(52px, 10vh, 96px); line-height: 1.1; }
.cpic:empty { display: none; }
.ctext { font-size: clamp(34px, 7vw, 60px); font-weight: 700; line-height: 1.15; overflow-wrap: anywhere; }
.ctext.long { font-size: clamp(24px, 4.6vw, 38px); line-height: 1.3; overflow-wrap: normal; }
.ctext.xlong { font-size: clamp(21px, 3.8vw, 32px); }
.ctext .gap { display: inline-block; min-width: 2.6em; height: 1em; vertical-align: -0.1em; border-bottom: 4px solid var(--brand); margin: 0 .15em; }
.ctext .gap.filled { height: auto; border-bottom-color: var(--good); color: var(--good); padding: 0 .1em; }
.card-tools { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.card-tools:not(:has(button:not([hidden]))) { display: none; }

.message { text-align: center; font-size: clamp(17px, 2.6vw, 23px); font-weight: 700; color: #fff; text-shadow: 0 2px 0 rgba(5, 46, 22, .35); min-height: 2.6em; line-height: 1.3; display: grid; place-items: center; padding: 0 4px; }
.message.bad { color: #fff7ed; }

/* Baskets */
.baskets { display: grid; gap: 10px; grid-template-columns: repeat(2, 1fr); }
.baskets[data-n="3"] { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 700px) { .baskets[data-n="4"] { grid-template-columns: repeat(4, 1fr); } }
.basket {
  position: relative; min-height: clamp(96px, 15vh, 140px); padding: 10px 6px 12px;
  border: 0; border-top: 9px solid var(--wicker); border-radius: 14px 14px 38px 38px;
  background:
    repeating-linear-gradient(0deg, rgba(120, 53, 15, .1) 0 5px, transparent 5px 12px),
    repeating-linear-gradient(90deg, rgba(120, 53, 15, .07) 0 5px, transparent 5px 14px),
    var(--c, #fde68a);
  box-shadow: 0 6px 0 rgba(120, 53, 15, .35), 0 10px 18px rgba(0,0,0,.15);
  display: grid; justify-items: center; align-content: center; gap: 2px; text-align: center; line-height: 1.15;
  transition: transform .1s, opacity .2s, filter .2s;
}
.basket:active { transform: translateY(3px); }
.b-icon { font-family: var(--emoji); font-size: clamp(30px, 5vh, 44px); line-height: 1.1; }
.b-label { font-weight: 700; font-size: clamp(17px, 2.6vw, 24px); overflow-wrap: anywhere; }
.b-sub { font-size: clamp(12px, 1.8vw, 15px); color: var(--muted); font-weight: 500; }
.b-sub:empty { display: none; }
.b-count { position: absolute; top: 6px; right: 8px; min-width: 26px; height: 26px; padding: 0 6px; border-radius: 999px; background: rgba(255,255,255,.85); font-size: 14px; font-weight: 700; display: grid; place-items: center; }
.key { display: none; position: absolute; top: 6px; left: 8px; width: 26px; height: 26px; border-radius: 8px; background: rgba(255,255,255,.85); border: 2px solid rgba(120, 53, 15, .3); font-size: 14px; font-weight: 700; place-items: center; }
@media (hover: hover) and (pointer: fine) { .key { display: grid; } }
.basket.tried { opacity: .45; filter: grayscale(.7); cursor: default; }
.basket.hint { animation: glow 1s ease-in-out 3; }
.basket.right { box-shadow: 0 0 0 5px var(--good), 0 6px 0 rgba(120, 53, 15, .35); }
.basket.bump { animation: bump .4s ease-out; }

@keyframes pop { from { transform: scale(.6); opacity: 0; } 70% { transform: scale(1.04); opacity: 1; } to { transform: scale(1); } }
@keyframes shake { 20%, 60% { transform: translateX(-10px) rotate(-2deg); } 40%, 80% { transform: translateX(10px) rotate(2deg); } }
@keyframes glow { 50% { box-shadow: 0 0 0 7px #fde047, 0 6px 0 rgba(120, 53, 15, .35); transform: translateY(-4px); } }
@keyframes bump { 40% { transform: scale(1.08, .92); } 70% { transform: scale(.97, 1.03); } }

.overlay { position: fixed; inset: 0; z-index: 7; display: grid; place-items: center; padding: 16px; background: rgba(5, 46, 22, .45); }
.panel { background: #fff; border-radius: var(--radius); padding: 20px; width: min(100%, 480px); text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.ov-icon { font-size: 52px; line-height: 1.1; }
.panel h2 { margin: 6px 0; font-size: 26px; }
.panel p { margin: 0 0 14px; color: var(--muted); font-size: 17px; line-height: 1.4; }
.buttons { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

/* ---------- Results ---------- */
.results { display: grid; gap: 10px; text-align: center; }
.results h2 { justify-content: center; font-size: 30px; margin: 0; }
.results h3 { margin: 10px 0 0; font-size: 18px; }
.stars { font-size: clamp(48px, 13vw, 72px); letter-spacing: 4px; }
.stars .off { filter: grayscale(1); opacity: .3; }
.res-set { margin: 0; font-size: 18px; font-weight: 600; color: var(--brand); }
.res-score { margin: 0; font-size: 20px; font-weight: 600; }
.table-wrap { overflow-x: auto; }
.std-table { width: 100%; border-collapse: collapse; text-align: left; font-size: 14px; }
.std-table th, .std-table td { padding: 8px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.std-table th { color: var(--muted); font-weight: 600; }
.std-table td:first-child { font-weight: 700; color: var(--brand); white-space: nowrap; }
.std-table td:last-child { font-weight: 700; white-space: nowrap; }
#copyBtn { justify-self: center; }
.review-help { margin: 0 0 6px; font-size: 14px; color: var(--muted); }
.review { text-align: left; margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.review li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; background: #f7fdf9; border-radius: 14px; padding: 4px 10px; }
.review button { border: 0; background: none; padding: 6px 0; min-height: 44px; text-align: left; font-size: 18px; font-weight: 600; }
.review .mark { font-size: 15px; font-weight: 600; color: var(--brand); }
.review-none { margin: 0; font-size: 18px; font-weight: 600; color: var(--good); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
