:root {
  --gold: #d4af37;
  --gold-bright: #f0d78c;
  --gold-dim: #8a6d1f;
  --ink: #14100c;
  --ink-2: #1c1610;
  --panel: rgba(18, 14, 10, 0.82);
  --panel-2: rgba(30, 24, 16, 0.9);
  --paper: #efe6d0;
  --paper-dim: #b9ad90;
  --crimson: #a32c2c;
  --ok: #5dbb6b;
  --bad: #d9534f;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  --radius: 14px;
  font-size: 17px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  background: var(--ink);
  color: var(--paper);
  font-family: "Crimson Pro", Georgia, serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

#app { position: fixed; inset: 0; }

h1, h2, h3, .serif {
  font-family: "Cinzel", Georgia, serif;
  font-weight: 700;
  letter-spacing: 0.04em;
}

button {
  font-family: "Cinzel", Georgia, serif;
  cursor: pointer;
  border: 1px solid rgba(212, 175, 55, 0.55);
  background: linear-gradient(180deg, #2a2214, #191207);
  color: var(--gold-bright);
  padding: 0.55rem 1.1rem;
  border-radius: 10px;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease;
}
button:hover { background: linear-gradient(180deg, #3a2f1a, #241b0c); box-shadow: 0 0 18px rgba(212, 175, 55, 0.25); }
button:active { transform: translateY(1px) scale(0.99); }
button.primary {
  background: linear-gradient(180deg, #d4af37, #a17e1c);
  color: #1a1406;
  font-weight: 700;
  border-color: #f0d78c;
}
button.primary:hover { background: linear-gradient(180deg, #e8c65a, #b89422); }
button.ghost { background: transparent; border-color: rgba(240, 215, 140, 0.35); }
button:disabled { opacity: 0.4; cursor: not-allowed; box-shadow: none; }

/* ---------- screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--ink);
}
.screen.active { display: flex; }

.bg-image {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  z-index: 0;
}
.scrim {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(10, 8, 5, 0.45) 0%, rgba(10, 8, 5, 0.82) 70%, #0c0a07 100%);
  z-index: 1;
}
.content { position: relative; z-index: 2; width: 100%; max-width: 1100px; margin: 0 auto; padding: clamp(4rem, 8vh, 5.2rem) 1rem 3rem; flex: 1; }
#homeScreen .content { padding-top: 1.2rem; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  background: linear-gradient(180deg, rgba(10, 8, 5, 0.92), rgba(10, 8, 5, 0.55));
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(212, 175, 55, 0.18);
}
.topbar .spacer { flex: 1; }
.topbar button { padding: 0.35rem 0.7rem; font-size: 0.82rem; }

.lang-switch { display: flex; gap: 2px; }
.lang-switch button { border-radius: 6px; padding: 0.3rem 0.55rem; font-size: 0.78rem; min-width: 34px; }
.lang-switch button.on { background: linear-gradient(180deg, #d4af37, #a17e1c); color: #1a1406; font-weight: 700; }

.icon-btn { font-size: 1.05rem !important; line-height: 1; padding: 0.4rem 0.6rem !important; }

/* ---------- home ---------- */
.hero-title {
  text-align: center;
  padding-top: clamp(1.5rem, 6vh, 4.5rem);
}
.hero-title .kicker {
  font-family: "Cinzel", serif;
  letter-spacing: 0.5em;
  text-transform: uppercase;
  color: var(--gold-dim);
  font-size: 0.72rem;
  margin-bottom: 0.4rem;
}
.hero-title h1 {
  font-size: clamp(2rem, 6vw, 3.6rem);
  line-height: 1.05;
  color: var(--gold-bright);
  text-shadow: 0 4px 30px rgba(0, 0, 0, 0.7), 0 0 60px rgba(212, 175, 55, 0.25);
}
.hero-title .tagline {
  font-family: "Cinzel", serif;
  font-size: clamp(1.5rem, 4.5vw, 2.6rem);
  letter-spacing: 0.45em;
  text-transform: uppercase;
  color: var(--gold);
  margin-top: 0.35rem;
  text-shadow: 0 3px 20px rgba(0, 0, 0, 0.6);
}
.hero-title .sub {
  color: var(--paper-dim);
  font-style: italic;
  font-size: 1.05rem;
  margin-top: 0.5rem;
}
.home-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.7rem;
  margin: 1.6rem auto 0.4rem;
  max-width: 640px;
}
.home-actions button { font-size: 1.05rem; padding: 0.7rem 1.4rem; }
.online-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0.8rem auto;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  background: rgba(20, 30, 16, 0.7);
  border: 1px solid rgba(93, 187, 107, 0.4);
  color: #a8e3ae;
  font-size: 0.85rem;
}
.online-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

/* ---------- era timeline ---------- */
.era-timeline {
  display: flex;
  gap: 0.9rem;
  overflow-x: auto;
  padding: 1rem 0.4rem 1.4rem;
  scroll-snap-type: x mandatory;
}
.era-card {
  flex: 0 0 auto;
  width: clamp(210px, 30vw, 260px);
  scroll-snap-align: center;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(212, 175, 55, 0.35);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease;
  background: var(--ink-2);
}
.era-card:hover { transform: translateY(-4px); border-color: var(--gold); }
.era-card.locked { opacity: 0.55; filter: grayscale(0.7); cursor: not-allowed; }
.era-card .card-img { width: 100%; height: 130px; object-fit: cover; display: block; }
.era-card .card-body { padding: 0.75rem 0.85rem 0.85rem; }
.era-card .card-body h3 { font-size: 1rem; color: var(--gold-bright); }
.era-card .date { color: var(--paper-dim); font-style: italic; font-size: 0.85rem; margin: 0.2rem 0 0.5rem; }
.era-card .elo-badge {
  display: inline-block;
  font-family: "Cinzel", serif;
  font-size: 0.75rem;
  color: #ffe9a8;
  background: rgba(212, 175, 55, 0.15);
  border: 1px solid rgba(212, 175, 55, 0.4);
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
}
.era-card .stars { color: var(--gold-bright); letter-spacing: 0.15em; margin-top: 0.35rem; font-size: 0.95rem; }
.era-card .lock { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 3rem; color: rgba(240, 215, 140, 0.8); background: rgba(0, 0, 0, 0.25); }

.section-label {
  font-family: "Cinzel", serif;
  color: var(--gold);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  font-size: 0.78rem;
  margin: 1.2rem 0 0.2rem;
}

/* ---------- panels / cards ---------- */
.panel {
  background: var(--panel);
  border: 1px solid rgba(212, 175, 55, 0.25);
  border-radius: var(--radius);
  padding: 1.1rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

/* ---------- era screen ---------- */
.era-header { display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.era-header .big-img {
  width: clamp(200px, 38vw, 340px);
  aspect-ratio: 3 / 2;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid rgba(212, 175, 55, 0.4);
  box-shadow: var(--shadow);
}
.era-header .meta h2 { font-size: clamp(1.4rem, 4vw, 2.2rem); color: var(--gold-bright); }
.era-header .meta .date { font-style: italic; color: var(--paper-dim); font-size: 1.05rem; }
.era-header .meta .champ { margin-top: 0.6rem; color: var(--paper); }
.era-header .meta .champ b { color: var(--gold-bright); }
.story {
  margin-top: 1rem;
  font-size: 1.06rem;
  line-height: 1.6;
  color: var(--paper);
  max-width: 900px;
  text-align: justify;
}
.era-actions { display: flex; flex-wrap: wrap; gap: 0.8rem; margin-top: 1.2rem; }
.era-actions button { font-size: 1.02rem; padding: 0.7rem 1.4rem; }

/* ---------- game layout ---------- */
#gameScreen .game-wrap { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); gap: 1rem; align-items: start; }
@media (max-width: 860px) { #gameScreen .game-wrap { grid-template-columns: 1fr; } }

.board-ctn {
  position: relative;
  width: 100%;
  max-width: min(92vw, 74vh);
  margin: 0 auto;
  aspect-ratio: 1;
  border-radius: var(--radius);
  box-shadow: var(--shadow), 0 0 0 1px rgba(212, 175, 55, 0.35);
  overflow: hidden;
}
.board-ctn canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

.thinking {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  background: rgba(10, 8, 5, 0.8);
  border: 1px solid rgba(212, 175, 55, 0.4);
  border-radius: 999px;
  padding: 0.3rem 1rem;
  font-size: 0.85rem;
  color: var(--gold-bright);
  display: none;
  white-space: nowrap;
}
.thinking .spin {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid rgba(212, 175, 55, 0.3);
  border-top-color: var(--gold-bright);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-right: 0.5rem;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.side-panel { display: flex; flex-direction: column; gap: 0.7rem; }
.game-bar { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.game-bar .who {
  font-family: "Cinzel", serif;
  font-size: 0.9rem;
  color: var(--paper);
  line-height: 1.25;
}
.game-bar .who .turn { color: var(--gold-bright); }
.clock {
  font-family: "Cinzel", serif;
  font-variant-numeric: tabular-nums;
  font-size: 1.15rem;
  color: var(--gold-bright);
  background: rgba(212, 175, 55, 0.12);
  border: 1px solid rgba(212, 175, 55, 0.4);
  padding: 0.2rem 0.7rem;
  border-radius: 8px;
}
.clock.low { color: var(--bad); border-color: var(--bad); }

.captured { min-height: 1.6rem; font-size: 0.9rem; color: var(--paper-dim); display: flex; flex-wrap: wrap; gap: 0.15rem; align-items: center; }
.captured .glyph { font-size: 1.05rem; line-height: 1; }
.move-list {
  height: 140px;
  overflow-y: auto;
  font-family: "Crimson Pro", serif;
  font-size: 0.92rem;
  color: var(--paper);
  line-height: 1.55;
}
.move-list .mv { display: inline-block; margin-right: 0.7rem; }
.move-list .n { color: var(--gold-dim); margin-right: 0.25rem; }

.moves-title { font-family: "Cinzel", serif; font-size: 0.72rem; letter-spacing: 0.25em; color: var(--gold); text-transform: uppercase; margin-bottom: 0.3rem; }

.hint-arrow { position: absolute; z-index: 6; pointer-events: none; }

/* ---------- modals ---------- */
.modal-back {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(6, 4, 2, 0.75);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(3px);
}
.modal-back.open { display: flex; }
.modal {
  width: min(560px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #241c10, #140f08);
  border: 1px solid rgba(212, 175, 55, 0.55);
  border-radius: 18px;
  padding: 1.6rem;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7);
  text-align: center;
  animation: modalIn 0.25s ease;
}
@keyframes modalIn { from { transform: translateY(20px); opacity: 0; } }
.modal h2 { color: var(--gold-bright); font-size: 1.5rem; }
.modal p { margin: 0.7rem 0; line-height: 1.55; }
.modal .big-emoji { font-size: 3rem; }
.stars-big { font-size: 2.2rem; letter-spacing: 0.2em; color: var(--gold-dim); }
.stars-big.filled { color: var(--gold-bright); text-shadow: 0 0 14px rgba(212, 175, 55, 0.6); }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.6rem; margin-top: 1.1rem; }

/* ---------- lesson ---------- */
.lesson-slide { max-width: 760px; margin: 0 auto; }
.lesson-slide h2 { color: var(--gold-bright); font-size: 1.35rem; margin-bottom: 0.8rem; }
.lesson-slide .body { font-size: 1.08rem; line-height: 1.7; text-align: justify; white-space: pre-line; }
.lesson-slide .body b { color: var(--gold-bright); }
.lesson-slide .body .ex { color: var(--paper-dim); font-style: italic; }
.lesson-nav { display: flex; justify-content: space-between; gap: 0.6rem; margin-top: 1.4rem; }

.piece-table { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.7rem; margin: 1rem 0; }
.piece-tile {
  border: 1px solid rgba(212, 175, 55, 0.3);
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
  padding: 0.7rem 0.5rem;
  text-align: center;
}
.piece-tile .glyph { font-size: 2rem; line-height: 1.2; }
.piece-tile .name { font-family: "Cinzel", serif; font-size: 0.85rem; color: var(--gold-bright); }
.piece-tile .move { font-size: 0.8rem; color: var(--paper-dim); }

/* ---------- puzzle ---------- */
.puzzle-top { text-align: center; }
.puzzle-top .task { font-size: 1.25rem; color: var(--gold-bright); font-style: italic; }
.puzzle-top .meta { color: var(--paper-dim); font-size: 0.9rem; margin-top: 0.3rem; }
.puzzle-feedback { margin-top: 0.8rem; font-size: 1.05rem; min-height: 1.5em; }
.puzzle-feedback.ok { color: var(--ok); }
.puzzle-feedback.bad { color: var(--bad); }
.puzzle-mini { max-width: min(92vw, 40vh); }

/* ---------- online ---------- */
.queue-ctn { text-align: center; padding: 2rem 1rem; }
.queue-status { font-size: 1.2rem; color: var(--gold-bright); margin-bottom: 1rem; }
.queue-ctn .big-emoji { font-size: 3.4rem; }
.match-panel { text-align: center; }

/* ---------- leaderboard / forms ---------- */
table.lb { width: 100%; border-collapse: collapse; margin-top: 0.8rem; }
table.lb th { font-family: "Cinzel", serif; color: var(--gold); font-size: 0.78rem; letter-spacing: 0.2em; text-transform: uppercase; padding: 0.45rem 0.6rem; text-align: left; border-bottom: 1px solid rgba(212, 175, 55, 0.3); }
table.lb td { padding: 0.5rem 0.6rem; border-bottom: 1px solid rgba(212, 175, 55, 0.12); }
table.lb tr.me td { color: var(--gold-bright); background: rgba(212, 175, 55, 0.1); }

.field { margin: 0.7rem 0; text-align: left; }
.field label { display: block; font-family: "Cinzel", serif; font-size: 0.8rem; letter-spacing: 0.1em; color: var(--gold); margin-bottom: 0.3rem; }
.field input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid rgba(212, 175, 55, 0.35);
  background: rgba(0, 0, 0, 0.35);
  color: var(--paper);
  font-family: "Crimson Pro", serif;
  font-size: 1rem;
}
.field input:focus { outline: none; border-color: var(--gold-bright); }

.form-err { color: var(--bad); font-size: 0.9rem; min-height: 1.2em; }

/* ---------- promo / footer ---------- */
.footer-note {
  text-align: center;
  color: var(--paper-dim);
  font-size: 0.82rem;
  padding: 1.5rem 0.5rem 0.5rem;
  font-style: italic;
}

/* ---------- maintenance ---------- */
.maint-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.maint-panel { text-align: center; max-width: 560px; padding: 2rem 2.2rem; }
.maint-panel .big-emoji { font-size: 3.4rem; }
.maint-panel h2 { color: var(--gold-bright); font-size: 1.8rem; margin: 0.6rem 0 0.4rem; }
.maint-panel p { color: var(--paper-dim); font-size: 1.05rem; line-height: 1.6; }
.maint-note { margin-top: 0.8rem; font-style: italic; font-size: 0.95rem !important; }

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: rgba(10, 8, 5, 0.92);
  border: 1px solid var(--gold);
  color: var(--gold-bright);
  padding: 0.55rem 1.2rem;
  border-radius: 999px;
  font-size: 0.9rem;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
  max-width: 90vw;
}
.toast.show { opacity: 1; }

@media (max-width: 600px) {
  :root { font-size: 15.5px; }
  .content { padding: clamp(3.8rem, 8vh, 5.2rem) 0.7rem 2rem; }
  #homeScreen .content { padding-top: 0.8rem; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(212, 175, 55, 0.3); border-radius: 4px; }
::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.2); }
