:root {
  --bg: #11130f;
  --panel: rgba(255, 255, 255, 0.055);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #f1eee5;
  --muted: #a9aa9f;
  --accent: #d6b36b;
  --accent-2: #e1c78c;
  --board: #22251f;
  --tile: #eee7d6;
  --tile-edge: #c9bfaa;
  --gap: 4px;
  --radius: 22px;
  --shadow: 0 28px 80px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(105, 119, 87, .18), transparent 32%),
    radial-gradient(circle at 100% 100%, rgba(122, 91, 54, .16), transparent 34%),
    var(--bg);
}

button { font: inherit; }

.app-shell {
  width: min(1480px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 48px;
}

.topbar,
.toolbar,
.sidepanel {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 28px;
  padding: 24px 28px;
  border-radius: var(--radius);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .18em;
}

h1, h2, p { margin-top: 0; }

h1 {
  margin-bottom: 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(36px, 5vw, 66px);
  line-height: .95;
  font-weight: 500;
}

.subtitle,
.small,
.instructions { color: var(--muted); }
.subtitle { margin-bottom: 0; }

.stats {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.stats > div {
  min-width: 92px;
  padding: 12px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: rgba(0,0,0,.16);
}

.stat-label {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
}

.stats strong { font-size: 19px; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 14px;
  padding: 14px 16px 14px 20px;
  border-radius: 18px;
}

.instructions { font-size: 14px; }
.instructions strong { color: var(--text); }

.actions {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

button {
  border: 0;
  border-radius: 12px;
  padding: 10px 15px;
  cursor: pointer;
  transition: transform .16s ease, opacity .16s ease, background .16s ease;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }

button.primary {
  color: #1a160d;
  background: var(--accent);
  font-weight: 800;
}
button.secondary {
  color: var(--text);
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.08);
}

.game-area {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 22px;
  align-items: start;
  margin-top: 22px;
}

.board-wrap {
  display: grid;
  place-items: center;
  min-width: 0;
}

.board-frame {
  position: relative;
  width: min(100%, 920px);
  aspect-ratio: 1;
  padding: 14px;
  border-radius: 26px;
  background:
    linear-gradient(145deg, #5b3a22, #2b1d14 45%, #6b4628 100%);
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(255,255,255,.09), inset 0 0 0 8px rgba(0,0,0,.20);
}

.board {
  --n: 8;
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: var(--gap);
  width: 100%;
  height: 100%;
  padding: var(--gap);
  border-radius: 15px;
  background: #171912;
  overflow: hidden;
  user-select: none;
}

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 7px;
  overflow: hidden;
  background:
    radial-gradient(circle at 22% 14%, rgba(255,255,255,.32), transparent 30%),
    linear-gradient(135deg, #f5efdf, var(--tile));
  box-shadow:
    inset 0 0 0 1px rgba(62, 47, 29, .18),
    inset 0 -8px 15px rgba(73, 54, 32, .05),
    0 2px 3px rgba(0,0,0,.30);
  cursor: grab;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
}

.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='90' height='90' viewBox='0 0 90 90'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.7' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.055'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}

.tile:hover { filter: brightness(1.04); }
.tile.dragging {
  opacity: .45;
  cursor: grabbing;
  transform: scale(.94);
}
.tile.drop-target {
  box-shadow: inset 0 0 0 4px rgba(214,179,107,.75), 0 0 0 2px rgba(214,179,107,.25);
}
.tile.selected {
  box-shadow: inset 0 0 0 4px rgba(214,179,107,.85), 0 0 0 2px rgba(214,179,107,.28);
}

.tile.locked {
  cursor: default;
  filter: saturate(.92) brightness(.98);
  box-shadow:
    inset 0 0 0 3px rgba(214,179,107,.55),
    inset 0 0 0 1px rgba(62, 47, 29, .18),
    inset 0 -8px 15px rgba(73, 54, 32, .05),
    0 2px 3px rgba(0,0,0,.30);
}
.tile.locked::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 2px solid rgba(214,179,107,.55);
  border-radius: 5px;
  pointer-events: none;
}
.tile.locked:hover {
  filter: saturate(.92) brightness(.98);
}


.tile svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  overflow: visible;
}

.node-overlay {
  position: absolute;
  z-index: 3;
  inset: 18px;
  pointer-events: none;
}

