/**
 * vim: et:ts=4:sw=4:sts=4
 *
 * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later)
 * Copyright 2023-2026 Josh Y Oshiro
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 *
 */

:root {
  color-scheme: dark;
  --font-ui: "IBM Plex Sans", "Segoe UI", sans-serif;
  --font-display: "Space Grotesk", "Segoe UI", sans-serif;
  --color-bg: #091018;
  --color-text: #edf3f7;
  --color-muted: #aab9c7;
  --color-accent: #d8a640;
  --color-accent-soft: rgba(216, 166, 64, 0.18);
  --surface-glass: rgba(14, 21, 29, 0.82);
  --surface-nav: rgba(19, 28, 38, 0.9);
  --surface-soft: rgba(255, 255, 255, 0.045);
  --surface-overlay: rgba(7, 12, 17, 0.72);
  --border-subtle: rgba(92, 114, 134, 0.55);
  --border-warm: rgba(216, 166, 64, 0.28);
  --border-warm-strong: rgba(216, 166, 64, 0.48);
  --shadow-soft: 0 16px 36px rgba(0, 0, 0, 0.28);
  --shadow-strong: 0 28px 80px rgba(0, 0, 0, 0.42);
  --app-max: 1440px;
  --sheet-peek: 84px;
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  min-height: 100vh;
  margin: 0;
  padding: 14px;
  padding-bottom: calc(var(--sheet-peek) + 26px);
  color: var(--color-text);
  font-family: var(--font-ui);
  background:
    radial-gradient(circle at top center, rgba(216, 166, 64, 0.12), transparent 26%),
    radial-gradient(circle at bottom left, rgba(52, 90, 140, 0.18), transparent 24%),
    linear-gradient(180deg, #081018 0%, #0b1218 48%, #0f151a 100%);
  text-rendering: optimizeSpeed;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(180deg, rgba(7, 12, 17, 0.2), rgba(7, 12, 17, 0.88)),
    url("https://hccc.club/graphics/hccc_bg2.png") center/cover no-repeat;
  opacity: 0.82;
  pointer-events: none;
}

h1, h2, h3, h4, strong {
  font-family: var(--font-display);
}

button,
select,
input,
textarea {
  font: inherit;
}

button,
select {
  appearance: none;
  min-height: 44px;
  border: 1px solid var(--border-warm);
  border-radius: 4px;
  color: var(--color-text);
  background: var(--surface-nav);
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.02em;
  transition: background-color 160ms ease, border-color 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

button:hover,
select:hover {
  background: rgba(31, 42, 55, 0.96);
  border-color: var(--border-warm-strong);
  box-shadow: 0 0 0 1px rgba(216, 166, 64, 0.12), 0 10px 24px rgba(0, 0, 0, 0.18);
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(216, 166, 64, 0.58);
  outline-offset: 2px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.06);
  padding: 9px 10px;
}

canvas {
  display: block;
  cursor: crosshair;
  border-radius: 8px;
  outline: none;
}

canvas:focus {
  box-shadow: 0 0 0 3px rgba(216, 166, 64, 0.35);
}

.panel,
.status-pill,
.glass-bar {
  background: var(--surface-glass);
  border: 1px solid var(--border-warm);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.panel {
  border-radius: 4px;
  padding: 14px;
}

.glass-bar {
  border-radius: 4px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: center;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

#app-shell {
  width: min(var(--app-max), 100%);
  margin: 0 auto;
  display: grid;
  gap: 10px;
}

#top-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 6px;
  background: rgba(22, 28, 36, 0.88);
  border-color: rgba(216, 166, 64, 0.16);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

#top-bar-center {
  min-width: 0;
}

#top-bar-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1rem;
}

#top-bar-subtitle {
  color: var(--color-muted);
  font-size: 0.82rem;
}

#top-bar-status {
  display: flex;
  justify-content: flex-end;
}

#top-status-pill {
  min-width: 0;
}

