:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --text: #eef3fb;
  --muted: #9fb0c8;
  --accent: #3d9eff;
  --accent-2: #6bc4ff;
  --danger: #ff6b6b;
  --ok: #5ee6a8;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --light-square: #e8d9b5;
  --dark-square: #9a7b4f;
  --highlight: rgba(61, 158, 255, 0.45);
  --last-move: rgba(94, 230, 168, 0.35);
  --check: rgba(255, 107, 107, 0.5);
  --radius: 14px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

[data-theme="forest"] {
  --light-square: #d4e4bc;
  --dark-square: #6b8f4e;
  --accent: #6ecf4a;
  --accent-2: #a8e67a;
}

[data-theme="ocean"] {
  --light-square: #cfe8f5;
  --dark-square: #4a7fa5;
  --accent: #4ecdc4;
  --accent-2: #8ee8e0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(61, 158, 255, 0.18), transparent),
    radial-gradient(900px 500px at 100% 0%, rgba(94, 230, 168, 0.12), transparent),
    var(--bg);
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem 1.25rem 3rem;
  padding-bottom: max(3rem, env(safe-area-inset-bottom, 0px));
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  font-size: 2.25rem;
  line-height: 1;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}

.brand h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.tagline {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.status {
  padding: 0.55rem 1rem;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  font-weight: 600;
  box-shadow: var(--shadow);
}

.status.check {
  border-color: var(--danger);
  color: #ffd0d0;
}

.status.win {
  border-color: var(--ok);
  color: #d7ffe9;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 320px;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.board-panel {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.board {
  width: min(100%, 72vmin);
  min-width: 260px;
  min-height: 260px;
  aspect-ratio: 1;
  height: auto;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: 10px;
  overflow: hidden;
  border: 3px solid var(--surface-2);
  user-select: none;
  touch-action: manipulation;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: clamp(1.6rem, 6.5vmin, 3.2rem);
  line-height: 1;
}

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

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

.square.highlight {
  box-shadow: inset 0 0 0 4px var(--highlight);
}

.square.last-move {
  background-image: linear-gradient(var(--last-move), var(--last-move));
}

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

.square .coord {
  position: absolute;
  font-size: 0.55rem;
  font-weight: 700;
  color: rgba(0, 0, 0, 0.45);
  pointer-events: none;
}

.square .coord.file {
  right: 4px;
  bottom: 2px;
}

.square .coord.rank {
  left: 4px;
  top: 2px;
}

.piece {
  width: 82%;
  height: 82%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease;
  z-index: 1;
}

.piece.dragging {
  opacity: 0.35;
}

.piece.selected {
  transform: scale(1.08);
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.35));
}

.hint-dot {
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(61, 158, 255, 0.75);
  pointer-events: none;
}

.hint-capture {
  width: 78%;
  height: 78%;
  border-radius: 50%;
  border: 4px solid rgba(61, 158, 255, 0.85);
  pointer-events: none;
}

.board-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: center;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.1s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0b1220;
}

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.65rem;
  font-size: 0.9rem;
}

.field input,
.field select {
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  padding: 0.45rem 0.55rem;
  background: #121a26;
  color: var(--text);
  font: inherit;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.35rem 0;
  font-size: 0.9rem;
  cursor: pointer;
}

.move-list {
  margin: 0;
  padding-left: 1.25rem;
  max-height: 220px;
  overflow-y: auto;
  font-size: 0.9rem;
  color: var(--muted);
}

.move-list li {
  margin: 0.2rem 0;
}

.tips p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.footer {
  margin-top: 1.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}
