:root {
  --bg: #faf6ef;
  --surface: #ffffff;
  --ink: #1e1e1e;
  --muted: #7a776e;
  --rule: #e4ddcd;
  --accent: #c8871f;
  --accent-soft: #f6ead2;
  --danger: #b23a2e;
  --danger-soft: #f7e2df;
  --success: #2e7d4f;
  --success-soft: #dcefe2;
  --square-light: #fbfaf7;
  --square-dark: #e6e0d2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16140f;
    --surface: #201d16;
    --ink: #f3ede0;
    --muted: #a89f8c;
    --rule: #3a352a;
    --accent: #e0a542;
    --accent-soft: #3a2c14;
    --danger: #e2685a;
    --danger-soft: #3a1f1b;
    --success: #6fcf97;
    --success-soft: #16321f;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--rule);
}
header h1 { font-size: 20px; margin: 0; }
#rating-box {
  font-family: ui-monospace, monospace;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 700;
}
#rating-box .label { font-size: 11px; font-weight: 500; opacity: 0.8; margin-left: 4px; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

#theme-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}
#theme-row select {
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
}

#board-wrap {
  width: min(100%, 560px);
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid var(--rule);
  padding: 12px;
}
#board { width: 100%; height: auto; display: block; }

.square { cursor: pointer; }
.square.selected { stroke: var(--accent); stroke-width: 4; }
.square.legal-hint { fill-opacity: 0.55; }
.square.hint-piece { stroke: #3a7bd5; stroke-width: 5; animation: hint-pulse 1.1s ease-in-out infinite; }
@keyframes hint-pulse {
  0%, 100% { stroke-opacity: 1; }
  50% { stroke-opacity: 0.35; }
}

#status-panel {
  width: 100%;
  text-align: center;
}
#status-line {
  font-size: 16px;
  font-weight: 600;
  min-height: 24px;
}
#status-line.correct { color: var(--success); }
#status-line.wrong { color: var(--danger); }
#puzzle-meta {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
}
#puzzle-meta a { color: var(--accent); }
#autonext-row {
  display: block;
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
#btn-row { margin-top: 10px; }
#next-btn, #hint-btn, #solution-btn {
  margin-inline: 6px;
  font-size: 15px;
  font-weight: 700;
  padding: 10px 22px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
}
#next-btn { background: var(--accent); color: #ffffff; }
#hint-btn, #solution-btn { background: var(--surface); color: var(--ink); border: 1px solid var(--rule); }
#next-btn:hover, #hint-btn:hover, #solution-btn:hover { opacity: 0.9; }
#hint-btn:disabled, #solution-btn:disabled { opacity: 0.4; cursor: default; }
