/* =========================================================================
   FIANCHETTO — a chess tactics trainer
   =========================================================================
   DESIGN APPROACH
   ----------------
   Warm "classic study" aesthetic: ivory paper, dark walnut wood, and brass
   hardware — the palette of a well-loved chess set and a library table
   lamp, not a screen. Two Google Fonts carry the whole voice: Playfair
   Display (a sharp, confident serif) for titles and numerals, Inter for
   all interface and body text so long explanations stay easy to read.

   Layout is built around a single warm neutral ("ivory") canvas with
   walnut chrome for structural elements (header, board frame, footer) and
   brass as the one recurring accent color (progress fills, focus rings,
   badges, the connecting "learning path" line). Depth comes from soft
   warm-toned shadows rather than harsh borders. Motion is small and
   purposeful: cards lift a couple of pixels on hover, correct moves get a
   short golden pulse, wrong moves get a quick, gentle shake — nothing
   flashy, everything reinforcing "you got that right" or "look again".

   The board itself uses a warm ivory/walnut square pairing (not the cool
   green/gray of most engines) to stay inside the wood-and-brass palette,
   with a inline SVG piece set (Cburnett/Rfc1394, CC BY-SA 3.0) so the
   whole site works completely offline.
   ========================================================================= */

:root {
  /* Paper & wood */
  --ivory: #f5efe2;
  --ivory-deep: #ece1cb;
  --paper: #fffdf7;
  --walnut-950: #1b120c;
  --walnut-900: #271a11;
  --walnut-800: #3a2717;
  --walnut-700: #4d3521;
  --walnut-600: #654529;
  --walnut-500: #8a6238;

  /* Brass accent */
  --brass: #b8863f;
  --brass-light: #ddb56d;
  --brass-lighter: #f0d9a4;
  --brass-dark: #8c631f;

  /* Board */
  --board-light: #f1e2bf;
  --board-dark: #a5713f;
  --board-dark-deep: #8a5c31;
  --board-border: var(--walnut-900);

  /* Ink */
  --ink: #2a1d12;
  --ink-soft: #5c4a35;
  --ink-faint: #8a765c;

  /* Feedback */
  --success: #3d7a4d;
  --success-bg: #e4efe1;
  --success-border: #a9cba3;
  --warn: #a66a1f;
  --warn-bg: #f7ecd8;
  --warn-border: #e2c48a;
  --error: #a13d2c;
  --error-bg: #f7e3dc;
  --error-border: #dba892;

  /* Tiers */
  --tier-beginner: #5f8a5b;
  --tier-intermediate: #b8863f;
  --tier-advanced: #b0602f;
  --tier-expert: #9a3c3c;
  --tier-master: #4a2e57;

  --shadow-1: 0 1px 2px rgba(27, 18, 12, 0.16);
  --shadow-2: 0 6px 18px rgba(27, 18, 12, 0.18);
  --shadow-3: 0 14px 34px rgba(27, 18, 12, 0.28);

  --font-display: "Playfair Display", "Georgia", serif;
  --font-body: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;

  --radius-s: 6px;
  --radius-m: 12px;
  --radius-l: 20px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--ivory);
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--walnut-900);
  margin: 0 0 0.4em;
  letter-spacing: 0.01em;
}

p { line-height: 1.55; }

a { color: var(--brass-dark); }
a:hover { color: var(--brass); }

button {
  font-family: var(--font-body);
  cursor: pointer;
}

::selection { background: var(--brass-lighter); color: var(--walnut-900); }

.brass-frame {
  height: 5px;
  width: 100%;
  background: linear-gradient(90deg, var(--walnut-900), var(--brass) 20%, var(--brass-light) 50%, var(--brass) 80%, var(--walnut-900));
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------- */
/* Header                                                                  */
/* ---------------------------------------------------------------------- */

.site-header {
  background: linear-gradient(180deg, var(--walnut-900), var(--walnut-950));
  color: var(--ivory);
  box-shadow: var(--shadow-2);
  flex-shrink: 0;
}

.site-header__inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 18px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: inherit;
}

.brand__glyph {
  font-size: 2.4rem;
  color: var(--brass-light);
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,0.4));
}

.brand__text { display: flex; flex-direction: column; }

.brand__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.6rem;
  color: var(--ivory);
  letter-spacing: 0.02em;
}

