:root {
  color-scheme: dark;
  --page: #101310;
  --surface: #181d19;
  --surface-raised: #202720;
  --border: #343c34;
  --text: #f1f3ec;
  --muted: #a8b0a5;
  --accent: #c6f36b;
  --accent-dark: #263519;
  --danger: #ff8f83;
  --light-square: #d8d1bd;
  --dark-square: #697b65;
  --selected: #e7ca52;
  --target: rgba(19, 35, 20, 0.38);
  --hint: #c6f36b;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 16% 12%, rgba(198, 243, 107, 0.08), transparent 28rem),
    var(--page);
}

button, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px clamp(18px, 4vw, 64px);
  border-bottom: 1px solid var(--border);
  background: rgba(16, 19, 16, 0.88);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-weight: 800;
}

.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: 0.03em; }
.brand small { color: var(--muted); margin-top: 2px; }

.service-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.state-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e9b949;
  box-shadow: 0 0 0 5px rgba(233, 185, 73, 0.12);
}
.service-state.online .state-dot { background: var(--accent); box-shadow: 0 0 0 5px rgba(198, 243, 107, 0.12); }
.service-state.offline .state-dot { background: var(--danger); box-shadow: 0 0 0 5px rgba(255, 143, 131, 0.12); }

.workspace {
  width: min(1240px, calc(100% - 36px));
  margin: clamp(24px, 4vw, 56px) auto;
  display: grid;
  grid-template-columns: clamp(520px, calc(100dvh - 220px), 760px) minmax(310px, 420px);
  justify-content: center;
  gap: clamp(20px, 3vw, 40px);
  align-items: start;
}

.board-column { min-width: 0; }

.board-shell {
  padding: clamp(8px, 1.4vw, 14px);
  border: 1px solid var(--border);
  background: #151a16;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
}

.board-stage {
  position: relative;
}

.board {
  width: 100%;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, minmax(0, 1fr));
  container-type: inline-size;
  overflow: hidden;
}

.square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  border: 0;
  padding: 0;
  color: #121512;
  line-height: 1;
}
.square.light { background: var(--light-square); }
.square.dark { background: var(--dark-square); }
.square.selected { box-shadow: inset 0 0 0 5px var(--selected); }
.square.target::after {
  content: "";
  width: 24%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--target);
  position: absolute;
}
.square.capture-target::after {
  width: 78%;
  border: 5px solid var(--target);
  background: transparent;
}
.square.hint-from, .square.hint-to { box-shadow: inset 0 0 0 5px var(--hint); }
.square:focus-visible { outline: 4px solid #fff; outline-offset: -4px; z-index: 2; }

.analysis-arrows {
  position: absolute;
  inset: 0;
  z-index: 3;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
}
.analysis-arrow {
  stroke: rgba(120, 170, 63, 0.68);
  stroke-width: 0.22;
  stroke-linecap: round;
  marker-end: url(#analysis-arrow-head);
}
#analysis-arrow-head path { fill: rgba(120, 170, 63, 0.68); }

.piece {
  font-family: "Segoe UI Symbol", "Noto Sans Symbols 2", serif;
  font-size: clamp(30px, 6vw, 70px);
  font-size: clamp(30px, 9.2cqw, 70px);
  pointer-events: none;
  transform: translateY(-2%);
  filter: drop-shadow(0 2px 1px rgba(0, 0, 0, 0.25));
  z-index: 1;
}

.coordinate {
  position: absolute;
  font: 700 11px/1 ui-monospace, monospace;
  opacity: 0.65;
  pointer-events: none;
}
.coordinate.file { right: 5px; bottom: 4px; }
.coordinate.rank { left: 5px; top: 5px; }

.timeline-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.timeline-label { margin: 0; color: var(--muted); }
.timeline-actions { display: flex; gap: 8px; }

.control-column { display: grid; gap: 16px; }
.panel {
  padding: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
}
.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.panel h1, .panel h2 { margin: 0; font-size: 22px; }

.status-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
}
.status-grid div { padding: 13px; background: var(--surface-raised); }
.status-grid span, .status-grid strong { display: block; }
.status-grid span { color: var(--muted); font-size: 12px; margin-bottom: 5px; }

.notice {
  margin: 14px 0 0;
  padding: 12px;
  border-left: 3px solid #e9b949;
  background: rgba(233, 185, 73, 0.08);
  color: #e9d8a5;
  font-size: 14px;
}

.depth-control { color: var(--muted); font-size: 13px; }
.depth-control select, .depth-control input {
  margin-left: 7px;
  padding: 6px 8px;
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--surface-raised);
}
.depth-control input { width: 76px; }

