/* ======================================================================
   The Endgame Study — dark-academia chess-manual theme
   Display: Fraunces · Body: Spectral · Notation: IBM Plex Mono
   ====================================================================== */

:root {
  --bg:        #15110c;
  --bg-2:      #1b1610;
  --panel:     #221b14;
  --panel-2:   #2a221a;
  --line:      rgba(201, 162, 39, 0.16);
  --line-soft: rgba(236, 228, 212, 0.08);

  --ink:       #ece4d4;
  --ink-dim:   #a99a83;
  --ink-faint: #6f6453;

  --brass:     #c9a227;
  --brass-lit: #e6cd76;
  --sage:      #93b06a;
  --oxblood:   #c4583f;

  --serif:  "Spectral", Georgia, "Times New Roman", serif;
  --display:"Fraunces", Georgia, serif;
  --mono:   "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;

  --radius: 4px;
  --shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.8);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--serif);
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(201, 162, 39, 0.08), transparent 60%),
    radial-gradient(100% 100% at 50% 120%, rgba(147, 176, 106, 0.05), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Subtle film-grain overlay for paper-like texture */
.grain {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ---------- Masthead ---------- */
.masthead {
  position: relative;
  z-index: 2;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(0,0,0,0.25), transparent);
}
.masthead-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 26px 24px 22px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.mark {
  font-size: 40px;
  line-height: 1;
  color: var(--brass);
  text-shadow: 0 0 26px rgba(201, 162, 39, 0.35);
  animation: rise 0.7s ease both;
}
.masthead h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(26px, 4vw, 40px);
  letter-spacing: 0.01em;
  line-height: 0.98;
  background: linear-gradient(180deg, var(--ink) 30%, #cdbf9f);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: rise 0.7s ease 0.05s both;
}
.dek {
  margin: 4px 0 0;
  font-style: italic;
  color: var(--brass-lit);
  font-size: 14px;
  letter-spacing: 0.02em;
  animation: rise 0.7s ease 0.12s both;
}

main {
  position: relative;
  z-index: 2;
  max-width: 1000px;
  margin: 34px auto 80px;
  padding: 0 24px;
}

/* ---------- Champion's Corner ---------- */
.champion {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 210px 1fr;
  gap: 30px;
  align-items: center;
  margin-bottom: 36px;
  padding: 24px;
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(201, 162, 39, 0.1), transparent 55%),
    var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  animation: rise 0.7s ease both;
}
.champion-photo {
  margin: 0;
  padding: 7px;
  background: linear-gradient(145deg, #2c2319, #17110b);
  border: 1px solid rgba(201, 162, 39, 0.35);
  border-radius: 5px;
  box-shadow: 0 16px 40px -20px rgba(0, 0, 0, 0.85);
  transform: rotate(-1.4deg);
  transition: transform 0.4s cubic-bezier(.2,.7,.2,1);
}
.champion:hover .champion-photo { transform: rotate(0deg) scale(1.02); }
.champion-photo img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 3px;
}
.champion-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--brass);
}
.champion-title {
  margin: 8px 0 4px;
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1;
  color: var(--ink);
}
.champion-meta {
  margin: 0 0 12px;
  font-style: italic;
  font-size: 15px;
  color: var(--brass-lit);
}
.champion-note {
  margin: 0;
  max-width: 46ch;
  font-size: 14.5px;
  line-height: 1.6;
  color: var(--ink-dim);
}

/* ---------- Home: topic index ---------- */
.topic-grid {
  counter-reset: study;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
.topic-card {
  counter-increment: study;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.015), transparent),
    var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 24px 24px 20px;
  cursor: pointer;
  transition: transform 0.35s cubic-bezier(.2,.7,.2,1), border-color 0.35s, box-shadow 0.35s;
  animation: rise 0.6s ease both;
}
.topic-card:nth-child(1) { animation-delay: 0.06s; }
.topic-card:nth-child(2) { animation-delay: 0.12s; }
.topic-card:nth-child(3) { animation-delay: 0.18s; }
.topic-card:nth-child(4) { animation-delay: 0.24s; }
.topic-card::before {
  content: counter(study, upper-roman);
  position: absolute;
  top: 14px;
  right: 18px;
  font-family: var(--display);
  font-weight: 900;
  font-size: 30px;
  color: var(--brass);
  opacity: 0.28;
  transition: opacity 0.35s, transform 0.35s;
}
.topic-card:hover {
  transform: translateY(-4px);
  border-color: var(--line);
  box-shadow: var(--shadow);
}
.topic-card:hover::before { opacity: 0.6; transform: scale(1.08); }
.topic-card h3 {
  margin: 0 38px 8px 0;
  font-family: var(--display);
  font-weight: 600;
  font-size: 21px;
  color: var(--ink);
}
.topic-card p {
  margin: 0 0 16px;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--ink-dim);
}
.topic-card .prog {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-faint);
  display: flex;
  align-items: center;
  gap: 8px;
}
.topic-card .prog::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--brass);
  box-shadow: 0 0 8px var(--brass);
}