.brand__pitch {
  font-size: 0.82rem;
  color: var(--brass-light);
  font-style: italic;
}

.overall-progress {
  min-width: 220px;
}

.overall-progress__label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brass-light);
  margin-bottom: 6px;
  text-align: right;
}

.overall-progress__label span { color: var(--paper); font-weight: 700; }

.overall-progress__track {
  width: 220px;
  height: 8px;
  border-radius: 99px;
  background: rgba(255,255,255,0.12);
  overflow: hidden;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.4);
}

.overall-progress__fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brass-dark), var(--brass-light));
  transition: width 0.5s cubic-bezier(.4,0,.2,1);
  border-radius: 99px;
}

/* ---------------------------------------------------------------------- */
/* Main app shell                                                          */
/* ---------------------------------------------------------------------- */

.app {
  flex: 1;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 28px 80px;
}

.site-footer {
  background: var(--walnut-950);
  color: var(--ink-faint);
  font-size: 0.78rem;
  text-align: center;
  padding: 18px 20px 26px;
}

.site-footer a { color: var(--brass-light); }
.site-footer p { max-width: 760px; margin: 0 auto; }

/* ---------------------------------------------------------------------- */
/* Landing / hero                                                          */
/* ---------------------------------------------------------------------- */

.hero {
  text-align: center;
  padding: 10px 0 44px;
}

.hero h1 {
  font-size: clamp(2.1rem, 4vw, 3.2rem);
  font-weight: 800;
}

.hero__pitch {
  font-size: 1.15rem;
  color: var(--ink-soft);
  max-width: 620px;
  margin: 0 auto;
}

.hero__meta {
  margin-top: 18px;
  font-size: 0.85rem;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ---------------------------------------------------------------------- */
/* Learning path                                                          */
/* ---------------------------------------------------------------------- */

.path {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.module-card {
  position: relative;
  display: flex;
  gap: 20px;
  align-items: stretch;
  background: var(--paper);
  border: 1px solid var(--ivory-deep);
  border-radius: var(--radius-l);
  padding: 22px 26px;
  box-shadow: var(--shadow-1);
  transition: box-shadow 0.25s ease, transform 0.25s ease;
  text-decoration: none;
  color: inherit;
}

.module-card:not(.is-locked):hover {
  box-shadow: var(--shadow-2);
  transform: translateY(-3px);
  cursor: pointer;
  border-color: var(--brass-light);
}

.module-card::before {
  content: "";
  position: absolute;
  left: 38px;
  top: 100%;
  width: 2px;
  height: 22px;
  background: linear-gradient(var(--brass-light), transparent);
}

.module-card:last-child::before { display: none; }

.module-card__medallion {
  flex-shrink: 0;
  width: 62px;
  height: 62px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--brass-light), var(--brass-dark));
  color: var(--walnut-950);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.4rem;
  box-shadow: var(--shadow-1), inset 0 1px 2px rgba(255,255,255,0.5);
  border: 2px solid var(--walnut-900);
}

.module-card.is-locked .module-card__medallion {
  background: linear-gradient(var(--ivory-deep), var(--ivory));
  color: var(--ink-faint);
}

.module-card__body { flex: 1; min-width: 0; }

.module-card__top-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.module-card__title {
  font-size: 1.3rem;
  margin-bottom: 2px;
}

.module-card__tagline {
  color: var(--brass-dark);
  font-style: italic;
  font-size: 0.92rem;
  margin-bottom: 8px;
}

.module-card__primer {
  font-size: 0.92rem;
  color: var(--ink-soft);
  max-width: 62ch;
  margin: 0 0 12px;
}

.module-card__footer {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.module-card__count {
  font-size: 0.8rem;
  color: var(--ink-faint);
  font-weight: 600;
  white-space: nowrap;
}

.module-progress-track {
  flex: 1;
  min-width: 120px;
  height: 7px;
  border-radius: 99px;
  background: var(--ivory-deep);
  overflow: hidden;
}

.module-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--tier-beginner), var(--brass));
  border-radius: 99px;
  transition: width 0.4s ease;
}

.lock-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--ink-faint);
  background: var(--ivory-deep);
  padding: 4px 10px;
  border-radius: 99px;
  font-weight: 600;
}

.module-card.is-locked {
  opacity: 0.62;
  filter: grayscale(0.35);
}

.module-card.is-locked:hover { cursor: not-allowed; transform: none; }

