:root {
  --bg: #17181b;
  --bg-2: #1d1f23;
  --panel: #212429;
  --panel-2: #282c32;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #eceae6;
  --muted: #9c978e;
  --brass: #c8a96e;
  --brass-dim: #8d7a52;
  --light-sq: #ebe0c9;
  --dark-sq: #9d7d60;
  --good: #7fbf7f;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(120% 80% at 50% -10%, #262a31 0%, rgba(23, 24, 27, 0) 60%),
    var(--bg);
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px 8px;
}

.brand {
  margin: 0;
  font-size: 17px;
  font-weight: 620;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brass);
}

.turnpill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
}

.turnpill.check {
  color: #ffd9d0;
  border-color: rgba(226, 106, 84, 0.5);
  background: rgba(226, 106, 84, 0.14);
}

.dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5) inset;
}

.dot.white { background: linear-gradient(180deg, #fff, #ddd4c1); }
.dot.black { background: linear-gradient(180deg, #4a4640, #1b1a17); }
.dot.thinking { animation: pulse 1s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

/* -------------------------------------------------------------------- main */

/* Portrait: players above the board, controls below it.
 * Landscape: board on the left, both panels stacked down the right. */
#main {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-areas: "top" "board" "bottom";
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow-x: hidden;
  gap: 8px;
  padding: 0 12px 12px;
}

#panelTop { grid-area: top; }
#boardArea { grid-area: board; }
#panelBottom { grid-area: bottom; }

.board-area {
  position: relative;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.board-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow), 0 0 0 1px rgba(0, 0, 0, 0.5);
}

canvas#board {
  display: block;
  touch-action: none;
  cursor: pointer;
}

/* ---------------------------------------------------------------- overlays */

.promo, .overlay, .confirm {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 13, 15, 0.66);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 5;
  padding: 12px;
}

.promo[hidden], .overlay[hidden], .confirm[hidden] { display: none; }

.promo-card, .overlay-card {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  text-align: center;
  max-width: 320px;
  animation: pop 0.16s ease-out;
}

@keyframes pop {
  from { transform: scale(0.94); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.promo-title {
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 10px;
}

.promo-options { display: flex; gap: 6px; justify-content: center; }

.promo-options button {
  width: 54px;
  height: 54px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
}

.promo-options button:hover { border-color: var(--brass); background: #31363d; }
.promo-options canvas { display: block; margin: auto; pointer-events: none; }

.promo-cancel {
  margin-top: 12px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
}

.overlay-card { max-width: 300px; padding: 20px 18px; }
.overlay-card.small { max-width: 280px; }

.overlay-icon {
  font-size: 19px;
  font-weight: 620;
  letter-spacing: 0.08em;
  color: var(--brass);
  line-height: 1;
  margin-bottom: 10px;
  font-variant-numeric: tabular-nums;
}

.overlay-title {
  font-size: 21px;
  font-weight: 640;
  letter-spacing: -0.01em;
}

.overlay-sub {
  margin-top: 6px;
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.4;
}

.overlay-actions {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ------------------------------------------------------------------- panel */

.card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-height: 0;
  min-width: 0;
  padding: 8px;
  border-radius: var(--radius);
  background: linear-gradient(180deg, var(--panel), #1e2126);
  border: 1px solid var(--line);
}

.controls {
  overflow-y: auto;
  gap: 8px;
  padding: 10px 8px;
}

.players { display: flex; flex-direction: column; gap: 2px; }

.player {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 9px;
  font-size: 13.5px;
  color: var(--muted);
  min-height: 30px;
  transition: background 0.15s, color 0.15s;
}

.player.active {
  background: rgba(200, 169, 110, 0.12);
  color: var(--text);
}

.player.active .pname { font-weight: 620; }

.pname { white-space: nowrap; }

.tray {
  flex: 1 1 auto;
  height: 20px;
  min-width: 0;
  display: block;
}

.adv {
  font-size: 12px;
  color: var(--good);
  font-variant-numeric: tabular-nums;
}

.statusline {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 20px;
  padding: 0 8px;
  font-size: 13.5px;
  color: var(--text);
}

.chip {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(226, 106, 84, 0.18);
  border: 1px solid rgba(226, 106, 84, 0.45);
  color: #ffb9a8;
}

.chip.calm {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line);
  color: var(--muted);
}

.setting {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
}

.setting[hidden] { display: none; }

.setting-label {
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  width: 68px;
  flex: 0 0 auto;
}

.seg {
  flex: 1 1 auto;
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: 10px;
  background: #15171a;
  border: 1px solid var(--line);
  min-width: 0;
}

.seg button {
  flex: 1 1 0;
  min-width: 0;
  padding: 7px 4px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.14s, color 0.14s;
}

.seg.small button { font-size: 11.5px; padding: 6px 2px; }

.seg button:hover { color: var(--text); }

.seg button.on {
  background: var(--brass);
  color: #201c14;
  font-weight: 620;
}

.actions {
  display: flex;
  gap: 6px;
  padding: 2px 8px 0;
}

.btn {
  flex: 1 1 0;
  min-width: 0;
  padding: 9px 6px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.14s, background 0.14s, opacity 0.14s;
}

.btn:hover:not(:disabled) { border-color: var(--line-strong); background: #333941; }
.btn:focus-visible, .seg button:focus-visible, .promo-options button:focus-visible, .promo-cancel:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}
.btn:disabled { opacity: 0.4; cursor: default; }
.btn.primary { background: var(--brass); border-color: var(--brass); color: #201c14; font-weight: 620; }
.btn.primary:hover:not(:disabled) { background: #d8bb80; border-color: #d8bb80; }
.btn.ghost { background: transparent; }
.btn.off { color: var(--muted); }

.moves-wrap {
  display: flex;
  flex-direction: column;
  min-height: 62px;
  flex: 1 1 auto;
  border-top: 1px solid var(--line);
  margin: 2px 8px 0;
  padding-top: 6px;
}

.moves-head {
  font-size: 11px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.moves {
  margin: 0;
  padding: 0 0 4px;
  list-style: none;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 46px;
  max-height: 132px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  columns: 2;
  column-gap: 14px;
}

.moves li {
  break-inside: avoid;
  color: var(--muted);
  padding: 1px 0;
}

.moves li .num { color: #6d6a63; margin-right: 5px; }
.moves li .san { color: var(--text); }
.moves li.latest .san { color: var(--brass); font-weight: 620; }

.moves .empty { color: #6d6a63; font-style: italic; }

/* -------------------------------------------------------- landscape / wide */

@media (min-aspect-ratio: 1/1) {
  #main {
    grid-template-areas: "board top" "board bottom";
    grid-template-columns: minmax(0, 1fr) minmax(272px, 336px);
    grid-template-rows: auto minmax(0, 1fr);
    align-items: stretch;
    padding: 0 14px 14px;
    gap: 12px;
  }

  .moves { columns: 1; max-height: none; }

  .topbar { padding-bottom: 10px; }
}

@media (min-aspect-ratio: 1/1) and (max-height: 460px) {
  .setting-label { width: 58px; font-size: 10px; }
  .player { min-height: 26px; padding: 4px 8px; }
  .btn { padding: 7px 5px; }
}

@media (max-width: 380px) {
  .setting-label { width: 58px; font-size: 10px; }
  .brand { font-size: 15px; }
  .turnpill { font-size: 11.5px; padding: 5px 9px; }
  .seg.small button { font-size: 10.5px; }
  .btn { font-size: 11.5px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

/* ----------------------------------------------------------- 3D art pass */
:root {
  --bg: #090b10;
  --bg-2: #10141c;
  --panel: rgba(20, 25, 34, 0.9);
  --panel-2: #202734;
  --line: rgba(224, 190, 123, 0.13);
  --line-strong: rgba(224, 190, 123, 0.3);
  --text: #f7f1e6;
  --muted: #a79f91;
  --brass: #ddb86e;
  --brass-dim: #806538;
  --good: #86d6ac;
  --shadow: 0 28px 60px rgba(0, 0, 0, 0.7);
}

html, body { background: #090b10; }
body {
  background:
    radial-gradient(ellipse at 50% 21%, rgba(210, 161, 79, .15), transparent 35%),
    radial-gradient(ellipse at 20% 80%, rgba(45, 91, 108, .13), transparent 48%),
    linear-gradient(155deg, #111620 0%, #080a0f 62%, #050609 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .34;
  background-image: repeating-linear-gradient(115deg, transparent 0 54px, rgba(255,255,255,.012) 55px 56px);
}

.topbar { padding: 12px 17px 8px; }
.eyebrow {
  display: block;
  margin-bottom: 2px;
  color: #78664b;
  font-size: 8px;
  font-weight: 750;
  letter-spacing: .29em;
}
.brand {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 21px;
  line-height: 1;
  letter-spacing: .09em;
  text-shadow: 0 2px 14px rgba(221,184,110,.2);
}
.brand b {
  display: inline-block;
  margin-left: 3px;
  padding: 2px 5px 1px;
  border: 1px solid rgba(221,184,110,.42);
  border-radius: 4px;
  font: 700 8px/1.2 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: .15em;
  vertical-align: 4px;
}
.turnpill {
  background: linear-gradient(180deg, rgba(39,45,57,.94), rgba(20,24,32,.94));
  border-color: rgba(221,184,110,.16);
  box-shadow: inset 0 1px rgba(255,255,255,.05), 0 7px 22px rgba(0,0,0,.25);
}

.board-area { overflow: visible; isolation: isolate; }
.board-stage {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(95%, 680px);
  aspect-ratio: 1.42;
  transform: translate(-50%, -48%);
  pointer-events: none;
  background: radial-gradient(ellipse, rgba(0,0,0,.78), rgba(0,0,0,0) 68%);
  filter: blur(7px);
}
.board-stage span { position:absolute; border-radius:50%; filter: blur(20px); }
.board-stage span:nth-child(1) { width:36%; height:20%; left:0; top:18%; background:rgba(255,189,83,.08); }
.board-stage span:nth-child(2) { width:32%; height:18%; right:2%; bottom:12%; background:rgba(56,139,160,.08); }
.board-stage span:nth-child(3) { width:24%; height:12%; left:36%; bottom:0; background:rgba(221,184,110,.07); }

.board-frame {
  overflow: visible;
  border-radius: 7px;
  background: #24190f;
  box-shadow:
    0 2px 0 #d5aa62 inset,
    0 -2px 0 #27180c inset,
    0 0 0 5px #614222,
    0 0 0 7px #1d1209,
    0 9px 0 7px #120b06,
    0 18px 30px rgba(0,0,0,.68),
    0 38px 74px rgba(0,0,0,.45);
}
.board-frame::before {
  content:"";
  position:absolute;
  inset:-7px;
  z-index:-1;
  border-radius:10px;
  background:linear-gradient(135deg,#dfb96f 0,#6d4925 17%,#2b1b0d 48%,#9c6e36 82%,#3a250f 100%);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.board-frame::after {
  content:"";
  position:absolute;
  left:2%; right:2%; bottom:-17px; height:12px;
  z-index:-2;
  border-radius:0 0 10px 10px;
  background:linear-gradient(180deg,#4a2d14,#160d07);
  transform:perspective(300px) rotateX(-28deg);
  transform-origin:top;
}
canvas#board { border-radius: 2px; filter: saturate(1.06) contrast(1.025); }

.card {
  background: linear-gradient(145deg, rgba(32,39,51,.92), rgba(14,18,25,.94));
  border-color: rgba(221,184,110,.13);
  box-shadow: inset 0 1px rgba(255,255,255,.035), 0 12px 30px rgba(0,0,0,.19);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.player.active { background: linear-gradient(90deg, rgba(221,184,110,.17), rgba(221,184,110,.04)); }
.seg { background: rgba(5,7,10,.7); }
.seg button.on, .btn.primary {
  background: linear-gradient(180deg, #eccb86, #bb8c45);
  border-color: #d5aa62;
  box-shadow: inset 0 1px rgba(255,255,255,.35), 0 4px 12px rgba(0,0,0,.22);
}
.promo-card, .overlay-card {
  background: linear-gradient(145deg, #252d3a, #11151d);
  border-color: rgba(221,184,110,.28);
}

@media (max-height: 650px) and (max-aspect-ratio: 1/1) {
  .eyebrow { display:none; }
  .brand { font-size:17px; }
  .topbar { padding-top:8px; }
}