/* ---------- Training screen ---------- */
.back {
  background: none;
  border: 0;
  color: var(--ink-dim);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  padding: 0;
  margin-bottom: 18px;
  transition: color 0.25s, letter-spacing 0.25s;
}
.back:hover { color: var(--brass-lit); letter-spacing: 0.1em; }

main > h2 {
  font-family: var(--display);
  font-weight: 900;
  font-size: clamp(24px, 3.4vw, 34px);
  margin: 0 0 20px;
  color: var(--ink);
}
main > h2::after {
  content: "";
  display: block;
  width: 54px; height: 2px;
  margin-top: 10px;
  background: linear-gradient(90deg, var(--brass), transparent);
}

.training {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 30px;
  align-items: start;
}

/* Mounted-board frame */
.board-col {
  padding: 12px;
  background: linear-gradient(145deg, #2a2118, #19130d);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(0,0,0,0.4);
  animation: rise 0.6s ease 0.08s both;
}
.board-col .cg-wrap { width: 356px; height: 356px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 22px;
  animation: rise 0.6s ease 0.16s both;
}

/* Underline tabs */
.tabs {
  display: flex;
  gap: 26px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line-soft);
}
.tab {
  padding: 0 0 12px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
  cursor: pointer;
  transition: color 0.25s, border-color 0.25s;
}
.tab:hover { color: var(--ink-dim); }
.tab.on { color: var(--brass-lit); border-bottom-color: var(--brass); }

/* Buttons */
.btn {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 10px 18px;
  border: 1px solid var(--brass);
  border-radius: var(--radius);
  background: var(--brass);
  color: #1a140a;
  cursor: pointer;
  transition: background 0.25s, box-shadow 0.25s, transform 0.1s, color 0.25s;
}
.btn:hover { box-shadow: 0 0 22px -4px var(--brass); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.alt {
  background: transparent;
  color: var(--brass-lit);
}
.btn.alt:hover { background: rgba(201, 162, 39, 0.1); box-shadow: none; }
.btn:disabled { opacity: 0.35; cursor: default; transform: none; box-shadow: none; }
.row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }

/* Feedback banners */
.feedback {
  margin-top: 14px;
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 14.5px;
  background: rgba(236, 228, 212, 0.04);
  border-left: 3px solid var(--ink-faint);
}
.feedback.ok  { background: rgba(147, 176, 106, 0.12); border-left-color: var(--sage); color: #cfe0b6; }
.feedback.bad { background: rgba(196, 88, 63, 0.12);  border-left-color: var(--oxblood); color: #efc3b6; }

/* ---------- Lesson study ---------- */
.chapters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chapter-btn {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  padding: 6px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 100px;
  background: transparent;
  color: var(--ink-dim);
  cursor: pointer;
  transition: all 0.25s;
}
.chapter-btn:hover { border-color: var(--line); color: var(--ink); }
.chapter-btn.on { background: var(--brass); border-color: var(--brass); color: #1a140a; }

.lesson-title {
  margin: 0 0 8px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 22px;
  color: var(--ink);
}
.lesson-intro {
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--ink-dim);
  margin: 0 0 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line-soft);
}
.lesson-log { max-height: 280px; overflow-y: auto; padding-right: 6px; }
.lesson-log::-webkit-scrollbar { width: 8px; }
.lesson-log::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
.lesson-log p {
  margin: 0 0 9px;
  padding: 11px 14px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg-2);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  animation: slidein 0.4s ease both;
}
.lesson-log p:last-child { border-color: var(--line); }
.lesson-log p em { color: var(--ink-dim); }
/* Move notation pops in brass monospace */
.lesson-log strong {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 13px;
  color: var(--brass-lit);
}

/* ---------- Motion ---------- */
@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slidein {
  from { opacity: 0; transform: translateX(8px); }
  to   { opacity: 1; transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 800px) {
  .training { grid-template-columns: 1fr; }
  .board-col { justify-self: center; }
  .topic-grid { grid-template-columns: 1fr; }
  .champion { grid-template-columns: 1fr; gap: 20px; }
  .champion-photo { max-width: 240px; justify-self: center; }
}
@media (max-width: 420px) {
  .board-col .cg-wrap { width: 86vw; height: 86vw; }
}
