:root {
  --bg: #0e1f16;
  --bg-2: #13291c;
  --card: #1b3525;
  --card-2: #21402f;
  --ink: #f1f7ee;
  --ink-dim: #aec4ad;
  --gold: #f2c14e;
  --accent: #5aa45e;
  --accent-2: #2f7d4a;
  --good: #7bd88f;
  --bad: #e98a6b;
  --light-sq: #eaf0d3;
  --dark-sq: #7a9b58;
  --sel: #f2c14e99;
  --hint: #00000033;
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.7);
  --radius: 18px;
}

* { box-sizing: border-box; }

/* The [hidden] attribute must always win, even over our display:grid/flex rules. */
[hidden] { display: none !important; }

/* Confetti canvas — covers the viewport, never blocks clicks, sits under the game overlay. */
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }

html, body { margin: 0; }

body {
  font-family: "Georgia", "Times New Roman", serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 50% -10%, #2f6a40 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg) 60%);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(20px, 5vw, 48px) clamp(16px, 4vw, 32px) 64px;
}

/* ---------- Hero ---------- */
.hero { text-align: center; margin-bottom: clamp(24px, 5vw, 40px); }
.hero__eyebrow {
  letter-spacing: 0.22em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--gold);
  margin: 0 0 12px;
}
.hero__title {
  font-size: clamp(1.9rem, 7vw, 3.1rem);
  line-height: 1.08;
  margin: 0;
  background: linear-gradient(180deg, #fff, var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 30px rgba(245, 196, 81, 0.18);
}
.hero__subtitle {
  margin: 10px 0 0;
  font-size: clamp(1.05rem, 3vw, 1.4rem);
  color: var(--gold);
  font-style: italic;
}
.hero__intro {
  color: var(--ink-dim);
  font-size: clamp(1rem, 2.6vw, 1.12rem);
  line-height: 1.55;
  max-width: 46ch;
  margin: 16px auto 0;
}

/* ---------- Chapters ---------- */
.chapters { list-style: none; margin: 0; padding: 0; display: grid; gap: 18px; }

.chapter {
  background: linear-gradient(160deg, var(--card), var(--card-2));
  border: 1px solid #ffffff14;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, opacity 0.3s ease, border-color 0.3s ease;
}
.chapter--locked { opacity: 0.55; }
.chapter--done { border-color: #f5c45155; }

.chapter__head { display: flex; align-items: center; gap: 14px; }
.chapter__num {
  flex: 0 0 auto;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 1.3rem;
  background: radial-gradient(circle at 35% 30%, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: inset 0 0 0 2px #ffffff22;
}
.chapter--done .chapter__num { background: radial-gradient(circle at 35% 30%, var(--gold), #c98f1a); color: #2a1d00; }
.chapter--locked .chapter__num { background: #2c4233; color: var(--ink-dim); }

.chapter__titles { flex: 1 1 auto; min-width: 0; }
.chapter__title { margin: 0; font-size: 1.22rem; }
.chapter__meta { margin: 2px 0 0; font-size: 0.86rem; color: var(--ink-dim); }

.chapter__action { margin-top: 16px; }

.chapter__reveal { margin-top: 18px; display: grid; gap: 12px; }
.chapter__images { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .chapter__images { grid-template-columns: 1fr; } }
.chapter__images img {
  width: 100%; height: auto; display: block;
  border-radius: 12px;
  border: 1px solid #ffffff1f;
  background: #0003;
  animation: pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.chapter__caption { margin: 0; color: var(--ink-dim); font-size: 0.92rem; text-align: center; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  cursor: pointer;
  border: none;
  border-radius: 999px;
  padding: 13px 26px;
  font-size: 1rem;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 24px -10px var(--accent);
  transition: transform 0.12s ease, filter 0.2s ease;
}
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:hover { filter: brightness(1.08); }
.btn--block { width: 100%; }
.btn--gold { background: linear-gradient(135deg, var(--gold), #d99a1e); color: #2a1d00; box-shadow: 0 10px 24px -10px var(--gold); }
.btn--ghost { background: transparent; border: 1px solid #ffffff33; box-shadow: none; color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.linklike {
  background: none; border: none; color: var(--ink-dim);
  font: inherit; font-size: 0.85rem; cursor: pointer; text-decoration: underline; opacity: 0.7;
}
.foot { text-align: center; margin-top: 36px; }

/* ---------- Finale ---------- */
.finale {
  margin-top: 26px; text-align: center;
  background: linear-gradient(160deg, #1d4030, #2a5e3a);
  border: 1px solid #f2c14e55;
  border-radius: var(--radius); padding: 32px 22px;
  box-shadow: var(--shadow);
  animation: pop 0.6s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.finale__burst { font-size: 3rem; animation: float 2.4s ease-in-out infinite; }
.finale__title { margin: 8px 0 10px; font-size: clamp(1.5rem, 5vw, 2.1rem); color: var(--gold); }
.finale__text { color: var(--ink-dim); line-height: 1.55; margin: 0 auto; max-width: 44ch; }

/* ---------- Game overlay ---------- */
.game {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(10, 7, 18, 0.86);
  backdrop-filter: blur(6px);
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}
.game__panel {
  width: 100%; max-width: 520px;
  background: linear-gradient(160deg, var(--bg-2), var(--bg));
  border: 1px solid #ffffff1a;
  border-radius: 20px;
  padding: 14px clamp(12px, 3.5vw, 20px) 20px;
  box-shadow: var(--shadow);
}
.game__bar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.game__close {
  background: #ffffff14; color: var(--ink); border: none; cursor: pointer;
  width: 36px; height: 36px; border-radius: 50%; font-size: 1rem;
}
.game__heading { font-size: 1.15rem; font-weight: bold; }

.clocks { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.clock {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-radius: 12px;
  background: #ffffff0d; border: 1px solid #ffffff14;
}
.clock__who { color: var(--ink-dim); font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.08em; }
.clock__time { font-variant-numeric: tabular-nums; font-size: 1.5rem; font-weight: bold; }
.clock--active { border-color: var(--gold); box-shadow: 0 0 0 1px var(--gold) inset; }
.clock--active .clock__time { color: var(--gold); }
.clock--low .clock__time { color: var(--bad); }

/* ---------- Board ---------- */
.board {
  width: 100%;
  max-width: 460px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 14px 30px -12px #000, 0 0 0 4px #00000040;
  touch-action: manipulation;
}
.sq {
  position: relative;
  display: grid; place-items: center;
  cursor: pointer;
  user-select: none;
  font-size: min(11vw, 54px);
  line-height: 1;
}
.sq--light { background: var(--light-sq); }
.sq--dark { background: var(--dark-sq); }
.sq--sel::after {
  content: ""; position: absolute; inset: 0;
  background: var(--sel);
}
.sq--last { box-shadow: inset 0 0 0 100px #f5c4512e; }
.sq--check { box-shadow: inset 0 0 0 100px #f8717155; }
.sq__dot {
  position: absolute; width: 30%; height: 30%; border-radius: 50%;
  background: var(--hint); pointer-events: none;
}
.sq--capture .sq__dot { width: 86%; height: 86%; background: none; border: 5px solid #00000033; }
.piece { pointer-events: none; }
.piece--w { color: #fff; text-shadow: 0 1px 0 #000, 0 0 2px #0007, 0 2px 4px #0006; }
.piece--b { color: #1b1b1b; text-shadow: 0 1px 1px #fff6; }

.status { text-align: center; min-height: 1.4em; margin: 14px 0 6px; color: var(--ink-dim); font-size: 1.02rem; }
.status--good { color: var(--good); font-weight: bold; }
.status--bad { color: var(--bad); }
.status--check { color: var(--gold); }

.game__controls { display: flex; gap: 10px; justify-content: center; }

/* ---------- Promotion ---------- */
.promo {
  position: absolute; inset: 0; display: grid; place-items: center;
  background: rgba(10, 7, 18, 0.7);
}
.promo__panel { background: var(--card); border-radius: 16px; padding: 18px 20px; text-align: center; border: 1px solid #ffffff1f; }
.promo__label { margin: 0 0 12px; color: var(--ink-dim); }
.promo__choices { display: flex; gap: 8px; }
.promo__btn {
  width: 56px; height: 56px; font-size: 2rem; cursor: pointer;
  border-radius: 12px; border: 1px solid #ffffff22;
  background: var(--light-sq); color: #1b1b1b;
}
.promo__btn:hover { background: var(--gold); }

/* ---------- Animations ---------- */
@keyframes pop { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }

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