:root {
  --bg: #080a0f;
  --hud-bg: rgba(12, 15, 22, 0.78);
  --hud-border: rgba(212, 175, 55, 0.36);
  --gold: #d4af37;
  --gold-bright: #f5d76e;
  --text: #f0ece1;
  --muted: #9aa0a6;
  --accent-blue: #4ea8de;
  --danger: #e63946;
}
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  user-select: none;
}
html, body, #root {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, serif;
  overscroll-behavior: none;
}

/* WebGL mount point — touch-action:none prevents pull-to-refresh / rubber-banding on mobile */
#canvas-container {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 1;
  touch-action: none;
  overscroll-behavior: none;
}
#canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* Floating Minimal Top HUD */
#hud-top {
  position: fixed;
  top: 16px;
  left: 20px;
  right: 20px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  gap: 12px;
  flex-wrap: wrap;
}
.hud-group {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
  flex-wrap: wrap;
}
.brand-pill {
  background: var(--hud-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--hud-border);
  padding: 8px 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
}
.brand-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}
.status-pill {
  background: var(--hud-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 8px 16px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
}
.turn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f5f3ef;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
  transition: all 0.25s ease;
}
.turn-dot.black {
  background: #2b303c;
  border: 1.5px solid var(--gold);
  box-shadow: 0 0 8px rgba(212, 175, 55, 0.5);
}
.mode-badge {
  font-size: 0.75rem;
  padding: 2px 9px;
  border-radius: 999px;
  background: rgba(212, 175, 55, 0.16);
  color: var(--gold-bright);
  border: 1px solid rgba(212, 175, 55, 0.32);
  letter-spacing: 0.04em;
}
.hud-divider {
  width: 1px;
  height: 22px;
  background: rgba(212, 175, 55, 0.28);
  margin: 0 2px;
}
.hud-btn {
  background: var(--hud-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: all 0.18s ease;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  -webkit-tap-highlight-color: transparent;
}
.hud-btn:hover {
  border-color: var(--gold);
  color: var(--gold-bright);
  transform: translateY(-1px);
}
.hud-btn.active,
.hud-btn.primary {
  background: linear-gradient(135deg, rgba(212, 175, 55, 0.28), rgba(212, 175, 55, 0.12));
  border-color: var(--gold);
  color: var(--gold-bright);
}

/* Bottom HUD */
#hud-bottom {
  position: fixed;
  bottom: 16px;
  left: 20px;
  right: 20px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  gap: 12px;
  flex-wrap: wrap;
}
.hint-pill {
  background: rgba(10, 12, 18, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(212, 175, 55, 0.22);
  padding: 7px 16px;
  border-radius: 999px;
  font-size: 0.76rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}
.hint-pill strong {
  color: var(--gold-bright);
  font-weight: 600;
}
.captured-pill {
  background: rgba(10, 12, 18, 0.72);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 12px;
}
.captured-pill:empty {
  display: none;
}

/* Cinematic UI Hidden Mode */
body.cinematic-ui-hidden #hud-top,
body.cinematic-ui-hidden #hud-bottom {
  opacity: 0 !important;
  pointer-events: none !important;
  transition: opacity 0.25s ease;
}

/* Gothic Cathedral Checkmate Proclamation Banner */
#checkmate-overlay {
  position: fixed;
  inset: 0;
  z-index: 24;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 78px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-12px) scale(0.97);
  transition: opacity 0.55s cubic-bezier(0.22, 1, 0.36, 1), transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}
