@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Playfair+Display:ital,wght@0,500;0,700;1,500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0f;
  --surface: #111118;
  --surface-2: #18181f;
  --surface-hover: #1e1e28;
  --border: #252530;
  --border-light: #303040;
  --text: #ece8e1;
  --text-secondary: #9a9490;
  --text-dim: #5a5555;
  --gold: #c9a84c;
  --gold-bright: #e4c35a;
  --gold-glow: rgba(201, 168, 76, 0.12);
  --red: #d44040;
  --light-sq: #dcc8a0;
  --dark-sq: #a07850;
  --selected: #b8c840;
  --last-move-l: #ccd060;
  --last-move-d: #98a838;
  --font: 'Inter', -apple-system, system-ui, sans-serif;
  --font-serif: 'Playfair Display', Georgia, serif;
}

html { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px 60px;
  position: relative;
  overflow-x: hidden;
}

/* Ambient background glow */
body::before {
  content: '';
  position: fixed;
  top: -40%;
  left: -20%;
  width: 140%;
  height: 100%;
  background: radial-gradient(ellipse at 30% 20%, rgba(201, 168, 76, 0.04) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  bottom: -30%;
  right: -20%;
  width: 100%;
  height: 80%;
  background: radial-gradient(ellipse at 70% 80%, rgba(120, 80, 200, 0.025) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

#app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  width: 100%;
  max-width: 480px;
}

/* ── Header ── */
#header {
  text-align: center;
  padding: 8px 0 4px;
}

h1 {
  font-family: var(--font);
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1 .accent {
  font-family: var(--font-serif);
  font-style: italic;
  font-weight: 500;
  color: var(--gold);
  text-transform: lowercase;
  letter-spacing: 0;
  font-size: 22px;
}

/* ── Difficulty toggle ── */
#difficulty-bar {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin: 0 auto;
}

.diff-btn {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 9px 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.diff-btn:hover { color: var(--text-secondary); }

.diff-btn.active {
  background: var(--gold);
  color: #0a0a0f;
  border-color: var(--gold);
  box-shadow: 0 1px 8px rgba(201, 168, 76, 0.25);
}

.diff-btn.active[data-diff="ultra"] {
  background: linear-gradient(135deg, #d44040 0%, #a020a0 100%);
  color: #fff;
  box-shadow: 0 1px 12px rgba(212, 64, 64, 0.3);
}

/* ── Status ── */
#sf-status {
  font-size: 10px;
  color: var(--text-dim);
  text-align: center;
  letter-spacing: 0.03em;
}

#status-bar {
  font-size: 12px;
  color: var(--text-secondary);
  text-align: center;
  font-weight: 500;
  min-height: 16px;
  letter-spacing: 0.02em;
}

/* ── Board ── */
#board-wrap { position: relative; width: 100%; }

#board-container {
  border-radius: 6px;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 1;
  position: relative;
  box-shadow:
    0 0 0 1px var(--border),
    0 0 0 4px var(--surface),
    0 0 0 5px var(--border),
    0 12px 40px rgba(0, 0, 0, 0.6),
    0 0 100px rgba(201, 168, 76, 0.03);
}

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
}

.sq {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.sq.light { background: var(--light-sq); }
.sq.dark  { background: var(--dark-sq); }
.sq.selected  { background: var(--selected) !important; }
.sq.last-move-l { background: var(--last-move-l) !important; }
.sq.last-move-d { background: var(--last-move-d) !important; }
.sq:hover { filter: brightness(1.05); }

/* Piece images */
.piece-img {
  width: 85%;
  height: 85%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
  transition: transform 0.1s ease;
}

.sq:hover .piece-img { transform: scale(1.05); }

.sq.legal-move::after {
  content: '';
  position: absolute;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.sq.legal-capture::after {
  content: '';
  position: absolute;
  inset: 5%;
  border-radius: 50%;
  border: 4px solid rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.sq.hint-from { background: rgba(80, 160, 255, 0.3) !important; }
.sq.hint-to   { background: rgba(80, 160, 255, 0.5) !important; }

.coord-label {
  position: absolute;
  font-size: 8px;
  font-weight: 700;
  opacity: 0.5;
  pointer-events: none;
  line-height: 1;
  font-family: var(--font);
}
.coord-file { bottom: 2px; right: 3px; }
.coord-rank { top: 2px; left: 3px; }
.on-light { color: var(--dark-sq); }
.on-dark  { color: var(--light-sq); }

/* ── Result overlay ── */
#result-overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 15, 0.82);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 20;
  backdrop-filter: blur(8px);
}
#result-overlay.show { display: flex; }

#result-text {
  font-family: var(--font-serif);
  font-size: 30px;
  font-weight: 700;
  color: #fff;
  text-align: center;
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.8);
  white-space: pre-line;
  line-height: 1.3;
}

#result-btns { display: flex; gap: 10px; }

.btn-overlay {
  padding: 10px 28px;
  border-radius: 8px;
  border: none;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.btn-overlay.primary { background: var(--gold); color: #0a0a0f; }
.btn-overlay.primary:hover { background: var(--gold-bright); }
.btn-overlay.secondary { background: rgba(255,255,255,0.08); color: #ccc; border: 1px solid rgba(255,255,255,0.12); }
.btn-overlay.secondary:hover { background: rgba(255,255,255,0.14); }

/* ── Controls ── */
#controls {
  display: flex;
  gap: 6px;
  justify-content: center;
}

button.ctrl {
  font-family: var(--font);
  font-size: 11px;
  font-weight: 600;
  padding: 8px 0;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  flex: 1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
button.ctrl:hover { background: var(--surface-hover); color: var(--text); border-color: var(--border-light); }
button.ctrl:disabled { opacity: 0.25; cursor: default; }
button.ctrl.accent {
  background: var(--gold);
  color: #0a0a0f;
  border-color: var(--gold);
  font-weight: 700;
}
button.ctrl.accent:hover { background: var(--gold-bright); }

/* ── Commentary panel ── */
#commentary-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 12px 16px;
  min-height: 44px;
  display: flex;
  align-items: center;
}

#commentary-text {
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--text);
  flex: 1;
}
#commentary-text.muted { color: var(--text-dim); font-style: italic; }

.loading-dots::after { content: ''; animation: dots 1.2s steps(4, end) infinite; }
@keyframes dots {
  0%,100% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* ── Move log ── */
#move-log-wrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--surface);
  max-height: 88px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #303040 transparent;
}

#move-log {
  font-size: 11px;
  line-height: 1.9;
  font-variant-numeric: tabular-nums;
  font-family: 'SF Mono', 'Consolas', 'Courier New', monospace;
}

.move-num { color: var(--text-dim); }
.move-w   { color: var(--text-secondary); }
.move-b   { color: var(--text-dim); }

/* ── Analysis panel ── */
#analysis-wrap {
  display: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  padding: 16px 18px;
}
#analysis-wrap.show { display: block; }

#analysis-title {
  font-family: var(--font-serif);
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text);
}

#analysis-text {
  font-size: 12.5px;
  line-height: 1.7;
  white-space: pre-line;
  color: var(--text-secondary);
}
#analysis-text strong { font-weight: 600; color: var(--gold); }

/* ── Responsive ── */
@media (max-width: 400px) {
  body { padding: 16px 12px 40px; }
  #app { gap: 12px; }
  h1 { font-size: 20px; }
  .diff-btn { font-size: 11px; padding: 6px 0; }
  button.ctrl { font-size: 10px; padding: 7px 0; }
}