.node {
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(.7);
  opacity: 0;
  background: #8fdd84;
  box-shadow: 0 0 0 3px rgba(143,221,132,.20), 0 0 16px rgba(143,221,132,.78);
  transition: opacity .2s ease, transform .2s ease;
}
.node.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}
.node.bad {
  background: #e16f69;
  box-shadow: 0 0 0 3px rgba(225,111,105,.17), 0 0 13px rgba(225,111,105,.62);
}

.sidepanel {
  position: sticky;
  top: 18px;
  padding: 22px;
  border-radius: var(--radius);
}

.sidepanel h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 28px;
  font-weight: 500;
}

.sidepanel p {
  color: #c7c7bd;
  line-height: 1.55;
}

.rule-demo {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  width: 150px;
  height: 150px;
  margin: 22px auto;
  padding: 4px;
  background: #1b1d18;
  border-radius: 13px;
  overflow: hidden;
}
.demo-cell { background: #efe9da; position: relative; overflow: hidden; }
.demo-cell::after {
  content: "";
  position: absolute;
  width: 80px;
  height: 80px;
  border: 18px double #3f5b4a;
  border-radius: 50%;
}
.q1::after { right: -49px; bottom: -49px; }
.q2::after { left: -49px; bottom: -49px; }
.q3::after { right: -49px; top: -49px; }
.q4::after { left: -49px; top: -49px; }
.demo-center {
  position: absolute;
  left: 50%; top: 50%;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 4px rgba(214,179,107,.18);
}

.message {
  margin-top: 20px;
  padding: 13px 14px;
  border-radius: 13px;
  background: rgba(0,0,0,.18);
  color: var(--accent-2);
  font-size: 13px;
  line-height: 1.45;
}

.modal {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8,9,7,.74);
  backdrop-filter: blur(10px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(470px, 100%);
  padding: 34px;
  text-align: center;
  border: 1px solid rgba(255,255,255,.10);
  border-radius: 24px;
  background: #1a1d17;
  box-shadow: var(--shadow);
}
.modal-card h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 38px;
  font-weight: 500;
  margin-bottom: 10px;
}
.modal-card p:not(.eyebrow) { color: var(--muted); }

@media (max-width: 1020px) {
  .game-area { grid-template-columns: 1fr; }
  .sidepanel { position: static; }
}

@media (max-width: 760px) {
  .app-shell { width: min(100% - 20px, 1480px); padding-top: 10px; }
  .topbar, .toolbar { align-items: stretch; flex-direction: column; }
  .stats { justify-content: flex-start; }
  .toolbar .actions { justify-content: flex-start; }
  .board-frame { padding: 8px; border-radius: 18px; }
  :root { --gap: 2px; }
  .node-overlay { inset: 10px; }
}

/* =========================
   FASE 2 — SCACCHI
   ========================= */
.chess-status {
  min-width: 155px;
  padding: 12px 14px;
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  background: rgba(0,0,0,.16);
  text-align: right;
}
.chess-status strong { font-size: 19px; }
.turn-label {
  display: block;
  margin-top: 4px;
  color: var(--accent-2);
  font-size: 12px;
}

.board-frame.flipping {
  perspective: 1200px;
}
.board-frame.flipping .tile {
  animation: tileFlipOut .72s cubic-bezier(.55,.02,.38,.99) forwards;
  animation-delay: var(--flip-delay, 0ms);
  transform-style: preserve-3d;
}
@keyframes tileFlipOut {
  0% { transform: rotateY(0deg) scale(1); opacity: 1; }
  48% { transform: rotateY(90deg) scale(.96); opacity: .6; }
  100% { transform: rotateY(180deg) scale(.94); opacity: 0; }
}

body.chess-phase .toolbar,
body.chess-phase .sidepanel,
body.chess-phase .node-overlay {
  display: none !important;
}
body.chess-phase .stats { display: none; }
body.chess-phase .chess-status { display: block; }
body.chess-phase .game-area {
  grid-template-columns: minmax(190px, 240px) minmax(480px, 820px) minmax(190px, 240px);
  justify-content: center;
  gap: 20px;
}
body.chess-phase .board-frame {
  width: min(100%, 820px);
}
body.chess-phase .board {
  gap: 0;
  padding: 0;
  border-radius: 12px;
  background: #151610;
}