.icon-btn {
  width: 48px;
  padding: 0;
  font-size: 1.3rem;
}

.status-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(216, 166, 64, 0.18);
  font-size: 0.82rem;
  white-space: nowrap;
}

#landscape-frame {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.edge-rail {
  display: none;
  flex-direction: column;
  gap: 8px;
}

.rail-btn {
  min-width: 72px;
}

#board-stage {
  display: grid;
  gap: 12px;
  justify-items: center;
}

#player-strip {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) minmax(0, 1.4fr) minmax(96px, 1fr);
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  width: min(820px, 100%);
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(34, 39, 48, 0.94), rgba(29, 35, 43, 0.96));
  border-color: rgba(216, 166, 64, 0.14);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

#player-hero {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-width: 0;
  grid-template-rows: 34px 28px 20px 6px;
  align-items: center;
  overflow: hidden;
}

.player-strip-center {
  text-align: center;
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.03em;
  font-size: 1.1rem;
}

#player-strip-meta {
  display: grid;
  grid-template-columns: minmax(7ch, 9ch) minmax(14ch, 22ch) minmax(12ch, 32ch);
  gap: 8px;
  justify-content: center;
  width: 100%;
  align-items: center;
  min-height: 20px;
  max-height: 20px;
  overflow: hidden;
}

#nn-load-progress {
  width: min(220px, 100%);
  height: 4px;
  min-height: 4px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(224, 211, 190, 0.12);
  border: 1px solid rgba(216, 166, 64, 0.14);
  visibility: hidden;
  opacity: 0;
  transition: opacity 120ms ease;
}

#nn-load-progress.is-visible {
  visibility: visible;
  opacity: 1;
}

.mini-loadbar-fill {
  display: block;
  width: 38%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, rgba(216, 166, 64, 0.26), rgba(216, 166, 64, 0.94), rgba(242, 230, 207, 0.78));
  animation: nn-loadbar-slide 1.05s ease-in-out infinite;
  transform: translateX(-120%);
  will-change: transform;
}

.player-slot {
  display: grid;
  justify-items: center;
  gap: 2px;
  padding: 6px 0;
}

.player-slot-label {
  color: rgba(224, 211, 190, 0.74);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.player-slot-time {
  color: #f2e6cf;
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
}

.inline-meta {
  display: block;
  color: rgba(224, 211, 190, 0.9);
  font-size: 0.78rem;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 20px;
  text-align: center;
}

#engine-state {
  width: 100%;
  min-width: 0;
  max-width: 100%;
}

#engine-move-status {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#nn-inline-state {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

@keyframes nn-loadbar-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

#board-container {
  min-height: 0;
  display: flex;
  justify-content: center;
  width: 100%;
}

#board-shell {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 14px;
}

#prep-area {
  position: relative;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow-strong);
  border: 1px solid rgba(216, 166, 64, 0.14);
}

#eval-wrap {
  width: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#eval-score {
  min-width: 48px;
  text-align: center;
  font-size: 0.84rem;
  color: #d7dde5;
  font-variant-numeric: tabular-nums;
}

#eval-bar {
  position: relative;
  width: 22px;
  height: 640px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 4px;
  overflow: hidden;
  background: #11161c;
  box-shadow: var(--shadow-soft);
}

#eval-black,
#eval-white {
  position: absolute;
  left: 0;
  width: 100%;
  transition: height 160ms ease, width 160ms ease;
}

#eval-black {
  top: 0;
  background: #101316;
}

#eval-white {
  bottom: 0;
  background: #f2eee8;
}

#eval-marker {
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  background: #d8a640;
  transform: translateY(-1px);
  transition: top 160ms ease;
}

#quick-menu[hidden] {
  display: none !important;
}

#quick-menu {
  position: fixed;
  inset: 0;
  z-index: 80;
}

#quick-menu-scrim {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 12, 0.56);
  backdrop-filter: blur(4px);
}

