/* Heirloom Checkers — HUD & overlay styles */

:root {
  --ink: #f3ead9;
  --ink-dim: #c9bda4;
  --panel-bg: rgba(24, 18, 12, 0.82);
  --panel-line: rgba(243, 234, 217, 0.12);
  --accent: #d8a04c;
  --accent-deep: #b5482a;
  --dark-piece: #2b2320;
  --light-piece: #e8d9b8;
  --radius: 14px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --font: "Avenir Next", "Segoe UI", system-ui, -apple-system, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: #14100c;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
svg { width: 20px; height: 20px; fill: currentColor; display: block; }

/* ---------- top HUD ---------- */
#hud-top {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  pointer-events: none;
  z-index: 20;
}
#hud-top > div { display: flex; align-items: center; gap: 8px; pointer-events: auto; }
.hud-left { min-width: 150px; }
.hud-right { min-width: 150px; justify-content: flex-end; }

.wordmark {
  font-family: var(--serif);
  font-size: 17px; font-weight: 600; letter-spacing: 0.4px;
  color: var(--ink);
  text-shadow: 0 2px 8px rgba(0,0,0,.6);
  line-height: 1;
}
.wordmark span { display: block; font-size: 11px; letter-spacing: 3.2px; text-transform: uppercase; color: var(--accent); margin-top: 3px; }