.done-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--success);
  background: var(--success-bg);
  padding: 4px 10px;
  border-radius: 99px;
  font-weight: 700;
}

/* ---------------------------------------------------------------------- */
/* Module puzzle grid view                                                 */
/* ---------------------------------------------------------------------- */

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--brass-dark);
  text-decoration: none;
  margin-bottom: 18px;
  background: none;
  border: none;
  padding: 0;
}

.back-link:hover { color: var(--brass); }

.module-header {
  margin-bottom: 26px;
}

.module-header__primer {
  background: var(--ivory-deep);
  border-left: 4px solid var(--brass);
  padding: 14px 18px;
  border-radius: var(--radius-s);
  font-size: 0.95rem;
  color: var(--ink-soft);
  max-width: 72ch;
  margin-top: 12px;
}

.puzzle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
}

.puzzle-badge {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px 12px;
  background: var(--paper);
  border: 2px solid var(--ivory-deep);
  border-radius: var(--radius-m);
  text-decoration: none;
  color: var(--ink);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.puzzle-badge:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-2);
  border-color: var(--brass-light);
}

.puzzle-badge__index {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
}

.puzzle-badge__tier {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  color: #fff;
}

.puzzle-badge__rating {
  font-size: 0.72rem;
  color: var(--ink-faint);
}

.puzzle-badge__status {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: var(--shadow-1);
}

.puzzle-badge__status.solved {
  background: var(--success);
  color: #fff;
}

.puzzle-badge__status.revealed {
  background: var(--warn);
  color: #fff;
}

/* ---------------------------------------------------------------------- */
/* Puzzle player                                                          */
/* ---------------------------------------------------------------------- */

.player {
  display: grid;
  grid-template-columns: minmax(300px, 520px) 1fr;
  gap: 34px;
  align-items: start;
}

@media (max-width: 860px) {
  .player { grid-template-columns: 1fr; }
}

.player-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.player-nav__buttons { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--walnut-700);
  background: var(--paper);
  color: var(--walnut-900);
  font-weight: 600;
  font-size: 0.86rem;
  padding: 9px 16px;
  border-radius: 99px;
  transition: all 0.18s ease;
}

.btn:hover:not(:disabled) {
  background: var(--walnut-900);
  color: var(--ivory);
  box-shadow: var(--shadow-1);
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.btn--brass {
  background: linear-gradient(180deg, var(--brass-light), var(--brass));
  border-color: var(--brass-dark);
  color: var(--walnut-950);
}

.btn--brass:hover:not(:disabled) {
  background: linear-gradient(180deg, var(--brass-lighter), var(--brass-light));
  color: var(--walnut-950);
}

.btn--ghost {
  background: transparent;
  border-color: var(--ivory-deep);
  color: var(--ink-soft);
}

.btn--ghost:hover:not(:disabled) {
  background: var(--ivory-deep);
  color: var(--ink);
}

/* Board */

.board-wrap {
  background: linear-gradient(160deg, var(--walnut-600), var(--walnut-900));
  padding: 18px;
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-3);
}

.board-frame {
  border: 6px solid var(--walnut-950);
  border-radius: var(--radius-s);
  overflow: hidden;
  box-shadow: 0 0 0 2px var(--brass-dark), var(--shadow-2);
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.square.light { background: var(--board-light); }
.square.dark { background: var(--board-dark); }

.square__coord {
  position: absolute;
  font-size: 0.62rem;
  font-weight: 700;
  opacity: 0.55;
  pointer-events: none;
}

.square.light .square__coord { color: var(--board-dark-deep); }
.square.dark .square__coord { color: var(--board-light); }

.square__coord--file { bottom: 2px; right: 4px; }
.square__coord--rank { top: 2px; left: 4px; }

.square.is-selected::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(184, 134, 63, 0.55);
  box-shadow: inset 0 0 0 3px var(--brass-light);
}

.square.is-last-move { background-image: linear-gradient(rgba(184,134,63,0.38), rgba(184,134,63,0.38)); }

.square.is-legal-target .move-dot {
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(58, 39, 23, 0.35);
  pointer-events: none;
}

.square.is-legal-target.has-piece .move-dot {
  width: 100%;
  height: 100%;
  border-radius: 0;
  background: transparent;
  box-shadow: inset 0 0 0 4px rgba(58, 39, 23, 0.45);
}