.chess-prompt {
  width: min(100%, 820px);
  margin-top: 14px;
  padding: 14px 18px;
  text-align: center;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  background: var(--panel);
  backdrop-filter: blur(16px);
}
.chess-prompt strong {
  display: block;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(23px, 3vw, 34px);
  font-weight: 500;
  color: var(--text);
}
.chess-prompt span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

.move-panel {
  position: sticky;
  top: 18px;
  min-height: 310px;
  padding: 20px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}
.move-panel .move-side {
  margin: 0 0 7px;
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .16em;
}
.move-panel h2 {
  margin-bottom: 18px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  line-height: 1.08;
  font-weight: 500;
}
.move-panel h2 span { font-size: .78em; color: var(--muted); }
.move-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}
.move-list li {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 11px;
  background: rgba(0,0,0,.16);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.move-list li::before {
  content: attr(data-move-number);
  min-width: 28px;
  color: var(--muted);
  font-size: 11px;
}
.move-list li.pending {
  color: transparent;
  border-style: dashed;
  background: rgba(0,0,0,.08);
}

.chess-square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  cursor: pointer;
  overflow: hidden;
}
.chess-square.light { background: #e6d9bd; }
.chess-square.dark { background: #6b7757; }
.chess-square.selected {
  box-shadow: inset 0 0 0 5px rgba(214,179,107,.9);
}
.chess-square.last-from::after,
.chess-square.last-to::after {
  content: "";
  position: absolute;
  inset: 7%;
  border: 3px solid rgba(214,179,107,.62);
  border-radius: 8px;
  pointer-events: none;
}
.chess-square.drag-over {
  box-shadow: inset 0 0 0 5px rgba(214,179,107,.9);
}

.chess-piece {
  position: relative;
  z-index: 2;
  width: 82%;
  height: 82%;
  display: grid;
  place-items: center;
  font-family: "DejaVu Sans", "Segoe UI Symbol", "Noto Sans Symbols 2", serif;
  font-size: clamp(36px, 6.2vw, 72px);
  line-height: 1;
  cursor: grab;
  user-select: none;
  filter: drop-shadow(0 3px 2px rgba(0,0,0,.25));
  transition: transform .12s ease;
}
.chess-piece:active { cursor: grabbing; transform: scale(.94); }
.chess-piece.white-piece {
  color: #f7f0df;
  -webkit-text-stroke: 1.4px #24251f;
  text-shadow: 0 1px 0 rgba(0,0,0,.65);
}
.chess-piece.black-piece {
  color: #22241e;
  -webkit-text-stroke: .8px rgba(245,235,210,.35);
}

.board-frame.chess-error {
  animation: chessShake .42s ease;
}
@keyframes chessShake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-10px); }
  40% { transform: translateX(9px); }
  60% { transform: translateX(-7px); }
  80% { transform: translateX(5px); }
}

.board-frame.chess-complete {
  box-shadow:
    0 0 0 2px rgba(214,179,107,.38),
    0 0 46px rgba(214,179,107,.24),
    var(--shadow),
    inset 0 0 0 2px rgba(255,255,255,.09),
    inset 0 0 0 8px rgba(0,0,0,.20);
}

@media (max-width: 1120px) {
  body.chess-phase .game-area {
    grid-template-columns: minmax(150px, 190px) minmax(420px, 1fr) minmax(150px, 190px);
    gap: 12px;
  }
  .move-panel { padding: 14px; }
  .move-panel h2 { font-size: 20px; }
}

@media (max-width: 850px) {
  body.chess-phase .game-area {
    grid-template-columns: 1fr 1fr;
  }
  body.chess-phase .board-wrap {
    grid-column: 1 / -1;
    grid-row: 1;
  }
  body.chess-phase .white-moves { grid-column: 1; grid-row: 2; position: static; min-height: 0; }
  body.chess-phase .black-moves { grid-column: 2; grid-row: 2; position: static; min-height: 0; }
}

.board-frame.chess-reveal .chess-square {
  animation: chessFlipIn .62s cubic-bezier(.2,.7,.25,1) both;
}
@keyframes chessFlipIn {
  0% { transform: rotateY(90deg); opacity: 0; }
  100% { transform: rotateY(0deg); opacity: 1; }
}