#checkmate-overlay.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}
#checkmate-overlay.visible .checkmate-banner {
  pointer-events: auto;
}
.checkmate-banner {
  pointer-events: none;
  position: relative;
  min-width: 480px;
  max-width: 92vw;
  padding: 22px 44px 20px;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(212, 175, 55, 0.24), transparent 72%),
    linear-gradient(180deg, rgba(14, 17, 26, 0.94) 0%, rgba(8, 10, 16, 0.96) 100%);
  border: 1.5px solid rgba(212, 175, 55, 0.78);
  border-radius: 6px;
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.88),
    0 0 42px rgba(212, 175, 55, 0.25),
    inset 0 0 24px rgba(212, 175, 55, 0.12);
  text-align: center;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.checkmate-banner::before {
  content: '';
  position: absolute;
  inset: 5px;
  border: 1px solid rgba(212, 175, 55, 0.34);
  border-radius: 3px;
  pointer-events: none;
}
.checkmate-ornament {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 0.72rem;
  letter-spacing: 0.34em;
  text-transform: uppercase;
  color: rgba(212, 175, 55, 0.85);
  margin-bottom: 4px;
}
.checkmate-crown {
  font-size: 1.85rem;
  line-height: 1;
  color: var(--gold-bright);
  text-shadow: 0 0 18px rgba(245, 215, 110, 0.75);
  margin-bottom: 4px;
}
.checkmate-title {
  font-family: 'Cinzel', 'Georgia', 'Times New Roman', serif;
  font-size: 2.35rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  background: linear-gradient(180deg, #fff6d1 0%, #f5d76e 48%, #b8891e 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 4px 14px rgba(0, 0, 0, 0.85));
  margin: 2px 0 6px;
}
.checkmate-rule {
  width: 72%;
  height: 1px;
  margin: 8px auto 10px;
  background: linear-gradient(90deg, transparent 0%, rgba(212, 175, 55, 0.85) 50%, transparent 100%);
}
.checkmate-subtitle {
  font-family: 'Georgia', 'Times New Roman', serif;
  font-size: 0.96rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #f0ece1;
  margin-bottom: 14px;
}
.checkmate-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.checkmate-btn {
  background: rgba(212, 175, 55, 0.16);
  border: 1px solid rgba(212, 175, 55, 0.62);
  color: var(--gold-bright);
  padding: 7px 16px;
  border-radius: 4px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.18s ease;
  -webkit-tap-highlight-color: transparent;
}
.checkmate-btn:hover {
  background: rgba(212, 175, 55, 0.30);
  border-color: var(--gold-bright);
  transform: translateY(-1px);
}
.checkmate-btn.secondary {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.22);
  color: var(--muted);
}
.checkmate-btn.secondary:hover {
  color: var(--text);
  border-color: rgba(255, 255, 255, 0.45);
}

/* Initial Loading Overlay */
#loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: radial-gradient(circle at center, #111622 0%, #06080d 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.45s ease;
}
#loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}
.loader-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}
.loader-bar-wrap {
  width: 260px;
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(212, 175, 55, 0.28);
}
.loader-bar {
  height: 100%;
  width: 15%;
  background: linear-gradient(90deg, var(--gold), var(--gold-bright));
  transition: width 0.25s ease;
}
#loader-text {
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.04em;
}

/* Mobile-only elements hidden on desktop so desktop view is 100% unchanged */
.mobile-controls-trigger,
.mobile-sheet-backdrop,
.mobile-sheet-handle-wrap,
.mobile-sheet-header,
.mobile-sheet-section-label,
.mobile-sheet-hint,
.mobile-only-restore-ui {
  display: none;
}

