.hidden { display: none !important; }

:root {
  /* Tetrarch theme — warm dark + gold, matching the site */
  --bg: #14100a;
  --panel: #1d1810;
  --panel2: #262013;
  --text: #f2ead9;
  --muted: #b3a488;
  --light: #e7ddc2;
  --dark: #8a6b3f;
  --accent: #d9a94a;
  --red: #d1495b;
  --blue: #3f7cac;
  --yellow: #e2b13c;
  --green: #4a9d6a;
  --sel: rgba(217, 169, 74, 0.5);
  --last: rgba(217, 169, 74, 0.4);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  overflow: hidden;
}

#wrap { display: flex; height: 100vh; gap: 14px; padding: 12px; }

#boardZone { flex: 1; display: flex; align-items: center; justify-content: center; gap: 10px; min-width: 0; }

/* ---- eval bar ---- */
#evalWrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#evalBar {
  width: 16px; height: min(84vh, 60vw, 100vh - 160px);
  background: linear-gradient(#6f8dd8, #4a6ed3);
  border-radius: 8px; overflow: hidden; position: relative;
  box-shadow: inset 0 0 6px rgba(0,0,0,.5);
}
#evalFillRY {
  position: absolute; bottom: 0; left: 0; right: 0; height: 50%;
  background: linear-gradient(#f3d97e, #e2574c);
  transition: height .4s ease;
}
#evalText { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---- board + plates ---- */
#boardArea { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.midRow { display: flex; align-items: center; gap: 6px; }

/* board + permanent a–n / 1–14 coordinate labels (shared from the puzzles look) */
.play {
  display: inline-grid;
  grid-template-columns: 18px auto;
  grid-template-rows: auto 18px;
  gap: 12px;
}
.ranks { grid-column: 1; grid-row: 1; display: grid; grid-template-rows: repeat(14, 1fr); }
.files { grid-column: 2; grid-row: 2; display: grid; grid-template-columns: repeat(14, 1fr); }
.ranks div, .files div {
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; font-weight: 600;
}
#board {
  grid-column: 2; grid-row: 1;
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  grid-template-rows: repeat(14, 1fr);
  width: min(84vh, 60vw, 100vh - 160px);
  height: min(84vh, 60vw, 100vh - 160px);
  border-radius: 6px; overflow: hidden;
  box-shadow: 0 0 0 9px #1f1d1a, 0 12px 34px rgba(0,0,0,.55);
  transition: transform .5s ease;
  position: relative;
}