.square.is-check-king::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle, rgba(161,61,44,0.65), rgba(161,61,44,0));
}

.piece-svg {
  width: 82%;
  height: 82%;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.35));
  transition: transform 0.12s ease;
  cursor: grab;
  touch-action: none;
}

.piece-svg.is-dragging {
  cursor: grabbing;
  opacity: 0.25;
}

.piece-ghost {
  position: fixed;
  width: 64px;
  height: 64px;
  pointer-events: none;
  z-index: 999;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.4));
  transform: translate(-50%, -50%) scale(1.08);
}

.board-frame.shake { animation: board-shake 0.4s ease; }

@keyframes board-shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}

.board-frame.pulse-success { animation: board-pulse 0.7s ease; }

@keyframes board-pulse {
  0% { box-shadow: 0 0 0 2px var(--brass-dark), var(--shadow-2); }
  40% { box-shadow: 0 0 0 6px var(--brass-light), 0 0 40px 6px rgba(221,181,109,0.7); }
  100% { box-shadow: 0 0 0 2px var(--brass-dark), var(--shadow-2); }
}

/* Info panel */

.info-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 99px;
  letter-spacing: 0.02em;
}

.chip--turn {
  background: var(--walnut-900);
  color: var(--ivory);
}

.chip--motif {
  background: var(--ivory-deep);
  color: var(--walnut-800);
  border: 1px solid var(--brass-light);
}

.chip--tier {
  color: #fff;
}

.info-card {
  background: var(--paper);
  border: 1px solid var(--ivory-deep);
  border-radius: var(--radius-m);
  padding: 18px 20px;
  box-shadow: var(--shadow-1);
}

.info-card h3 {
  font-size: 1rem;
  margin-bottom: 8px;
  color: var(--walnut-800);
}

.hint-box {
  font-size: 0.92rem;
  color: var(--ink-soft);
  border-left: 3px solid var(--brass-light);
  padding-left: 12px;
  margin-top: 8px;
}

.feedback-banner {
  border-radius: var(--radius-m);
  padding: 14px 18px;
  font-weight: 600;
  font-size: 0.95rem;
  display: none;
  align-items: center;
  gap: 10px;
  animation: banner-in 0.25s ease;
}

.feedback-banner.show { display: flex; }

.feedback-banner.correct {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid var(--success-border);
}

.feedback-banner.close {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid var(--warn-border);
}

.feedback-banner.illegal {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid var(--error-border);
}

.feedback-banner.revealed {
  background: var(--ivory-deep);
  color: var(--walnut-800);
  border: 1px solid var(--brass-light);
}

@keyframes banner-in {
  from { opacity: 0; transform: translateY(-6px); }
  to { opacity: 1; transform: translateY(0); }
}

.explanation-panel {
  display: none;
  flex-direction: column;
  gap: 10px;
}

.explanation-panel.show { display: flex; }

.explanation-panel__why { font-size: 0.95rem; color: var(--ink); }

.explanation-panel__line {
  font-family: "Inter", monospace;
  background: var(--ivory-deep);
  border-radius: var(--radius-s);
  padding: 10px 14px;
  font-size: 0.88rem;
  color: var(--walnut-800);
}

.actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.source-note {
  font-size: 0.74rem;
  color: var(--ink-faint);
}
.source-note a { color: var(--ink-faint); text-decoration: underline; }

/* Completion banner (all 48 solved) */
.completion-banner {
  text-align: center;
  background: linear-gradient(160deg, var(--walnut-800), var(--walnut-950));
  color: var(--ivory);
  border-radius: var(--radius-l);
  padding: 40px 30px;
  margin-bottom: 30px;
  box-shadow: var(--shadow-3);
}

.completion-banner h2 { color: var(--brass-light); }

/* Utility */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.tier-beginner { background: var(--tier-beginner); }
.tier-intermediate { background: var(--tier-intermediate); }
.tier-advanced { background: var(--tier-advanced); }
.tier-expert { background: var(--tier-expert); }
.tier-master { background: var(--tier-master); }

@media (max-width: 560px) {
  .site-header__inner { padding: 14px 16px; }
  .overall-progress { min-width: 0; width: 100%; }
  .overall-progress__track { width: 100%; }
  .app { padding: 24px 14px 60px; }
  .module-card { flex-direction: column; padding: 18px; }
  .module-card__medallion { width: 46px; height: 46px; font-size: 1.1rem; }
}