/* Mobile Responsive View Optimization */
@media (max-width: 768px) {
  #hud-top {
    top: 12px;
    left: 12px;
    right: 12px;
    z-index: 30;
    gap: 8px;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
  }
  #hud-left {
    flex: 1 1 auto;
    min-width: 0;
    flex-wrap: nowrap;
    gap: 6px;
  }
  .brand-pill {
    padding: 7px 11px;
    flex-shrink: 0;
  }
  .brand-title {
    font-size: 0.76rem;
    letter-spacing: 0.07em;
    white-space: nowrap;
  }
  .status-pill {
    padding: 7px 11px;
    font-size: 0.76rem;
    gap: 7px;
    min-width: 0;
    flex: 0 1 auto;
  }
  #turn-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mode-badge {
    display: none;
  }
  .mobile-controls-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    flex-shrink: 0;
    min-height: 38px;
    padding: 7px 14px;
    font-size: 0.78rem;
    font-weight: 600;
    border-color: var(--hud-border);
    color: var(--gold-bright);
    white-space: nowrap;
  }
  body.cinematic-ui-hidden .mobile-only-restore-ui {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 22;
    min-height: 38px;
    padding: 7px 14px;
    border-color: var(--hud-border);
    color: var(--gold-bright);
    pointer-events: auto;
  }
  .mobile-sheet-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 28;
    background: rgba(4, 6, 11, 0.58);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.24s ease;
  }
  .mobile-sheet-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }
  #hud-right {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 29;
    background: linear-gradient(180deg, rgba(14, 18, 28, 0.96) 0%, rgba(8, 10, 16, 0.98) 100%);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-top: 1px solid rgba(212, 175, 55, 0.45);
    border-radius: 22px 22px 0 0;
    padding: 10px 16px calc(18px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.82);
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 8px;
    max-height: 82vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    pointer-events: none;
    transform: translateY(105%);
    opacity: 0;
    transition:
      transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
      opacity 0.22s ease;
  }
  #hud-right.mobile-sheet-open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  .mobile-sheet-handle-wrap {
    grid-column: span 6;
    display: flex;
    justify-content: center;
    padding: 6px 0 6px;
    cursor: pointer;
    pointer-events: auto;
  }
  .mobile-sheet-handle {
    width: 42px;
    height: 5px;
    border-radius: 999px;
    background: rgba(212, 175, 55, 0.45);
  }
  .mobile-sheet-header {
    grid-column: span 6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 8px;
    margin-bottom: 2px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    pointer-events: auto;
  }
  .mobile-sheet-title {
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gold);
  }
  .mobile-sheet-close {
    min-height: 38px;
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid rgba(212, 175, 55, 0.42);
    background: rgba(212, 175, 55, 0.14);
    color: var(--gold-bright);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: auto;
    position: relative;
    z-index: 2;
  }
  .mobile-sheet-close:hover,
  .mobile-sheet-close:active {
    border-color: var(--gold);
    color: var(--gold-bright);
  }
  .mobile-sheet-section-label {
    grid-column: span 6;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    padding: 4px 2px 2px;
  }
  .mobile-sheet-section-sub {
    font-size: 0.66rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: none;
    color: rgba(245, 215, 110, 0.78);
  }
  #hud-right .hud-divider {
    display: none;
  }
  #hud-right .hud-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 44px;
    padding: 10px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    width: 100%;
    white-space: nowrap;
  }
  #btn-side-toggle,
  #btn-ai-move,
  #btn-reset {
    grid-column: span 2;
  }
  #btn-cam-player,
  #btn-cam-top,
  #btn-cam-side,
  #btn-cam-wide {
    grid-column: span 3;
  }
  #btn-hide-ui {
    grid-column: span 6;
  }
  .mobile-sheet-hint {
    grid-column: span 6;
    display: block;
    margin-top: 2px;
    padding: 9px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(212, 175, 55, 0.18);
    font-size: 0.72rem;
    line-height: 1.45;
    color: var(--muted);
    text-align: center;
  }
  .mobile-sheet-hint strong {
    color: var(--gold-bright);
    font-weight: 600;
  }
  #hud-bottom {
    bottom: 12px;
    left: 12px;
    right: 12px;
    z-index: 8;
    justify-content: center;
  }
  #controls-hint {
    display: none;
  }
  .captured-pill {
    font-size: 0.74rem;
    padding: 6px 12px;
  }
  #checkmate-overlay {
    padding-top: 64px;
  }
  .checkmate-banner {
    min-width: 0;
    width: calc(100vw - 24px);
    max-width: 420px;
    padding: 18px 18px 16px;
  }
  .checkmate-title {
    font-size: 1.65rem;
    letter-spacing: 0.16em;
  }
  .checkmate-subtitle {
    font-size: 0.8rem;
    letter-spacing: 0.08em;
  }
  .checkmate-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
}
@media (max-width: 380px) {
  .brand-pill {
    padding: 6px 9px;
  }
  .brand-title {
    font-size: 0.7rem;
  }
  .status-pill {
    padding: 6px 9px;
    font-size: 0.72rem;
  }
  .mobile-controls-trigger {
    padding: 6px 11px;
    font-size: 0.74rem;
  }
  #btn-side-toggle {
    grid-column: span 6;
  }
  #btn-ai-move,
  #btn-reset {
    grid-column: span 3;
  }
}
