﻿:root {
  --bg: #eef3f8;
  --panel: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --line: #dbe3ec;
  --accent: #1769c3;
  --accent-strong: #0f56a3;
  --danger: #c62828;

  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --check: #ef4444;
  --move-dot: rgba(23, 105, 195, 0.7);
  --selected: #ffd166;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  font-size: 14px;
  color: var(--text);
  background:
    radial-gradient(900px 480px at 0% 0%, #ffffff 0%, transparent 55%),
    linear-gradient(160deg, #ebf1f7, var(--bg));
  overflow: hidden;
}

.app {
  width: 100%;
  max-width: 1100px;
  height: 100dvh;
  margin: 0 auto;
  padding: 0.5rem;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.5rem;
}

.panel,
.side-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

.top-panel {
  padding: 0.55rem;
  position: sticky;
  top: 0;
  z-index: 5;
}

.top-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.status-row {
  display: flex;
  gap: 0.35rem;
}

.meta-pill {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  padding: 0.28rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8fafc;
  font-size: 0.82rem;
}

.meta-key {
  color: var(--muted);
}

.clock-row {
  margin-top: 0.45rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.clock-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.62rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f8fafc;
}

.clock-card.active {
  border-color: #a7c7eb;
  box-shadow: 0 0 0 2px rgba(23, 105, 195, 0.2);
}

.clock-card.low-time .clock-time {
  color: var(--danger);
}

.clock-name {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.clock-time {
  font-size: 0.96rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.game-area {
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 0.5rem;
}

.board-wrap {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board {
  width: min(96vw, calc(100dvh - 255px));
  aspect-ratio: 1 / 1;
  border-radius: 12px;
  overflow: hidden;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border: 3px solid #223143;
  box-shadow: 0 14px 28px rgba(15, 23, 42, 0.22);
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(1.45rem, 5.2vw, 2.25rem);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.square.light {
  background: var(--board-light);
}

.square.dark {
  background: var(--board-dark);
}

.square.selected {
  outline: 4px solid var(--selected);
  outline-offset: -4px;
}

.square.legal::after {
  content: "";
  position: absolute;
  width: 26%;
  height: 26%;
  border-radius: 50%;
  background: var(--move-dot);
}

.square.capture::after {
  content: "";
  position: absolute;
  inset: 9%;
  border-radius: 50%;
  border: 4px solid var(--move-dot);
}

.square.in-check {
  box-shadow: inset 0 0 0 6px var(--check);
}

.square.last-move {
  box-shadow: inset 0 0 0 3px rgba(255, 209, 102, 0.75);
}

.coord {
  position: absolute;
  font-size: 0.62rem;
  font-weight: 600;
  opacity: 0.84;
  pointer-events: none;
}

.coord.file {
  right: 5px;
  bottom: 4px;
}

.coord.rank {
  top: 4px;
  left: 5px;
}

.side-panel {
  padding: 0.55rem;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 0.5rem;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.26rem;
}

.control-group label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 600;
}

.input,
.btn {
  min-height: 44px;
  border-radius: 10px;
  font-size: 0.94rem;
}

.input {
  width: 100%;
  border: 1px solid #cfd8e3;
  background: #fff;
  color: var(--text);
  padding: 0.55rem 0.62rem;
}

.actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.btn {
  border: none;
  font-weight: 700;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  color: #fff;
}

.btn-primary,
.btn {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
}

.btn-danger {
  background: linear-gradient(180deg, #dc4f4f, var(--danger));
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn:focus-visible,
.input:focus-visible,
.square:focus-visible {
  outline: 3px solid rgba(23, 105, 195, 0.45);
  outline-offset: 2px;
}

.advantage-wrap {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #f8fafc;
  padding: 0.4rem 0.5rem;
}

.advantage-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 0.22rem;
}

.advantage-bar {
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #cfd7e2;
  background: linear-gradient(90deg, #1f2937 0%, #1f2937 50%, #f8fafc 50%, #f8fafc 100%);
}

.advantage-fill {
  height: 100%;
  width: 50%;
  background: linear-gradient(90deg, #ffffff, #f8fafc);
  transition: width 220ms ease;
}

.capture-block,
.legend,
.subtitle {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  white-space: nowrap;
  clip-path: inset(100%);
  clip: rect(0 0 0 0);
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(6, 14, 26, 0.5);
  z-index: 30;
  padding: 1rem;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(92vw, 420px);
  border-radius: 12px;
  border: 1px solid #cad7e5;
  background: #fff;
  box-shadow: 0 22px 44px rgba(15, 23, 42, 0.35);
  padding: 1rem;
}

.modal-card h2 {
  margin: 0;
  font-size: 1.2rem;
}

.modal-card p {
  margin: 0.5rem 0 0.85rem;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

@media (min-width: 901px) {
  body {
    overflow: hidden;
  }

  .app {
    padding: 0.85rem;
    gap: 0.7rem;
  }

  .top-panel {
    padding: 0.75rem;
  }

  h1 {
    font-size: 1.25rem;
  }

  .game-area {
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: 1fr;
    gap: 0.7rem;
  }

  .board {
    width: min(78vh, 72vw);
    max-width: 720px;
  }

  .side-panel {
    overflow: auto;
    align-content: start;
  }

  .capture-block {
    display: block;
  }

  .capture-block h2 {
    margin: 0 0 0.25rem;
    font-size: 0.82rem;
    color: var(--muted);
  }

  .captured-list {
    min-height: 2rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fafcff;
    padding: 0.35rem;
    font-size: 1.05rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem;
  }
}

@media (max-width: 360px) {
  .top-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .status-row {
    width: 100%;
  }

  .meta-pill {
    flex: 1;
    justify-content: center;
  }

  .board {
    width: min(96vw, calc(100dvh - 245px));
  }
}