.sq { position: relative; user-select: none; }
.sq.light { background: var(--light); }
.sq.dark { background: var(--dark); }
.sq.corner { background: transparent; }
/* hover: show the square's coordinate (e.g. h4) */
body.coords .sq:not(.corner):hover::after {
  content: attr(data-sq); position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%); width: 55%; height: 55%;
  display: flex; align-items: center; justify-content: center;
  font: 700 clamp(10px, 1.7vmin, 22px)/1 sans-serif; color: #f7ecd4;
  text-shadow: 0 1px 2px rgba(0,0,0,.6); background: rgba(20,16,10,.5);
  border-radius: 7px; pointer-events: none; z-index: 6;
}
.sq.sel::before, .sq.last::before {
  content: ""; position: absolute; inset: 0; background: var(--last);
}
.sq.sel::before { background: var(--sel); }
.sq.check { background: radial-gradient(circle, #ff6b5e 30%, transparent 75%) , var(--light); }
.sq.dark.check { background: radial-gradient(circle, #ff6b5e 30%, transparent 75%), var(--dark); }

.sq .dot { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.sq .dot::after {
  content: ""; width: 32%; height: 32%; border-radius: 50%;
  background: rgba(0, 0, 0, 0.18);
}
.sq .ring::after {
  content: ""; position: absolute; inset: 4%; border-radius: 50%;
  border: 4px solid rgba(0, 0, 0, 0.2);
}

.piece {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: calc(min(84vh, 60vw, 100vh - 160px) / 14 * 0.82);
  line-height: 1; cursor: grab;
  transition: transform .5s ease;
  z-index: 2;
  text-shadow: 0 1px 2px rgba(0,0,0,.55);
}
.piece.cR { color: var(--red); }
.piece.cB { color: var(--blue); }
.piece.cY { color: var(--yellow); }
.piece.cG { color: var(--green); }
.piece svg { width: 100%; height: 100%; display: block; }

/* the grabbed piece lifts out of its square and tracks the cursor, sized to
   the board — its home square is left empty, exactly like the desktop arena */
.piece.lift {
  position: fixed; left: 0; top: 0; margin: 0; z-index: 100;
  pointer-events: none; cursor: grabbing; transition: none;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,.55)); transform: scale(1.06);
}
#board { touch-action: none; }

/* ---- player plates ---- */
.plate {
  background: var(--panel);
  border-radius: 8px;
  padding: 6px 14px;
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; min-width: 170px; justify-content: space-between;
  border: 1px solid transparent;
}
.plate.active { border-color: var(--accent); box-shadow: 0 0 10px rgba(129,182,76,.35); }
.plate .pname { display: flex; align-items: center; gap: 7px; font-weight: 600; }
.plate .pdot { width: 10px; height: 10px; border-radius: 50%; }
.plate .clock {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px;
  background: #1f1d1a; border-radius: 5px; padding: 2px 9px;
}
.plate .clock.low { color: var(--red); }
.plate-left, .plate-right { flex-direction: column; min-width: 0; padding: 12px 8px; gap: 6px; }

/* ---- sidebar ---- */
#side {
  width: 380px; display: flex; flex-direction: column; gap: 10px; overflow-y: auto;
}
#brand { font-size: 20px; padding: 4px 2px; }
#brand #sub { font-size: 12px; color: var(--muted); margin-left: 8px; }

.statusbar {
  background: var(--panel); border-radius: 8px; padding: 10px 12px;
  font-size: 14px; border-left: 4px solid var(--accent);
}
.statusbar.over { border-left-color: var(--yellow); }

.panel { background: var(--panel); border-radius: 10px; padding: 12px; }
.panelTitle { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 8px; }

.seatsGrid { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.seatRow { display: flex; gap: 6px; align-items: center; }
.seatRow .tag {
  width: 64px; text-align: center; font-weight: 700; border-radius: 5px; padding: 4px 0; font-size: 12px;
  color: #1f1d1a;
}
.seatRow select, .seatRow input, .tcRow input {
  background: var(--panel2); color: var(--text); border: 1px solid #4a4642;
  border-radius: 5px; padding: 5px 7px; font-size: 13px;
}
.seatRow select { width: 105px; }
.seatRow input.cmd { flex: 1; min-width: 0; }
.tcRow { display: flex; gap: 10px; margin-bottom: 10px; }
.tcRow label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.tcRow input { width: 76px; }

button {
  background: var(--panel2); color: var(--text); border: none; border-radius: 6px;
  padding: 8px 12px; font-size: 13px; cursor: pointer; font-weight: 600;
}
button:hover { filter: brightness(1.15); }
button.primary { background: var(--accent); color: #14120f; width: 100%; font-size: 15px; padding: 10px; }
.btnRow { display: flex; gap: 8px; margin-top: 10px; }

#moveList {
  max-height: 200px; overflow-y: auto; font-size: 13px;
  font-variant-numeric: tabular-nums; line-height: 1.7;
}
.mrow { display: grid; grid-template-columns: 30px 1fr 1fr 1fr 1fr; gap: 4px; }
.mrow .num { color: var(--muted); }
.mv { padding: 0 4px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mv.mR { color: var(--red); } .mv.mB { color: var(--blue); }
.mv.mY { color: var(--yellow); } .mv.mG { color: var(--green); }
.mv.cur { background: var(--panel2); }

.engineInfo { font-size: 12px; color: var(--muted); line-height: 1.7; }

/* ---- promotion chooser ---- */
#promoOverlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
#promoOverlay.hidden { display: none; }
#promoBox { background: var(--panel); border-radius: 12px; padding: 14px; display: flex; gap: 10px; }
#promoBox .pchoice { font-size: 56px; cursor: pointer; padding: 6px 10px; border-radius: 8px; }
#promoBox .pchoice svg { width: 56px; height: 56px; display: block; }
#promoBox .pchoice:hover { background: var(--panel2); }

/* ------------------------------------------------------------ game review */
#btnReview { width: 100%; }
#reviewPanel svg { width: 100%; height: 64px; border-radius: 8px; display: block;
  margin-bottom: 8px; cursor: pointer; }
.rvTable { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 8px; }
.rvTable th, .rvTable td { padding: 2px 4px; text-align: left; }
.rvTable th { color: #b3a488; font-weight: 600; }
.rvTable td:nth-child(n+2), .rvTable th:nth-child(n+2) { text-align: right;
  font-variant-numeric: tabular-nums; }
.rvNote { font-size: 12.5px; color: #d8cdb4; min-height: 32px; line-height: 1.45;
  margin-top: 6px; }
.rvNav button { flex: 1; }
.mv .rc { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 4px; vertical-align: middle; }
.mv { cursor: pointer; }

/* ------------------------------------------------------------ PGN4 import */
#importOverlay { position: fixed; inset: 0; background: #000a; z-index: 40;
  display: flex; align-items: center; justify-content: center; }
#importOverlay.hidden { display: none; }
#importBox { width: min(560px, 92vw); background: var(--panel, #1d1810);
  border: 1px solid #3a301e; border-radius: 14px; padding: 18px; }
#importText { width: 100%; height: 180px; margin: 10px 0; resize: vertical;
  background: #14100a; color: #f2ead9; border: 1px solid #3a301e; border-radius: 8px;
  padding: 10px; font: 12px/1.5 monospace; box-sizing: border-box; }
