:root {
  --ink: #f6eedf;
  --muted: #b9aa94;
  --bg: #17130f;
  --panel: #231d17;
  --panel-2: #2d251d;
  --gold: #d9a441;
  --gold-dark: #8e6424;
  --green: #4f8d67;
  --red: #bd5b4f;
  --light-square: #d8b67d;
  --dark-square: #875834;
  --line: rgba(246, 238, 223, .13);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  min-height: 100dvh; margin: 0;
  background:
    radial-gradient(circle at 50% -20%, rgba(217,164,65,.18), transparent 35rem),
    linear-gradient(135deg, #17130f 0%, #110e0b 100%);
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.topbar {
  width: min(100%, 980px); margin: 0 auto; padding: max(18px, env(safe-area-inset-top)) 20px 12px;
  display: flex; justify-content: space-between; align-items: center;
}
.eyebrow { margin: 0 0 4px; color: var(--gold); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
h1 { margin: 0; font-family: Georgia, serif; font-size: clamp(24px, 6vw, 34px); letter-spacing: .09em; }
.icon-button { width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel); color: var(--ink); font-size: 20px; }

.shell { width: min(100%, 980px); margin: 0 auto; padding: 8px 16px calc(34px + env(safe-area-inset-bottom)); }
.session-strip {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 14px 16px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 16px;
  background: rgba(35,29,23,.88); backdrop-filter: blur(10px);
}
.pilot { display: block; color: var(--muted); font-size: 10px; letter-spacing: .12em; margin-bottom: 4px; }
#progressText { font-size: 15px; }
.clock-card { text-align: right; min-width: 105px; }
.clock-card span { display: block; color: var(--muted); font-size: 9px; letter-spacing: .1em; }
.clock-card output { font-variant-numeric: tabular-nums; color: var(--gold); font-size: 21px; font-weight: 800; }

.training-view { display: grid; grid-template-columns: minmax(300px, 560px) minmax(260px, 1fr); gap: 20px; align-items: start; }
.board-wrap { border-radius: 18px; padding: clamp(7px, 1.5vw, 13px); background: linear-gradient(145deg, #6f4729, #3a2417); box-shadow: 0 24px 55px rgba(0,0,0,.38), inset 0 0 0 1px rgba(255,255,255,.08); }
.board { width: 100%; aspect-ratio: 1; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); touch-action: none; user-select: none; overflow: hidden; border: 1px solid rgba(0,0,0,.45); }
.square { position: relative; display: grid; place-items: center; cursor: pointer;
  min-width: 0; min-height: 0; width: 100%; height: 100%; padding: 0; border: 0; color: inherit; }
.square.light { background: linear-gradient(135deg, #dfc18d, var(--light-square)); }
.square.dark { background: linear-gradient(135deg, #95643d, var(--dark-square)); }
.square.selected::after { content: ""; position: absolute; inset: 3px; border: 4px solid var(--gold); border-radius: 8px; }
.square.destination::before { content: ""; position: absolute; width: 26%; aspect-ratio: 1; border-radius: 50%; background: rgba(217,164,65,.62); }
.square.last-from, .square.last-to { box-shadow: inset 0 0 0 5px rgba(225,190,88,.58); }
.piece { position: relative; z-index: 2; width: 84%; height: 84%; object-fit: contain; filter: drop-shadow(0 3px 1px rgba(0,0,0,.32)); pointer-events: none; }
.piece.white, .piece.black { color: inherit; }
.coord { position: absolute; z-index: 3; font-size: clamp(8px, 1.8vw, 11px); font-weight: 800; opacity: .7; }
.coord.file { right: 3px; bottom: 2px; }
.coord.rank { left: 3px; top: 2px; }
.light .coord { color: var(--dark-square); }
.dark .coord { color: #f1d8aa; }

.task-card { padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: 0 20px 45px rgba(0,0,0,.22); }
.exercise-title { margin: 0 0 6px; color: var(--gold); font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.task-card h2 { margin: 0; font: 700 clamp(22px, 4vw, 30px)/1.2 Georgia, serif; }
.turn-label { color: var(--muted); margin: 10px 0 18px; }
.status { border-radius: 12px; padding: 13px 14px; line-height: 1.4; font-size: 14px; }
.status.neutral { background: var(--panel-2); color: var(--muted); }
.status.good { background: rgba(79,141,103,.19); color: #a9e0ba; border: 1px solid rgba(79,141,103,.52); }
.status.bad { background: rgba(189,91,79,.16); color: #f1aaa1; border: 1px solid rgba(189,91,79,.48); }
.status.technical { background: rgba(217,164,65,.13); color: #f2d38e; border: 1px solid rgba(217,164,65,.42); }
.explanation { margin-top: 14px; padding: 15px; border-left: 3px solid var(--gold); background: rgba(217,164,65,.08); line-height: 1.55; font-size: 14px; }
.actions { display: grid; gap: 10px; margin-top: 16px; }
.button { min-height: 52px; border-radius: 13px; border: 1px solid transparent; font-weight: 850; letter-spacing: .05em; cursor: pointer; }
.button.primary { background: linear-gradient(180deg, #e1ad48, #bd7f25); color: #21160b; box-shadow: 0 8px 20px rgba(189,127,37,.2); }
.button.secondary { background: transparent; border-color: var(--line); color: var(--ink); }
.button.ghost { min-height: 42px; background: transparent; color: var(--muted); font-size: 13px; }
.button:disabled { opacity: .45; cursor: wait; }

.summary { max-width: 760px; margin: 24px auto 0; border: 1px solid var(--line); border-radius: 20px; padding: clamp(22px, 5vw, 38px); background: var(--panel); }
.summary h2 { font: 700 clamp(28px, 6vw, 40px)/1.1 Georgia, serif; margin: 5px 0 8px; }
.summary-note { color: var(--muted); line-height: 1.5; }
.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 22px 0; }
.metric { padding: 15px; border-radius: 13px; background: var(--panel-2); }
.metric span { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.metric strong { display: block; margin-top: 5px; font-size: 24px; font-variant-numeric: tabular-nums; }
.attempt-card { border-top: 1px solid var(--line); padding: 14px 0; }
.attempt-card h3 { margin: 0 0 8px; }
.attempt-card p { margin: 4px 0; color: var(--muted); font-size: 14px; }

.modal { width: min(92vw, 480px); border: 1px solid var(--line); border-radius: 20px; padding: 0; color: var(--ink); background: var(--panel); box-shadow: 0 30px 100px rgba(0,0,0,.7); }
.modal::backdrop { background: rgba(8,6,4,.78); backdrop-filter: blur(5px); }
.modal form { padding: 24px; }
.modal h2 { margin: 5px 0 20px; font: 700 25px/1.2 Georgia, serif; }
.promotion-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.promotion-grid button { min-height: 100px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel-2); color: var(--ink); font-size: 12px; font-weight: 800; }
.promotion-grid span { display: block; height: 52px; margin: 0 auto 5px; }
.promotion-grid .piece { width: 52px; height: 52px; filter: none; }
.cancel-button { width: 100%; margin-top: 12px; padding: 13px; color: var(--muted); background: transparent; border: 0; }
.toggle-row, .volume-row { display: flex; justify-content: space-between; align-items: center; margin: 18px 0 10px; }
#volume { width: 100%; accent-color: var(--gold); }
.settings-modal .button { width: 100%; margin-top: 22px; }
.settings-modal #soundTest { margin-top: 12px; }
.hidden { display: none !important; }

@media (max-width: 760px) {
  .topbar { padding-bottom: 7px; }
  .shell { padding-inline: 10px; }
  .training-view { grid-template-columns: 1fr; gap: 12px; }
  .board-wrap { border-radius: 13px; }
  .task-card { padding: 18px; border-radius: 15px; }
  .task-card h2 { font-size: 23px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 370px) {
  .session-strip { padding: 11px; }
  #progressText { font-size: 13px; }
  .clock-card output { font-size: 18px; }
  .piece { font-size: 9.6vw; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

/* Fase 1.3 — acabado premium sobrio; no altera geometría funcional ni estados. */
:root {
  --ink: #f5efe4;
  --muted: #b9ad9c;
  --bg: #0f0d0b;
  --panel: #1d1915;
  --panel-2: #29221b;
  --gold: #d6a85b;
  --gold-dark: #9b6f31;
  --line: rgba(238, 222, 196, .16);
  --line-strong: rgba(238, 222, 196, .27);
  --light-square: #d8b47a;
  --dark-square: #754b2e;
}

body {
  background:
    radial-gradient(ellipse at 50% -16%, rgba(214,168,91,.13), transparent 34rem),
    radial-gradient(ellipse at 0% 55%, rgba(118,78,42,.08), transparent 28rem),
    #0f0d0b;
}

.topbar { width: min(100%, 1080px); padding-top: max(24px, env(safe-area-inset-top)); padding-bottom: 16px; }
.eyebrow { color: #d6a85b; font-size: 10px; letter-spacing: .2em; }
h1 { font-size: clamp(25px, 6vw, 36px); letter-spacing: .12em; text-shadow: 0 2px 24px rgba(214,168,91,.13); }
.icon-button {
  width: 44px; height: 44px; border-color: var(--line); background: rgba(29,25,21,.74);
  box-shadow: 0 8px 22px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.05);
  transition: border-color .18s ease, background .18s ease, transform .18s ease;
}
.icon-button:hover { border-color: var(--line-strong); background: #2a231c; transform: translateY(-1px); }
.icon-button:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }

.shell { width: min(100%, 1080px); padding-top: 10px; }
.session-strip {
  min-height: 72px; padding: 15px 18px; margin-bottom: 18px; border-radius: 14px;
  border-color: var(--line); background: linear-gradient(115deg, rgba(35,29,24,.94), rgba(25,21,18,.86));
  box-shadow: 0 14px 30px rgba(0,0,0,.19), inset 0 1px 0 rgba(255,255,255,.045);
}
.pilot { color: #9e927f; font-size: 9px; letter-spacing: .2em; }
#progressText { color: #f3eadc; font-weight: 680; letter-spacing: .015em; }
.clock-card { min-width: 112px; }
.clock-card span { color: #9e927f; font-size: 8px; letter-spacing: .16em; }
.clock-card output { color: #e0b86c; font-size: 22px; letter-spacing: .02em; text-shadow: 0 0 20px rgba(214,168,91,.16); }

.training-view { grid-template-columns: minmax(300px, 580px) minmax(280px, 1fr); gap: 24px; }
.board-wrap {
  position: relative; padding: 11px; border-radius: 20px;
  background: linear-gradient(145deg, #795331 0%, #4c2e1d 48%, #2c1b12 100%);
  box-shadow: 0 28px 62px rgba(0,0,0,.48), 0 2px 0 rgba(255,236,195,.12) inset, 0 -2px 0 rgba(0,0,0,.34) inset;
}
.board-wrap::after { content: ""; position: absolute; inset: 5px; border: 1px solid rgba(255,229,181,.12); border-radius: 16px; pointer-events: none; }
.board {
  position: relative; z-index: 1; border: 1px solid rgba(21,12,7,.62);
  box-shadow: 0 2px 0 rgba(255,228,174,.12) inset, 0 10px 24px rgba(0,0,0,.22);
}
.square.light { background: linear-gradient(135deg, #e0c391 0%, #d3ae72 100%); }
.square.dark { background: linear-gradient(135deg, #875a38 0%, #70462b 100%); }
.square:hover { filter: brightness(1.035); }
.square.selected::after { inset: 3px; border: 3px solid #e2b86d; border-radius: 5px; box-shadow: 0 0 0 1px rgba(48,27,14,.4), 0 0 15px rgba(226,184,109,.2); }
.square.destination::before { width: 21%; background: #d9aa59; box-shadow: 0 1px 4px rgba(31,17,9,.35); }
.square.last-from, .square.last-to { box-shadow: inset 0 0 0 4px rgba(236,195,111,.46); }
.piece { width: 82%; height: 82%; filter: drop-shadow(0 4px 2px rgba(20,10,4,.36)); }
.coord { font-size: clamp(8px, 1.7vw, 10px); opacity: .66; letter-spacing: .02em; }

.task-card {
  position: relative; padding: 27px 25px 24px; border-radius: 16px;
  border-color: var(--line); background: linear-gradient(155deg, rgba(34,29,24,.97), rgba(26,22,19,.96));
  box-shadow: 0 22px 46px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.045);
}
.task-card::before { content: ""; position: absolute; top: 22px; left: 0; width: 3px; height: 42px; background: linear-gradient(#d6a85b, transparent); border-radius: 0 3px 3px 0; }
.exercise-title { margin-bottom: 10px; color: #d6a85b; font-size: 10px; letter-spacing: .18em; }
.task-card h2 { max-width: 26ch; margin-bottom: 0; font-size: clamp(23px, 3.6vw, 31px); line-height: 1.16; letter-spacing: -.012em; }
.turn-label { margin: 13px 0 21px; color: #a99c89; font-size: 14px; }
.status { border-radius: 10px; padding: 14px 15px; font-size: 13px; box-shadow: inset 0 1px 0 rgba(255,255,255,.025); }
.status.neutral { background: rgba(53,43,34,.52); color: #bdb1a1; border: 1px solid rgba(239,220,185,.08); }
.explanation { border-left-width: 2px; background: rgba(214,168,91,.07); color: #d6c7b1; }
.actions { gap: 9px; margin-top: 19px; }
.button { min-height: 50px; border-radius: 10px; font-size: 13px; letter-spacing: .08em; transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease, background .16s ease; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translateY(0); }
.button:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.button.primary { background: linear-gradient(180deg, #e0b66b, #b7833b); box-shadow: 0 9px 22px rgba(108,68,22,.24), inset 0 1px 0 rgba(255,244,212,.32); }
.button.primary:hover:not(:disabled) { box-shadow: 0 12px 26px rgba(108,68,22,.34), inset 0 1px 0 rgba(255,244,212,.36); }
.button.secondary { border-color: rgba(239,220,185,.2); background: rgba(45,37,30,.42); color: #f2e7d7; }
.button.secondary:hover:not(:disabled) { border-color: rgba(239,220,185,.4); background: rgba(59,47,37,.65); }
.button.ghost { color: #a99c89; }
.button.ghost:hover:not(:disabled) { color: #dfc7a0; background: rgba(255,255,255,.025); }

.modal { border-color: rgba(239,220,185,.22); background: linear-gradient(155deg, #27211b, #1a1612); box-shadow: 0 34px 100px rgba(0,0,0,.78), inset 0 1px 0 rgba(255,255,255,.05); }
.promotion-grid button { border-color: rgba(239,220,185,.17); background: rgba(48,39,31,.68); transition: transform .16s ease, border-color .16s ease, background .16s ease; }
.promotion-grid button:hover, .promotion-grid button:focus-visible { border-color: rgba(214,168,91,.68); background: rgba(70,55,40,.84); transform: translateY(-1px); outline: none; }

@media (min-width: 761px) {
  .training-view { align-items: start; }
  .task-card { margin-top: 2px; }
}

@media (max-width: 760px) {
  .topbar { padding-top: max(20px, env(safe-area-inset-top)); }
  .shell { padding-inline: 10px; }
  .session-strip { margin-bottom: 15px; }
  .board-wrap { padding: 9px; border-radius: 16px; }
  .board-wrap::after { inset: 4px; border-radius: 13px; }
  .task-card { padding: 23px 19px 20px; }
  .task-card::before { top: 19px; }
  .task-card h2 { max-width: none; }
}

@media (max-width: 370px) {
  .session-strip { padding: 11px 12px; }
  .board-wrap { padding: 8px; }
  .task-card { padding-inline: 16px; }
}

/* El override desktop anterior no debe ganar al modo móvil. */
@media (max-width: 760px) {
  .training-view { grid-template-columns: 1fr; gap: 12px; }
}
