/* Sapling web UI styles. */

:root {
  --canvas: #0b0b0f;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --primaryText: #f2f2f7;
  --secondaryText: #98989f;
  --tertiaryText: #6c6c74;
  --accent: #0a84ff;
  --accentText: #409cff;
  --accentSoft: rgba(10, 132, 255, 0.16);
  --separator: #38383a;
  --strongSeparator: #48484a;
  --success: #30d158;
  --danger: #ff453a;
  --warningSurface: rgba(255, 69, 58, 0.16);
  --infoSurface: rgba(10, 132, 255, 0.16);

  --sq-light: #f0d9b5;
  --sq-dark: #b58863;
  --board-border: #333333;
  --sel: #ffff00;
  --last-from: rgba(10, 132, 255, 0.24);
  --last-to: rgba(48, 209, 88, 0.3);
  --check: rgba(255, 69, 58, 0.5);

  --radius-panel: 20px;
  --radius-control: 12px;
  --radius-capsule: 999px;
  --space-screen: 20px;
  --space-panel: 16px;
  --space-section: 24px;
  --space-related: 10px;
  --touch: 44px;
}

html:not(.dark) {
  --canvas: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f2f2f7;
  --primaryText: #1c1c1e;
  --secondaryText: #63636b;
  --tertiaryText: #74747c;
  --accent: #0066d6;
  --accentText: #005bc4;
  --accentSoft: #e8f1ff;
  --separator: #e5e5ea;
  --strongSeparator: #c7c7cc;
  --success: #248a3d;
  --danger: #c9342d;
  --warningSurface: #ffebe9;
  --infoSurface: #e8f1ff;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--canvas);
  color: var(--primaryText);
  font-family: system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    max(0px, env(safe-area-inset-top))
    max(var(--space-screen), env(safe-area-inset-right))
    max(0px, env(safe-area-inset-bottom))
    max(var(--space-screen), env(safe-area-inset-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 0 var(--space-section);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 22px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.logo { width: 28px; height: 28px; border-radius: 6px; display: block; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.github {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--primaryText);
  font-weight: 600;
  font-size: 15px;
  text-decoration: none;
}
.github:hover { background: var(--strongSeparator); }
.github:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--secondaryText);
  box-sizing: border-box;
  width: min(100%, 560px);
  height: 28px;
  margin: 8px auto 0;
  overflow: hidden;
  white-space: nowrap;
}
.status #status-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--tertiaryText); flex: none; }
.status[data-state="thinking"] .dot,
.status[data-state="yourmove"] .dot { background: var(--accent); }
.status[data-state="check"] .dot,
.status[data-state="error"] .dot { background: var(--danger); }
.status[data-state="over"] .dot,
.status[data-state="copied"] .dot { background: var(--success); }
.status[data-state="thinking"] .dot { animation: pulse 1.1s ease-in-out infinite; }
.status[data-state="thinking"] #status-text::after {
  content: '';
  display: inline-block;
  width: 1.25em;
  animation: thinking-dots 1.2s steps(1, end) infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes thinking-dots {
  0%, 100% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}
@media (prefers-reduced-motion: reduce) {
  .status[data-state="thinking"] .dot { animation: none; }
  .status[data-state="thinking"] #status-text::after { content: '...'; animation: none; }
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-section);
  max-width: 1080px;
  margin: 0 auto;
  width: 100%;
  flex: 1 0 auto;
}
.board-area { position: relative; width: 100%; }