#quick-menu-panel {
  position: absolute;
  top: 14px;
  left: 14px;
  right: auto;
  width: min(360px, calc(100vw - 28px));
  display: grid;
  gap: 12px;
  border-radius: 6px;
  background: rgba(16, 22, 29, 0.96);
  border-color: rgba(216, 166, 64, 0.18);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.32);
}

body[data-quick-menu-side="right"] #quick-menu-panel {
  left: auto;
  right: 14px;
}

#quick-menu-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#quick-menu-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.quick-menu-btn {
  min-height: 42px;
  font-size: 0.84rem;
}

.status-pill {
  min-height: 50px;
  border-radius: 6px;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: center;
}

.status-pill span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

#panel-surface {
  position: fixed;
  inset: auto 10px 10px 10px;
  z-index: 20;
  display: none;
}

body[data-panels-open="true"] #panel-surface {
  display: block;
}

.panel-surface-shell {
  background: transparent;
}

#bottom-sheet {
  border: 1px solid var(--border-warm);
  border-radius: 8px;
  background: rgba(11, 17, 24, 0.94);
  box-shadow: var(--shadow-strong);
  overflow: hidden;
  max-height: min(72vh, 640px);
  transform: translateY(calc(100% - var(--sheet-peek)));
  transition: transform 220ms ease;
}

body[data-sheet-state="half"] #bottom-sheet,
body[data-sheet-state="full"] #bottom-sheet {
  transform: translateY(0);
}

#sheet-header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 0;
}

#sheet-handle {
  width: 72px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.24);
}

.sheet-utility-btn {
  min-height: 36px;
  padding: 8px 10px;
  font-size: 0.8rem;
}

#sheet-panel-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 12px;
}

.icon-grid {
  gap: 10px;
}

.panel-launch-btn {
  min-height: 54px;
}

#panel-surface-body {
  display: grid;
  gap: 12px;
  padding: 0 12px 12px;
  max-height: calc(min(72vh, 640px) - 122px);
  overflow: auto;
}

.panel-column {
  display: contents;
}

.panel-card {
  display: none;
  gap: 12px;
}

body[data-sheet-state="full"] .panel-card.is-panel-active,
body[data-sheet-state="half"] .panel-card.is-panel-active {
  display: grid;
}

.panel-card-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.panel-card-note {
  color: var(--color-muted);
  font-size: 0.84rem;
}

.control-group-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.settings-stack,
.library-stack {
  display: grid;
  gap: 10px;
}

.settings-stack label {
  display: grid;
  gap: 6px;
}

.toggle-row {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.toggle-row input {
  width: auto;
}

.settings-actions {
  margin-top: 2px;
}

#secondary-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tab-btn[aria-selected="true"],
.panel-launch-btn.is-active,
.rail-btn.is-active {
  background: rgba(44, 58, 74, 0.96);
  border-color: var(--border-warm-strong);
  box-shadow: inset 0 0 0 1px rgba(216, 166, 64, 0.08);
}

#meta-panels {
  display: grid;
  gap: 10px;
}

.secondary-panel[hidden] {
  display: none !important;
}

.meta-line {
  color: #d5dde6;
  font-size: 0.9rem;
  word-break: break-word;
}

.meta-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow: auto;
}

.recent-item,
.mini-button {
  font-size: 0.88rem;
}

.mini-button {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
  white-space: normal;
  text-transform: none;
  font-weight: 600;
}

.proxy-list {
  min-height: 44px;
}

#captured-white,
#captured-black {
  min-height: 1.2em;
  font-size: 1.05rem;
}

#eval-history {
  width: 100%;
  height: auto;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  background: rgba(10, 14, 18, 0.92);
}

#restore-banner,
#game-over {
  position: fixed;
  inset: auto 18px 18px 18px;
  z-index: 40;
}

#restore-banner .panel,
#game-over .panel {
  background: rgba(11, 17, 24, 0.96);
}

