/* Haraya — chess of the barangay kingdoms.
   Visual language: carved hardwood, woven banig, gold leaf, shell inlay,
   torchlit dusk. */

@font-face {
  font-family: 'Philosopher';
  src: url('fonts/philosopher-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Philosopher';
  src: url('fonts/philosopher-700.woff2') format('woff2');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Mulish';
  src: url('fonts/mulish-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Mulish';
  src: url('fonts/mulish-600.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

:root {
  --gold: #d9a441;
  --gold-bright: #f0c15e;
  --ember: #ff8a3c;
  --wood-dark: #241610;
  --wood-mid: #3a2417;
  --wood-panel: rgba(38, 23, 14, 0.92);
  --cream: #f0dfc0;
  --cream-dim: #c9b28c;
  --shell: #a8e0d0;
  --danger: #e0603c;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: #14101f;
  font-family: 'Mulish', system-ui, sans-serif;
  color: var(--cream);
}

#scene-wrap {
  position: fixed;
  inset: 0;
}
#scene-wrap canvas {
  display: block;
  touch-action: none;
  cursor: grab;
}
#scene-wrap canvas:active { cursor: grabbing; }

#ui-root {
  position: fixed;
  inset: 0;
  pointer-events: none;
}
#ui-root > * { pointer-events: auto; }
#ui-root .hud, #ui-root .hud .review-banner { pointer-events: none; }
#ui-root .hud button, #ui-root .hud .side-panel, #ui-root .hud .thinking { pointer-events: auto; }

.hidden { display: none !important; }

h1, h2, h3, .title-kicker, .turn-banner, .btn, .choice {
  font-family: 'Philosopher', serif;
}

/* ---------- screens ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.overlay {
  background: rgba(10, 6, 4, 0.62);
  backdrop-filter: blur(3px);
  z-index: 30;
}

.title-screen {
  background:
    radial-gradient(ellipse at 50% 110%, rgba(255, 140, 60, 0.18), transparent 55%),
    radial-gradient(ellipse at 50% 40%, rgba(20, 10, 30, 0.25), rgba(12, 8, 18, 0.78) 90%);
}
.title-inner { text-align: center; padding: 24px; animation: rise-in 1.1s ease both; }
@keyframes rise-in {
  from { opacity: 0; transform: translateY(26px); }
  to { opacity: 1; transform: none; }
}
.title-kicker {
  color: var(--gold);
  letter-spacing: 0.34em;
  text-transform: uppercase;
  font-size: clamp(10px, 1.6vw, 14px);
  margin-bottom: 8px;
}
.title-name {
  font-size: clamp(64px, 13vw, 148px);
  font-weight: 700;
  line-height: 0.95;
  color: var(--cream);
  text-shadow:
    0 0 34px rgba(255, 150, 60, 0.45),
    0 3px 0 #7a4a1c,
    0 6px 18px rgba(0, 0, 0, 0.7);
  letter-spacing: 0.08em;
}
.title-sub {
  color: var(--cream-dim);
  font-style: italic;
  font-size: clamp(14px, 2.2vw, 20px);
  margin: 10px 0 34px;
}
.title-buttons { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.title-foot { margin-top: 30px; display: flex; gap: 10px; justify-content: center; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid rgba(217, 164, 65, 0.55);
  background: linear-gradient(180deg, rgba(122, 74, 28, 0.95), rgba(74, 44, 20, 0.95));
  color: var(--cream);
  padding: 10px 22px;
  font-size: 16px;
  border-radius: 6px;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 210, 130, 0.25);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 210, 130, 0.4); }
.btn:active { transform: translateY(1px); }
.btn.big { font-size: 19px; padding: 14px 34px; min-width: 300px; }
.btn.small { font-size: 13px; padding: 6px 12px; }
.btn.ghost {
  background: rgba(30, 18, 10, 0.5);
  border-color: rgba(240, 223, 192, 0.25);
  box-shadow: none;
}
.btn.danger { border-color: rgba(224, 96, 60, 0.6); }
.btn.danger.armed {
  background: linear-gradient(180deg, #8a3320, #5e2113);
  border-color: var(--danger);
  animation: pulse-armed 0.8s ease infinite alternate;
}
@keyframes pulse-armed { from { box-shadow: 0 0 4px rgba(224, 96, 60, 0.4); } to { box-shadow: 0 0 18px rgba(224, 96, 60, 0.8); } }
.link-btn {
  background: none; border: none; color: var(--gold-bright);
  text-decoration: underline; cursor: pointer; font: inherit;
}

/* ---------- panels ---------- */
.panel {
  background:
    linear-gradient(180deg, rgba(58, 36, 23, 0.97), rgba(30, 18, 11, 0.97));
  border: 1px solid rgba(217, 164, 65, 0.4);
  border-radius: 10px;
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 210, 130, 0.15);
  padding: 28px 32px;
  max-width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow-y: auto;
}
.panel h2 {
  color: var(--gold-bright);
  font-size: 26px;
  margin-bottom: 14px;
  letter-spacing: 0.03em;
}
.panel p { line-height: 1.6; margin-bottom: 12px; color: var(--cream); font-size: 15px; }
.panel em { color: var(--gold-bright); }

