/* Chess — game skin, in the house style of the rest of the family. */

:root {
  --room: #1b1e24;
  --room-2: #101216;
  --gold: #d8b36a;
  --panel: rgba(14, 17, 21, 0.93);
  --panel-line: rgba(216, 179, 106, 0.22);
  --text: #eef1f5;
  --dim: rgba(238, 241, 245, 0.62);
  --danger: #e0645a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 20%, #232830 0%, var(--room) 45%, var(--room-2) 100%);
  color: var(--text);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#table {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: stretch;
  gap: 14px;
  /* --hud-h is measured from the real HUD after every render; the fallback is
     only for the first paint. Hard-coding it let two seat chips wrap onto a
     second row and cover the top ranks of the board. */
  padding: calc(var(--hud-h, 84px) + 8px) 14px max(14px, env(safe-area-inset-bottom));
}

/*
 * min-height MATTERS. On a narrow screen #table becomes a column, and a canvas
 * is a replaced element: its width/height attributes give it an intrinsic
 * aspect ratio, so the default min-height:auto resolves to a transferred size
 * and the canvas simply refuses to shrink. It then eats the whole column and
 * pushes #side past the bottom of a fixed, overflow:hidden page, where it
 * cannot be scrolled to. min-height:0 lets the flex algorithm do its job.
 */
#board { flex: 1; min-width: 0; min-height: 0; display: block; touch-action: none; cursor: pointer; }

#side {
  width: 250px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  overflow: hidden;
}

.moves { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.moves h2 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--dim);
}

.move-grid {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
  font-size: 13.5px;
  scrollbar-width: thin;
}

.move-line {
  display: grid;
  grid-template-columns: 34px 1fr 1fr;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 5px;
}

.move-line:nth-child(odd) { background: rgba(255, 255, 255, 0.04); }
.move-no { color: var(--dim); }
.move-san { font-weight: 600; }

.side-actions { display: flex; flex-direction: column; gap: 6px; }

/* ---------- HUD ---------- */

#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: max(8px, env(safe-area-inset-top)) 14px 8px;
  z-index: 5;
}

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

.seat-chip {
  min-width: 190px;
  padding: 5px 11px 6px;
  border-radius: 11px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.09);
  opacity: 0.66;
}

.seat-chip.on-turn { opacity: 1; border-color: var(--gold); }
.seat-head { display: flex; align-items: center; gap: 7px; }

.seat-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--seat);
  border: 1px solid rgba(0, 0, 0, 0.5);
}

.seat-name { font-weight: 600; font-size: 13.5px; }

.tray {
  display: flex;
  align-items: center;
  gap: 1px;
  margin-top: 2px;
  min-height: 20px;
  flex-wrap: wrap;
}

.taken { display: block; width: 20px; height: 20px; opacity: 0.85; }
.edge { margin-left: 5px; font-size: 12px; font-weight: 700; color: var(--gold); }

.status { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.check-tag {
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(224, 100, 90, 0.18);
  border: 1px solid rgba(224, 100, 90, 0.5);
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}

/* ---------- buttons, menu, modal ---------- */

.btn {
  font: inherit;
  padding: 7px 14px;
  border-radius: 9px;
  border: 1px solid var(--panel-line);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.btn:hover { border-color: var(--gold); }
.btn.ghost { background: rgba(255, 255, 255, 0.05); }
.btn.danger:hover { border-color: var(--danger); color: var(--danger); }
.btn.primary { background: var(--gold); color: #1c1710; border-color: var(--gold); font-weight: 700; }

#menu {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: rgba(8, 10, 13, 0.86);
  backdrop-filter: blur(3px);
  z-index: 20;
  padding: 20px;
  overflow: auto;
}

#menu.open { display: grid; }

.menu-card {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.menu-card h1 { margin: 0 0 4px; font-size: 26px; letter-spacing: 0.06em; color: var(--gold); }
.menu-card .sub { margin: 0 0 16px; color: var(--dim); font-size: 14px; }

.menu-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  text-align: left;
  font: inherit;
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-line);
  border-radius: 10px;
  padding: 11px 14px;
  margin-bottom: 8px;
  cursor: pointer;
}

.menu-item:hover { border-color: var(--gold); background: rgba(216, 179, 106, 0.1); }
.menu-item.primary { background: var(--gold); color: #1c1710; border-color: var(--gold); }
.menu-item.primary .mi-sub { color: rgba(28, 23, 16, 0.75); }
.mi-label { font-weight: 600; }
.mi-sub { font-size: 12.5px; color: var(--dim); }

.form { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.seg-row { display: flex; flex-direction: column; gap: 5px; }
.seg-label { font-size: 12.5px; color: var(--dim); }
.seg { display: flex; gap: 5px; flex-wrap: wrap; }

.seg-btn {
  font: inherit;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
}

.seg-btn.on { background: var(--gold); color: #1c1710; border-color: var(--gold); font-weight: 600; }

.howto { margin: 0 0 12px; padding-left: 20px; font-size: 14px; line-height: 1.5; }
.howto li { margin-bottom: 7px; }

.promo-row { display: flex; gap: 8px; justify-content: center; }

.promo-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--panel-line);
  color: var(--text);
  font: inherit;
  font-size: 12px;
}

.promo-btn:hover { border-color: var(--gold); background: rgba(216, 179, 106, 0.14); }

.lede { font-size: 18px; margin: 0 0 8px; }
.dim { color: var(--dim); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translate(-50%, 12px);
  background: var(--panel);
  border: 1px solid var(--panel-line);
  color: var(--text);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 30;
  max-width: min(92vw, 420px);
  text-align: center;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Modal dialogs; openModal() in src/core/modal.js writes these class names. */

.tt-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 10, 13, 0.6);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.tt-modal {
  min-width: min(400px, 92vw);
  max-width: min(560px, 92vw);
  padding: 18px 20px 16px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.tt-modal-title { margin-bottom: 12px; font-size: 17px; font-weight: 700; color: var(--gold); }
.tt-modal-body { display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.tt-modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.tt-modal-btn {
  padding: 8px 16px;
  border: 1px solid var(--panel-line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.tt-modal-btn:hover { background: rgba(255, 255, 255, 0.12); }
.tt-modal-btn.tt-primary { background: var(--gold); border-color: var(--gold); color: #1c1710; font-weight: 700; }

/* ---------- narrow screens ---------- */

@media (max-width: 900px) {
  #table { flex-direction: column; gap: 8px; }
  #side { width: auto; flex: 0 0 auto; max-height: 30vh; padding: 10px; }
  /* Stacked, the three buttons ate the whole panel and left the move list
     zero pixels tall. In a row they cost one line. */
  .side-actions { flex-direction: row; gap: 6px; }
  .side-actions .btn { flex: 1; padding: 7px 4px; font-size: 13px; }
  .move-grid { max-height: none; }
  .seat-chip { min-width: 0; }
  .status { width: 100%; margin-left: 0; }
}