.turn-chip {
  display: flex; align-items: center; gap: 9px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 8px 16px; border-radius: 99px;
  font-size: 13.5px; font-weight: 600; letter-spacing: .3px;
  box-shadow: var(--shadow);
  transition: border-color .3s;
  white-space: nowrap;
}
.turn-chip.thinking { border-color: rgba(216, 160, 76, .5); }
.turn-disc {
  width: 15px; height: 15px; border-radius: 50%;
  box-shadow: inset 0 -2px 3px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.5);
  transition: background .3s;
}
.turn-disc.dark { background: radial-gradient(circle at 35% 30%, #5a4a42, var(--dark-piece)); }
.turn-disc.light { background: radial-gradient(circle at 35% 30%, #fff7e0, var(--light-piece) 70%, #c9b48c); }

.spinner {
  width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid rgba(216,160,76,.25); border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.hud-btn {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  height: 38px; min-width: 38px; padding: 0 10px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 11px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
  transition: transform .12s, border-color .2s, background .2s;
}
.hud-btn:hover { border-color: rgba(216,160,76,.55); transform: translateY(-1px); }
.hud-btn:active { transform: translateY(0) scale(.97); }
.hud-btn:disabled { opacity: .35; pointer-events: none; }
.hud-btn.accent { background: linear-gradient(160deg, #a8622b, #7c3f1d); border-color: rgba(232,180,110,.4); padding: 0 14px; }
.hud-btn.accent:hover { border-color: rgba(232,180,110,.8); }

/* ---------- toast ---------- */
.toast {
  position: fixed; top: calc(70px + env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(40, 22, 12, .92);
  border: 1px solid rgba(216, 160, 76, .45);
  color: #f5e2c0;
  padding: 10px 18px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; letter-spacing: .2px;
  box-shadow: var(--shadow);
  z-index: 40; pointer-events: none;
  opacity: 0; transition: opacity .25s, transform .25s;
  max-width: min(86vw, 420px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- side panel ---------- */
.panel {
  position: fixed; top: calc(76px + env(safe-area-inset-top)); right: 14px; bottom: 18px;
  width: 208px;
  display: flex; flex-direction: column;
  background: var(--panel-bg);
  border: 1px solid var(--panel-line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 15;
  overflow: hidden;
  transition: transform .3s ease, opacity .3s ease;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--panel-line);
}
.panel-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 2.4px; color: var(--ink-dim); font-weight: 700; }
.cap-counts { display: flex; gap: 8px; font-size: 12px; }
.cap { display: flex; align-items: center; gap: 4px; color: var(--ink-dim); }
.cap i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; box-shadow: inset 0 -1px 2px rgba(0,0,0,.5); }
.cap.dark i { background: #382e28; }
.cap.light i { background: #e8d9b8; }
.cap b { font-weight: 700; color: var(--ink); }

.move-list {
  flex: 1; overflow-y: auto; list-style: none;
  padding: 8px 6px; font-size: 13px;
  scrollbar-width: thin; scrollbar-color: rgba(216,160,76,.3) transparent;
}
.move-list li {
  display: grid; grid-template-columns: 26px 1fr 1fr; gap: 4px;
  padding: 3px 8px; border-radius: 7px;
}
.move-list li:nth-child(odd) { background: rgba(255,255,255,.03); }
.move-list .no { color: var(--ink-dim); font-size: 11.5px; align-self: center; }
.move-list .mv { font-variant-numeric: tabular-nums; letter-spacing: .3px; padding: 1px 5px; border-radius: 5px; }
.move-list .mv.jump { color: #f0b46a; }
.move-list .mv.crown::after { content: "♛"; margin-left: 3px; font-size: 11px; color: var(--accent); }
.move-list .mv.last { background: rgba(216,160,76,.18); outline: 1px solid rgba(216,160,76,.3); }
.panel-foot { padding: 8px 14px; border-top: 1px solid var(--panel-line); min-height: 32px; }
.ai-stat { font-size: 11px; color: var(--ink-dim); letter-spacing: .3px; }

.only-mobile { display: none; }

/* ---------- overlays / dialogs ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at center, rgba(16, 11, 7, .55), rgba(8, 5, 3, .88));
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  opacity: 1; transition: opacity .35s;
  padding: 18px;
  overflow-y: auto;
}
.overlay.closing { opacity: 0; pointer-events: none; }
.overlay[hidden] { display: none; }

.dialog {
  width: min(430px, 94vw);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  scrollbar-width: none;
  background: linear-gradient(175deg, rgba(46, 34, 22, .96), rgba(26, 18, 11, .97));
  border: 1px solid rgba(216, 160, 76, .28);
  border-radius: 20px;
  padding: 30px 30px 26px;
  box-shadow: 0 30px 90px rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.06);
  text-align: center;
  animation: dialog-in .4s cubic-bezier(.2,.9,.3,1.2);
}
.dialog::-webkit-scrollbar { display: none; }
.dialog.slim { width: min(360px, 92vw); }
@keyframes dialog-in {
  from { transform: translateY(18px) scale(.96); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.menu-title {
  font-family: var(--serif); font-size: 32px; font-weight: 600; letter-spacing: .5px;
}
.menu-title em { font-style: normal; color: var(--accent); }
.menu-sub { color: var(--ink-dim); font-size: 13px; margin: 6px 0 22px; }

.field { margin-bottom: 18px; text-align: left; }
.field-label {
  display: block; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 2.2px;
  color: var(--ink-dim); margin-bottom: 8px;
}

.seg { display: flex; gap: 8px; }
.seg-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 8px; border-radius: 11px;
  background: rgba(255,255,255,.045);
  border: 1px solid var(--panel-line);
  font-size: 13.5px; font-weight: 600;
  transition: all .18s;
}
.seg-btn:hover { border-color: rgba(216,160,76,.4); }
.seg-btn.selected {
  background: linear-gradient(160deg, rgba(168, 98, 43, .5), rgba(124, 63, 29, .5));
  border-color: rgba(232,180,110,.55);
  box-shadow: 0 3px 12px rgba(0,0,0,.3);
}
.mini-disc { width: 14px; height: 14px; border-radius: 50%; box-shadow: inset 0 -2px 3px rgba(0,0,0,.4); }
.mini-disc.dark { background: radial-gradient(circle at 35% 30%, #5a4a42, #2b2320); }
.mini-disc.light { background: radial-gradient(circle at 35% 30%, #fff7e0, #e8d9b8 70%, #c9b48c); }

.levels { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.level-btn {
  text-align: left; padding: 11px 12px; border-radius: 11px;
  background: rgba(255,255,255,.045);
  border: 1px solid var(--panel-line);
  transition: all .18s;
}
.level-btn:hover { border-color: rgba(216,160,76,.4); }
.level-btn.selected {
  background: linear-gradient(160deg, rgba(168, 98, 43, .5), rgba(124, 63, 29, .5));
  border-color: rgba(232,180,110,.55);
}
.level-btn b { display: block; font-size: 14px; }
.level-btn small { display: block; font-size: 11px; color: var(--ink-dim); margin-top: 3px; line-height: 1.35; }

.cta {
  width: 100%; margin-top: 6px;
  padding: 14px; border-radius: 13px;
  background: linear-gradient(165deg, #c97b35, #93481f);
  border: 1px solid rgba(240, 190, 120, .5);
  font-size: 15.5px; font-weight: 700; letter-spacing: .4px; color: #fff6e8;
  box-shadow: 0 8px 24px rgba(150, 75, 25, .35), inset 0 1px 0 rgba(255,255,255,.25);
  transition: transform .15s, box-shadow .2s, filter .2s;
}
.cta:hover { transform: translateY(-1px); filter: brightness(1.08); }
.cta:active { transform: translateY(0) scale(.98); }

.ghost {
  width: 100%; margin-top: 10px; padding: 12px;
  border-radius: 13px; border: 1px solid var(--panel-line);
  font-size: 13.5px; font-weight: 600; color: var(--ink-dim);
  transition: all .18s;
}
.ghost:hover { color: var(--ink); border-color: rgba(216,160,76,.4); }
.ghost.subtle { border: none; margin-top: 4px; font-size: 12.5px; }

.rules-note { margin-top: 16px; font-size: 11px; color: rgba(201, 189, 164, .6); letter-spacing: .3px; }

/* ---------- game over ---------- */
.medal {
  width: 74px; height: 74px; margin: 0 auto 14px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  background: radial-gradient(circle at 35% 28%, #ffe9b0, #d8a04c 55%, #8a5a1c);
  box-shadow: 0 8px 26px rgba(216, 160, 76, .4), inset 0 2px 4px rgba(255,255,255,.5);
  animation: medal-pop .55s cubic-bezier(.2,1.4,.4,1);
}
.medal.draw { background: radial-gradient(circle at 35% 28%, #d9d4c8, #9d968a 55%, #5c564c); box-shadow: 0 8px 26px rgba(160,150,130,.3), inset 0 2px 4px rgba(255,255,255,.4); }
@keyframes medal-pop { from { transform: scale(.3) rotate(-14deg); opacity: 0; } }
#go-title { font-family: var(--serif); font-size: 27px; }
.go-reason { color: var(--ink-dim); font-size: 13.5px; margin: 6px 0 20px; }
.row { display: flex; gap: 10px; }
.row .cta, .row .ghost { margin-top: 0; }

/* ---------- hints ---------- */
.rotate-hint {
  position: fixed; bottom: calc(14px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  font-size: 11.5px; letter-spacing: .4px; color: rgba(243,234,217,.55);
  background: rgba(20, 14, 9, .55); padding: 7px 14px; border-radius: 99px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  z-index: 10; pointer-events: none;
  transition: opacity .6s;
}
.rotate-hint.fade { opacity: 0; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  #hud-top > .hud-left { display: none; }
  .hud-center {
    position: fixed;
    top: calc(58px + env(safe-area-inset-top));
    left: 50%; transform: translateX(-50%);
  }
  #hud-top { justify-content: flex-end; }
  .hud-right { min-width: 0; }
  .only-mobile { display: flex; }
  .panel {
    top: auto; right: 0; left: 0; bottom: 0; width: auto;
    max-height: 42vh;
    border-radius: 18px 18px 0 0;
    transform: translateY(105%);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .panel.open { transform: translateY(0); }
  .rotate-hint { display: none; }
  .hud-btn.accent { font-size: 12.5px; padding: 0 11px; }
}
@media (max-width: 400px) {
  .turn-chip { padding: 7px 11px; font-size: 12px; }
  .levels { grid-template-columns: 1fr; }
  .dialog { padding: 24px 20px 20px; }
}
@media (max-height: 500px) and (orientation: landscape) {
  .dialog { max-height: calc(100vh - 24px); padding: 18px 24px 16px; }
  .menu-title { font-size: 24px; }
  .menu-sub { margin-bottom: 12px; }
  .levels { grid-template-columns: 1fr 1fr 1fr 1fr; }
}