.board {
  position: relative;
  width: min(100%, 560px);
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 0.2rem solid var(--board-border);
  border-radius: var(--radius-panel);
  overflow: hidden;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.sq {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: var(--sq-dark);
  cursor: pointer;
}
.sq.light { background: var(--sq-light); }
.sq:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.sq.selected, .sq.valid { box-shadow: inset 0 0 0 3px var(--sel); }
.hint-score {
  position: absolute; top: 2px; right: 2px; z-index: 3;
  max-width: 92%; overflow: hidden; white-space: nowrap; text-overflow: clip;
  padding: 1px 3px; border-radius: 4px;
  background: rgba(0, 0, 0, 0.78); color: #fff;
  font-size: clamp(7px, 1.7vw, 10px); font-weight: 700; line-height: 1.2;
  pointer-events: none;
}
.sq.last::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 0;
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.85);
}
.sq.valid::after, .sq.selected::after { outline: 3px solid var(--sel); outline-offset: -6px; }
.sq.last-from::after { background: var(--last-from); }
.sq.last-to::after { background: var(--last-to); }
.move-path { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 1; }
.move-path line {
  stroke: rgba(70, 70, 70, 0.72);
  stroke-width: 4;
  stroke-dasharray: 12 9;
  stroke-linecap: butt;
}
.move-path polyline { fill: none; stroke: rgba(70, 70, 70, 0.72); stroke-width: 4; stroke-dasharray: 12 9; stroke-linecap: butt; }
.sq.check::before {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at center, var(--check), transparent 70%);
  pointer-events: none;
}
.piece {
  position: absolute;
  width: 80%; height: 80%; top: 10%; left: 10%;
  z-index: 2;
  pointer-events: none;
}
.sq.animating .piece { visibility: hidden; }
.move-animation {
  position: absolute;
  z-index: 4;
  object-fit: contain;
  pointer-events: none;
  will-change: transform;
}
.coord { position: absolute; font-size: 10px; color: var(--tertiaryText); pointer-events: none; }
.coord.file { right: 3px; bottom: 2px; }
.coord.rank { left: 3px; top: 2px; }

.promotion {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; gap: 8px; padding: 12px;
  background: var(--surface);
  border-radius: var(--radius-panel);
  z-index: 5;
}
.promotion[hidden] { display: none; }
.promotion button {
  width: var(--touch); height: var(--touch);
  background: var(--surface-2); border: 0; border-radius: var(--radius-control);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.promotion .piece { position: static; width: 30px; height: 30px; top: auto; left: auto; }

.panel { display: flex; flex-direction: column; gap: var(--space-section); }
.group { background: var(--surface); border-radius: var(--radius-panel); padding: var(--space-panel); }
.section-label { font-size: 12px; font-weight: 600; color: var(--tertiaryText); margin: 0 0 var(--space-related); }

.row { display: flex; flex-wrap: wrap; gap: var(--space-related); align-items: center; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--secondaryText); }
.field > span em { font-style: normal; color: var(--accentText); font-weight: 600; }

.slider { width: 100%; height: 22px; accent-color: var(--accent); cursor: pointer; }
.slider-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--secondaryText); }

.btn {
  min-height: var(--touch);
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--surface-2);
  color: var(--primaryText);
  font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn.primary { background: var(--accent); color: #ffffff; }
.btn.secondary { background: var(--accentSoft); color: var(--accentText); }
.btn[aria-pressed="true"] { background: var(--accentSoft); color: var(--accentText); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.segmented {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface-2);
  border-radius: var(--radius-capsule);
  flex-wrap: wrap;
}
.pill {
  min-height: var(--touch);
  padding: 0 16px;
  border: 0;
  border-radius: var(--radius-capsule);
  background: transparent;
  color: var(--secondaryText);
  font: inherit; font-weight: 600; font-size: 15px;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}
.pill.selected { background: var(--accentSoft); color: var(--accentText); }
.pill:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.moves { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; font-variant-numeric: tabular-nums; }
.moves li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--separator); font-size: 15px; }
.moves li:last-child { border-bottom: 0; }
.moves li .no { color: var(--tertiaryText); width: 2.4em; }
.moves li .san { flex: 1; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 16px; margin: 0; }
.stats > div { display: flex; justify-content: space-between; gap: 8px; }
.stats dt { color: var(--secondaryText); font-size: 13px; }
.stats dd { margin: 0; font-variant-numeric: tabular-nums; }
.pv { margin-top: 12px; }
.pv summary { cursor: pointer; color: var(--secondaryText); font-size: 13px; }
.pv-text { display: block; margin-top: 6px; font-size: 14px; word-break: break-word; color: var(--primaryText); }

.footer {
  padding: 16px 0 24px;
  color: var(--tertiaryText);
  font-size: 13px;
  text-align: center;
  display: flex;
  gap: 6px;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.foot-link { color: var(--accentText); text-decoration: none; font-weight: 600; }
.foot-link:hover { text-decoration: underline; }
.foot-link:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

@media (min-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