.primary-button, .secondary-button, .quiet-button, .text-button, .icon-button {
  border: 1px solid transparent;
  border-radius: 2px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}
.primary-button {
  width: 100%;
  padding: 13px 16px;
  color: #11170d;
  background: var(--accent);
  font-weight: 800;
}
.primary-button:hover { background: #d8ff8a; }
.analysis-toggle[aria-pressed="false"] {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface-raised);
}
.analysis-toggle[aria-pressed="false"]:hover { background: #293129; }
.secondary-button {
  padding: 10px 14px;
  color: var(--text);
  border-color: var(--border);
  background: var(--surface-raised);
}
.quiet-button, .text-button, .icon-button {
  padding: 7px 9px;
  color: var(--muted);
  border-color: var(--border);
  background: transparent;
}
.quiet-button:hover, .text-button:hover, .icon-button:hover { color: var(--text); border-color: #5a655b; }
.icon-button { min-width: 36px; }

.analysis-result {
  min-height: 82px;
  margin-top: 14px;
  padding: 14px;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 14px;
}
.analysis-result p { margin: 0; }
.analysis-result dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; }
.analysis-result dt { color: var(--muted); }
.analysis-result dd { margin: 0; color: var(--text); font-family: ui-monospace, monospace; overflow-wrap: anywhere; }

.fen-panel form { display: grid; gap: 10px; }
.fen-panel label { color: var(--muted); font-size: 13px; }
.fen-panel textarea {
  width: 100%;
  resize: vertical;
  padding: 11px;
  color: var(--text);
  border: 1px solid var(--border);
  background: #111511;
  font-family: ui-monospace, "Cascadia Code", monospace;
  line-height: 1.5;
}
.fen-panel textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.preview-note { margin: 0 3px; color: var(--muted); font-size: 12px; line-height: 1.6; }

.site-footer {
  width: min(1120px, calc(100% - 36px));
  margin: 0 auto;
  padding: 12px 0 28px;
  text-align: center;
  font-size: 12px;
}
.site-footer a { color: var(--muted); text-decoration: none; }
.site-footer a:hover,
.site-footer a:focus-visible { color: var(--text); text-decoration: underline; }

.promotion-dialog {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(5, 8, 5, 0.78);
  z-index: 20;
}
.promotion-dialog[hidden] { display: none; }
.promotion-card {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.55);
}
.promotion-card h2 { margin: 0 0 18px; }
.promotion-options { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 16px; }
.promotion-options button {
  padding: 14px 8px;
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--surface-raised);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(420px, calc(100% - 44px));
  padding: 13px 16px;
  border: 1px solid rgba(255, 143, 131, 0.5);
  background: #351b19;
  color: #ffd4cf;
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.38);
  z-index: 30;
}

@media (max-width: 920px) {
  .workspace { grid-template-columns: 1fr; width: min(760px, calc(100% - 24px)); }
  .board-column { width: 100%; justify-self: center; }
  .control-column { grid-template-columns: 1fr 1fr; }
  .status-panel, .preview-note { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .topbar { align-items: flex-start; }
  .service-state { max-width: 145px; text-align: right; }
  .workspace { margin-top: 18px; }
  .control-column { grid-template-columns: 1fr; }
  .status-panel, .preview-note { grid-column: auto; }
  .timeline-panel { align-items: flex-start; flex-direction: column; }
  .timeline-actions { width: 100%; }
  .text-button { margin-left: auto; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