#game-over {
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 11, 16, 0.62);
}

#game-over[hidden],
#restore-banner[hidden] {
  display: none !important;
}

.overlay-card {
  min-width: 280px;
  text-align: center;
}

@media (max-width: 788px) {
  body {
    padding: 10px;
    padding-bottom: 10px;
  }

  #top-bar {
    grid-template-columns: auto 1fr auto;
    padding: 8px 10px;
  }

  .icon-btn {
    width: 38px;
    min-height: 38px;
    border-radius: 4px;
    border-color: transparent;
    background: transparent;
    box-shadow: none;
    color: #ece7da;
  }

  #board-shell {
    flex-direction: column-reverse;
    align-items: center;
    gap: 10px;
  }

  #eval-wrap {
    width: min(100%, 640px);
    padding: 0;
  }

  #eval-bar {
    width: 100%;
    height: 22px;
  }

  #eval-black,
  #eval-white {
    height: 100%;
  }

  #eval-black {
    width: 50%;
  }

  #eval-white {
    width: 50%;
    left: auto;
    right: 0;
  }

  #eval-marker {
    width: 2px;
    height: 100%;
    left: 50%;
    top: 0 !important;
    transform: translateX(-1px);
  }

  canvas {
    width: min(100vw - 20px, 640px);
    height: min(100vw - 20px, 640px);
    touch-action: none;
  }

  #player-strip {
    grid-template-columns: 76px minmax(0, 1fr) 76px;
    padding: 8px 10px;
    gap: 6px;
  }

  #side-indicator {
    min-height: 28px;
    font-size: 0.74rem;
  }

  #player-name-or-mode {
    font-size: 1rem;
  }

  #player-strip-meta {
    grid-template-columns: minmax(5ch, 7ch) minmax(10ch, 14ch) minmax(8ch, 12ch);
    gap: 4px;
  }

  .inline-meta {
    font-size: 0.7rem;
  }

  #board-container {
    background: transparent;
    padding: 0;
  }

  #prep-area {
    box-shadow: var(--shadow-soft);
  }

}

@media (min-width: 960px) {
  body[data-layout="landscape"] #landscape-frame {
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: start;
  }

  body[data-layout="landscape"] .edge-rail {
    display: flex;
    position: sticky;
    top: 12px;
  }

  body[data-layout="landscape"] #panel-surface {
    position: fixed;
    top: 84px;
    bottom: 16px;
    width: min(360px, calc(100vw - 120px));
    z-index: 25;
    pointer-events: none;
  }

  body[data-layout="landscape"][data-panel-side="left"] #panel-surface {
    left: 84px;
  }

  body[data-layout="landscape"][data-panel-side="right"] #panel-surface {
    right: 84px;
  }

  body[data-layout="landscape"] #bottom-sheet {
    height: 100%;
    border: 1px solid var(--border-warm);
    border-radius: 8px;
    background: rgba(11, 17, 24, 0.95);
    box-shadow: var(--shadow-strong);
    opacity: 0;
    transform: translateX(14px);
    transition: opacity 180ms ease, transform 180ms ease;
    pointer-events: none;
  }

  body[data-layout="landscape"][data-sheet-state="half"] #bottom-sheet,
  body[data-layout="landscape"][data-sheet-state="full"] #bottom-sheet {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
  }

  body[data-layout="landscape"] #sheet-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 12px 14px 0;
  }

  body[data-layout="landscape"] #sheet-panel-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 12px 14px;
  }

  body[data-layout="landscape"] #panel-surface-body {
    padding: 0 14px 14px;
    height: calc(100% - 118px);
    overflow: auto;
  }

  body[data-layout="landscape"] .panel-column {
    display: contents;
  }

  body[data-layout="landscape"] .panel-card {
    display: none;
  }

  body[data-layout="landscape"] .panel-card.is-panel-active {
    display: grid;
  }
}
