/* Crownhead — parlor styling. Warm woods, brass, felt. */

:root {
  --ink: #f2e7d8;
  --ink-dim: #b7a893;
  --brass: #d9a441;
  --brass-soft: rgba(217, 164, 65, 0.55);
  --felt: #21301f;
  --panel: rgba(24, 18, 13, 0.86);
  --panel-line: rgba(217, 164, 65, 0.16);
  --red: #c8403f;
  --black-p: #2b2118;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
  --rad: 14px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: #0b0908;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#stage.dragging { cursor: grabbing; }
#stage.piece-hover { cursor: pointer; }

#vignette {
  position: fixed; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at 50% 42%, transparent 52%, rgba(0, 0, 0, 0.42) 100%);
}

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip: rect(0 0 0 0); overflow: hidden; white-space: nowrap;
}

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

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
}

.brand {
  font-family: var(--serif);
  font-size: 20px; letter-spacing: 0.04em;
  color: var(--ink); display: flex; align-items: center; gap: 10px;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.8);
}
.brand-mark {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #e0574f, #7c1a1e 70%);
  box-shadow: 0 0 0 2px var(--brass-soft), 0 2px 6px rgba(0,0,0,0.6);
}

#turn-pill {
  margin-left: auto;
  display: flex; align-items: center; gap: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  padding: 8px 16px 8px 10px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
  transition: border-color 0.3s;
}
#turn-pill[data-state="human"] { border-color: rgba(217, 164, 65, 0.5); }
#turn-pill[data-state="thinking"] { border-color: rgba(140, 170, 220, 0.4); }