/* ---------- setup ---------- */
.setup-panel { width: min(620px, calc(100vw - 32px)); }
.setup-section { margin-bottom: 22px; }
.setup-label {
  font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--cream-dim); margin-bottom: 10px;
}
.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice {
  text-align: left;
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid rgba(240, 223, 192, 0.18);
  background: rgba(20, 12, 7, 0.55);
  color: var(--cream);
  font-size: 19px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}
.choice:hover { transform: translateY(-1px); border-color: rgba(217, 164, 65, 0.5); }
.choice.picked {
  border-color: var(--gold);
  background: rgba(84, 52, 22, 0.6);
  box-shadow: 0 0 14px rgba(217, 164, 65, 0.25), inset 0 1px 0 rgba(255, 210, 130, 0.2);
}
.choice-note { font-family: 'Mulish', sans-serif; font-size: 12px; color: var(--cream-dim); }
.swatch {
  width: 100%; height: 10px; border-radius: 4px; margin-bottom: 6px;
  border: 1px solid rgba(0,0,0,0.4);
}
.swatch.narra { background: linear-gradient(90deg, #9c5c28, #d9a441); }
.swatch.kamagong { background: linear-gradient(90deg, #35251a, #d8d2c4); }
.setup-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

/* ---------- HUD ---------- */
.hud { position: fixed; inset: 0; z-index: 5; }
.hud-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  pointer-events: none;
}
.hud-top > * { pointer-events: auto; }
.hud-top-right { display: flex; gap: 8px; }
.hud-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(217, 164, 65, 0.45);
  background: rgba(30, 18, 11, 0.78);
  color: var(--cream);
  font-size: 17px;
  cursor: pointer;
  transition: background 0.15s, transform 0.12s;
  backdrop-filter: blur(2px);
}
.hud-btn:hover { background: rgba(84, 52, 22, 0.85); transform: scale(1.06); }
.hud-btn.muted-look { opacity: 0.55; }
.turn-banner {
  font-size: clamp(16px, 2.4vw, 22px);
  color: var(--cream);
  background: rgba(30, 18, 11, 0.72);
  border: 1px solid rgba(217, 164, 65, 0.35);
  padding: 8px 22px;
  border-radius: 24px;
  letter-spacing: 0.04em;
  backdrop-filter: blur(2px);
  display: flex;
  gap: 10px;
  align-items: baseline;
}
.check-text {
  color: #ff9a70;
  font-style: italic;
  animation: check-flash 0.9s ease infinite alternate;
}
@keyframes check-flash { from { opacity: 0.65; } to { opacity: 1; text-shadow: 0 0 12px rgba(255, 100, 50, 0.9); } }

.review-banner {
  position: absolute;
  top: 64px; left: 50%;
  transform: translateX(-50%);
  background: rgba(60, 30, 12, 0.88);
  border: 1px solid var(--gold);
  border-radius: 8px;
  padding: 8px 18px;
  font-size: 14px;
  z-index: 6;
}

/* ---------- side panel ---------- */
.side-panel {
  position: absolute;
  top: 68px;
  right: 12px;
  width: 264px;
  max-height: calc(100vh - 140px);
  background: var(--wood-panel);
  border: 1px solid rgba(217, 164, 65, 0.32);
  border-radius: 10px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  backdrop-filter: blur(3px);
}
.panel-handle {
  display: none;
  text-align: center;
  padding: 6px;
  cursor: pointer;
  color: var(--gold);
}
.panel-scroll { overflow-y: auto; padding: 10px 12px; }
.tray { padding: 4px 2px 8px; }
.tray-label {
  font-size: 10px; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--cream-dim); margin-bottom: 4px;
}
.tray-icons { min-height: 24px; display: flex; flex-wrap: wrap; gap: 2px; align-items: center; }
.tray-icon { width: 22px; height: 22px; display: inline-flex; }
.tray-icon svg { width: 100%; height: 100%; }
.tray-icon.light { color: #d9a441; }
.tray-icon.dark { color: #cfc8b8; }
.tray-score { color: var(--gold-bright); font-size: 13px; font-weight: 600; min-height: 16px; }

.movelist-wrap {
  max-height: 30vh;
  overflow-y: auto;
  border: 1px solid rgba(240, 223, 192, 0.12);
  border-radius: 6px;
  background: rgba(14, 8, 5, 0.5);
  margin: 6px 0;
}
#movelist { padding: 4px 0; }
.move-row { display: grid; grid-template-columns: 34px 1fr 1fr; align-items: center; }
.move-num { color: var(--cream-dim); font-size: 12px; text-align: right; padding-right: 8px; }
.move-cell {
  background: none;
  border: none;
  color: var(--cream);
  font-family: 'Mulish', sans-serif;
  font-weight: 600;
  font-size: 14px;
  text-align: left;
  padding: 5px 8px;
  cursor: pointer;
  border-radius: 4px;
}
.move-cell:hover { background: rgba(217, 164, 65, 0.18); }
.move-cell.current { background: rgba(217, 164, 65, 0.3); color: var(--gold-bright); }
.move-cell.live:not(.current) { color: var(--gold-bright); }
.replay-controls { display: flex; justify-content: center; gap: 6px; margin: 8px 0; }
.replay-controls .hud-btn { width: 34px; height: 34px; font-size: 13px; border-radius: 8px; }

.hud-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}
.controls-hint {
  margin-top: 12px;
  font-size: 11px;
  line-height: 1.6;
  color: var(--cream-dim);
  text-align: center;
  opacity: 0.85;
}
.controls-hint b { color: var(--gold-bright); }

.thinking {
  position: absolute;
  bottom: 18px;
  left: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(30, 18, 11, 0.8);
  border: 1px solid rgba(217, 164, 65, 0.4);
  border-radius: 24px;
  padding: 9px 20px;
  font-style: italic;
  font-size: 14px;
  z-index: 6;
}
.thinking-flame {
  width: 10px; height: 14px;
  border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%;
  background: radial-gradient(circle at 50% 70%, #ffd76a, #ff8a1e 70%);
  animation: flame-flicker 0.5s ease infinite alternate;
}
@keyframes flame-flicker {
  from { transform: scaleY(1) scaleX(1); opacity: 0.85; }
  to { transform: scaleY(1.25) scaleX(0.85); opacity: 1; }
}

/* ---------- promotion ---------- */
.promo-panel { text-align: center; }
.promo-text { color: var(--cream-dim); }
.promo-row { display: flex; gap: 12px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.promo-choice {
  width: 96px;
  padding: 14px 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(217, 164, 65, 0.4);
  background: rgba(20, 12, 7, 0.6);
  color: var(--gold-bright);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: transform 0.12s, box-shadow 0.15s, background 0.15s;
}
.promo-choice:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(217, 164, 65, 0.3);
  background: rgba(84, 52, 22, 0.7);
}
.promo-glyph { width: 44px; height: 44px; display: block; }
.promo-glyph svg { width: 100%; height: 100%; }
.promo-name { font-family: 'Philosopher', serif; font-size: 15px; color: var(--cream); }

/* ---------- dialogs & game over ---------- */
.dialog-panel { text-align: center; min-width: min(400px, calc(100vw - 32px)); }
.dialog-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.gameover-panel { text-align: center; min-width: min(440px, calc(100vw - 32px)); animation: rise-in 0.7s ease both; }
.gameover-crown { font-size: 40px; color: var(--gold); margin-bottom: 4px; }
.gameover-panel.narra h2 { color: var(--gold-bright); text-shadow: 0 0 18px rgba(217, 164, 65, 0.5); }
.gameover-panel.kamagong h2 { color: var(--shell); text-shadow: 0 0 18px rgba(168, 224, 208, 0.4); }
.gameover-panel.draw h2 { color: var(--cream); }
.gameover-panel h2 { font-size: 32px; }

.about-panel { width: min(600px, calc(100vw - 32px)); }
.about-close { text-align: center; margin-top: 8px; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .side-panel {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-height: 46px;
    overflow: hidden;
    border-radius: 12px 12px 0 0;
    transition: max-height 0.25s ease;
  }
  .side-panel.open { max-height: 62vh; }
  .panel-handle { display: block; }
  .movelist-wrap { max-height: 20vh; }
  .turn-banner { font-size: 14px; padding: 6px 14px; }
  .hud-btn { width: 36px; height: 36px; }
  .btn.big { min-width: 0; width: 100%; }
  .title-buttons { width: min(320px, 86vw); margin: 0 auto; }
  .choice-row { grid-template-columns: 1fr; }
  .thinking { bottom: 56px; }
}

@media (prefers-reduced-motion: reduce) {
  .title-inner, .gameover-panel { animation: none; }
  .thinking-flame, .check-text, .btn.danger.armed { animation: none; }
}