.turn-dot { width: 20px; height: 20px; border-radius: 50%; flex: none; box-shadow: inset 0 -3px 5px rgba(0,0,0,0.35), 0 0 0 2px rgba(255,255,255,0.12); }
.turn-dot.red { background: radial-gradient(circle at 35% 30%, #d9635b, #7c1a1e 75%); }
.turn-dot.black { background: radial-gradient(circle at 35% 30%, #6b563e, #191009 75%); }

.turn-text { display: flex; flex-direction: column; line-height: 1.15; }
.turn-text strong { font-size: 14.5px; font-weight: 650; }
.turn-text small { font-size: 11.5px; color: var(--ink-dim); }

#think-wrap { display: none; font-style: normal; }
#turn-pill[data-state="thinking"] #think-wrap { display: inline-flex; }
#think-wrap em {
  font-style: normal; font-size: 11px; color: #a9c2e8;
  border: 1px solid rgba(140, 170, 220, 0.35); border-radius: 8px; padding: 2px 7px;
  animation: thinkPulse 1.4s ease-in-out infinite;
}
@keyframes thinkPulse { 50% { opacity: 0.55; } }

.icon-btn {
  display: none; width: 40px; height: 40px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--panel-line); color: var(--ink);
  font-size: 17px; cursor: pointer;
}

/* Banner + toast */
.banner {
  position: absolute; left: 50%; top: 74px; transform: translate(-50%, -12px);
  background: var(--panel); border: 1px solid var(--panel-line);
  border-left: 3px solid var(--brass);
  padding: 9px 16px; border-radius: 10px;
  font-size: 13.5px; opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  box-shadow: var(--shadow); backdrop-filter: blur(8px);
  max-width: min(86vw, 480px); text-align: center;
}
.banner.show { opacity: 1; transform: translate(-50%, 0); }
.banner.warn { border-left-color: #e0684f; }
.banner.gold { border-left-color: var(--brass); }

.toast {
  position: absolute; left: 50%; bottom: 116px; transform: translateX(-50%) translateY(8px);
  background: rgba(32, 20, 14, 0.92); color: var(--ink);
  border: 1px solid var(--panel-line); border-radius: 10px;
  padding: 8px 14px; font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

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

#panel {
  position: absolute; right: 16px; top: 76px; bottom: 16px;
  width: 268px; max-width: calc(100vw - 32px);
  display: flex; flex-direction: column; gap: 12px;
  overflow: hidden auto; scrollbar-width: thin;
}
.card {
  background: var(--panel); border: 1px solid var(--panel-line);
  border-radius: var(--rad); padding: 13px 15px;
  box-shadow: var(--shadow); backdrop-filter: blur(10px);
}
.card h3 {
  margin: 0 0 9px; font-family: var(--serif); font-weight: 600;
  font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--brass);
}
#history-card { flex: 1; min-height: 120px; display: flex; flex-direction: column; }
#history { margin: 0; padding: 0 4px 4px 0; list-style: none; overflow-y: auto; flex: 1; font-size: 13.5px; font-variant-numeric: tabular-nums; }
#history li { display: flex; gap: 8px; padding: 3.5px 6px; border-radius: 7px; }
#history li.last { background: rgba(217, 164, 65, 0.12); }
#history .mv-no { color: var(--ink-dim); min-width: 26px; }
#history .mv.cap { color: #f0a58f; font-weight: 650; }
#hist-empty { color: var(--ink-dim); font-size: 12.5px; margin: 4px 0 0; }

.cap-row { display: flex; align-items: center; gap: 8px; font-size: 12.5px; margin: 6px 0; }
.cap-name { color: var(--ink-dim); min-width: 70px; }
.cap-row .none { color: #5c5142; }
.mini { display: inline-block; width: 13px; height: 13px; border-radius: 50%; margin-right: 3px; vertical-align: -2px; }
.mini.red { background: radial-gradient(circle at 35% 30%, #d9635b, #7c1a1e 75%); }
.mini.black { background: radial-gradient(circle at 35% 30%, #6b563e, #191009 75%); }

.controls { display: flex; flex-direction: column; gap: 9px; }
.btn {
  appearance: none; border: 1px solid var(--panel-line);
  background: rgba(52, 40, 28, 0.7); color: var(--ink);
  font: 600 14px var(--sans); letter-spacing: 0.02em;
  border-radius: 11px; padding: 11px 14px; cursor: pointer;
  transition: transform 0.12s, background 0.2s, border-color 0.2s;
}
.btn:hover { background: rgba(74, 57, 38, 0.8); border-color: rgba(217, 164, 65, 0.4); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: linear-gradient(180deg, #b8862e, #96691f); border-color: #d9a441; color: #fff8ea; }
.btn.primary:hover { background: linear-gradient(180deg, #cb9438, #a5762a); }
.btn.ghost { background: transparent; }
.btn-row { display: flex; gap: 9px; }
.btn-row .btn { flex: 1; padding: 10px 0; font-size: 15px; }

/* ---------------------------------------------------------------- */
/* Modals                                                             */

.modal {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: rgba(6, 4, 3, 0.62); backdrop-filter: blur(4px);
  opacity: 0; pointer-events: none; transition: opacity 0.28s; z-index: 40;
  padding: 18px;
}
.modal.open { opacity: 1; pointer-events: auto; }
.modal-card {
  width: min(480px, 100%); max-height: min(84vh, 720px); overflow-y: auto;
  background: linear-gradient(180deg, #241a12, #17100b);
  border: 1px solid var(--panel-line); border-radius: 18px;
  padding: 26px 26px 22px; box-shadow: var(--shadow);
  transform: translateY(14px) scale(0.98); transition: transform 0.28s;
}
.modal.open .modal-card { transform: none; }
.modal-card h2 { font-family: var(--serif); font-size: 24px; margin: 0 0 18px; letter-spacing: 0.02em; }

.field { margin-bottom: 17px; }
.field > label { display: block; font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--brass); margin-bottom: 8px; }
.field > label em { text-transform: none; letter-spacing: 0; color: var(--ink-dim); font-style: normal; }

.seg { display: flex; gap: 8px; }
.seg.col { flex-direction: column; }
.seg-btn {
  flex: 1; text-align: left; cursor: pointer;
  background: rgba(43, 33, 23, 0.65); color: var(--ink);
  border: 1px solid var(--panel-line); border-radius: 12px;
  padding: 10px 13px; display: flex; flex-direction: column; gap: 2px;
  transition: border-color 0.2s, background 0.2s;
}
.seg-btn strong { font-size: 14px; }
.seg-btn span { font-size: 11.5px; color: var(--ink-dim); }
.seg-btn.active { border-color: var(--brass); background: rgba(217, 164, 65, 0.14); }
.seg-btn.active strong { color: #f4d9a2; }
#side-wrap.disabled { opacity: 0.35; pointer-events: none; }

.modal-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.modal-actions .btn { flex: 1; }

.result { text-align: center; }
.result-title { font-size: 34px; margin-bottom: 6px; }
.result-title.red { color: #e2716a; }
.result-title.black { color: #d8c6a0; }
.result-title.draw { color: var(--ink-dim); }
.result-reason { color: var(--ink-dim); margin: 0 0 10px; }
.result-stats { font-size: 13px; color: var(--ink-dim); margin: 0 0 6px; line-height: 1.7; }
.result-stats b { color: var(--ink); font-weight: 600; }

.help-body { font-size: 14px; line-height: 1.65; color: #d9cbb8; }
.help-body p { margin: 0 0 12px; }
.help-body kbd {
  font-family: var(--sans); font-size: 11.5px; border: 1px solid var(--panel-line);
  border-bottom-width: 2px; border-radius: 5px; padding: 1px 6px; background: rgba(0,0,0,0.35);
}

/* ---------------------------------------------------------------- */
/* Mobile                                                             */

@media (max-width: 860px), (max-height: 560px) {
  .brand { font-size: 16px; }
  .brand .brand-mark { width: 11px; height: 11px; }
  #panel-toggle { display: grid; place-items: center; }

  #panel {
    position: fixed; left: 0; right: 0; top: auto; bottom: 0; width: auto;
    flex-direction: row; gap: 0; padding: 0;
    transform: translateY(calc(100% - 0px));
    transition: transform 0.32s cubic-bezier(0.2, 0.9, 0.25, 1);
    background: transparent; overflow: visible; height: 0;
  }
  body.panel-open #panel { transform: translateY(-46vh); }
  #panel::before { /* sheet backdrop */
    content: ""; position: absolute; inset: -46vh 0 0 0;
    background: linear-gradient(180deg, rgba(10,7,5,0.0), rgba(10,7,5,0.9) 30%);
    opacity: 0; transition: opacity 0.3s; pointer-events: none;
  }
  body.panel-open #panel::before { opacity: 1; }

  #panel .card {
    position: absolute; left: 10px; right: 10px; bottom: 10px;
    border-radius: 16px 16px 12px 12px;
  }
  #status-card { bottom: calc(10px + 76vw * 0 + 118px); display: none; }
  #history-card {
    bottom: 108px; top: auto; max-height: 30vh; min-height: 0;
  }
  #controls-card {
    bottom: 10px; flex-direction: row; padding: 9px 10px;
  }
  #controls-card .btn { padding: 9px 12px; font-size: 12.5px; }
  #btn-new { flex: 1.4; }
  #btn-undo { flex: 1; }
  .btn-row { flex: 0 0 auto; }
  .btn-row .btn { padding: 9px 11px; }

  #banner { top: 64px; font-size: 12.5px; }
  .toast { bottom: 132px; }
  .modal-card { padding: 20px 18px 16px; }
  .modal-card h2 { font-size: 21px; }
  .result-title { font-size: 27px; }
}
