:root {
  --bg: #0f172a;
  --bg2: #111827;
  --panel: rgba(15, 23, 42, .86);
  --panel-solid: #0b1220;
  --panel2: rgba(30, 41, 59, .92);
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #38bdf8;
  --accent2: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
}

* { box-sizing: border-box; }
html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 0%, rgba(56, 189, 248, .16), transparent 32%),
    radial-gradient(circle at 80% 20%, rgba(34, 197, 94, .10), transparent 30%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}
body {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}
header {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 14px 10px;
  background: rgba(11, 18, 32, .82);
  border-bottom: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(16px);
  z-index: 10;
}
.title { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.title strong { font-size: clamp(15px, 2.4vw, 18px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.title span { font-size: 12px; color: var(--muted); }
.title-variant { font-size: .75em; font-weight: 500; color: var(--muted); background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.12); border-radius: 6px; padding: 1px 6px; vertical-align: middle; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
button {
  appearance: none;
  border: 1px solid rgba(255,255,255,.12);
  background: linear-gradient(180deg, rgba(51,65,85,.95), rgba(30,41,59,.95));
  color: var(--text);
  padding: 9px 12px;
  border-radius: 12px;
  font-weight: 750;
  font-size: 13px;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255,255,255,.08) inset, 0 10px 24px rgba(0,0,0,.18);
  touch-action: manipulation;
}
button:hover { border-color: rgba(56,189,248,.60); transform: translateY(-1px); }
button:active { transform: translateY(0) scale(.98); }
button.primary { background: linear-gradient(180deg, #0891b2, #0e7490); border-color: rgba(103,232,249,.40); }
button.good { background: linear-gradient(180deg, #16a34a, #15803d); border-color: rgba(74,222,128,.35); }
button.ghost { background: rgba(255,255,255,.07); }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); user-select: none; }
input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }
main { min-height: 0; position: relative; overflow: hidden; }
canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  background:
    radial-gradient(circle at center, rgba(255,255,255,.08), transparent 42%),
    linear-gradient(135deg, #475569, #334155 55%, #1e293b);
  touch-action: none;
}
footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 8px 14px max(8px, env(safe-area-inset-bottom));
  background: rgba(11,18,32,.9);
  border-top: 1px solid rgba(255,255,255,.08);
  color: var(--muted);
  font-size: 12px;
  backdrop-filter: blur(14px);
  z-index: 10;
}
.status { color: var(--text); font-weight: 750; }
.kbd { border: 1px solid rgba(255,255,255,.16); border-bottom-color: rgba(255,255,255,.25); padding: 1px 5px; border-radius: 5px; background: rgba(255,255,255,.06); color: var(--text); }
.credits { font-size: 11px; color: rgba(156,163,175,.55); white-space: nowrap; }
.credits a { color: rgba(156,163,175,.70); text-decoration: none; }
.credits a:hover { color: var(--accent); text-decoration: underline; }
.side-panel {
  position: absolute;
  right: 12px;
  top: 12px;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100% - 24px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 22px;
  box-shadow: 0 22px 60px rgba(0,0,0,.35);
  backdrop-filter: blur(16px);
  overflow: hidden;
  z-index: 5;
  transform: translateX(0);
  opacity: 1;
  transition: transform .25s cubic-bezier(.4,0,.2,1), opacity .2s ease;
}
.panel-collapsed .side-panel {
  transform: translateX(calc(100% + 24px));
  opacity: 0;
  pointer-events: none;
}
#btnTogglePanel[aria-pressed="true"] {
  background: rgba(56,189,248,.15);
  border-color: rgba(56,189,248,.45);
  color: var(--accent);
}
#btnTogglePanel[aria-pressed="false"] {
  background: rgba(255,255,255,.07);
}
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 12px 12px 8px; border-bottom: 1px solid rgba(255,255,255,.08); }
.panel-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.panel-title strong { font-size: 14px; }
.panel-title span { color: var(--muted); font-size: 12px; line-height: 1.25; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 7px; padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,.08); }
.panel-actions button { padding: 8px 10px; font-size: 12px; border-radius: 10px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,.08); }
.stat { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.08); border-radius: 14px; padding: 8px; }
.stat b { display: block; font-size: 17px; color: var(--text); }
.stat span { font-size: 11px; color: var(--muted); }
.history-list { min-height: 80px; overflow: auto; padding: 8px 10px 12px; }
.move-row { display: grid; grid-template-columns: 36px 1fr auto; align-items: center; gap: 8px; padding: 8px; border-radius: 12px; font-size: 12px; color: var(--text); }
.move-row:nth-child(odd) { background: rgba(255,255,255,.045); }
.move-row.undone { opacity: .42; text-decoration: line-through; }
.move-row .idx { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.move-row .notation { font-weight: 800; letter-spacing: .2px; }
.move-row .meta { color: var(--muted); font-size: 11px; }
.history-empty { color: var(--muted); font-size: 12px; padding: 14px 8px; line-height: 1.4; }
.divider { color: var(--warn); font-size: 11px; font-weight: 800; padding: 9px 8px 5px; text-transform: uppercase; letter-spacing: .08em; }
.mobile-pad {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  width: min(520px, calc(100vw - 24px));
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 20px;
  background: rgba(11,18,32,.72);
  backdrop-filter: blur(16px);
  box-shadow: 0 18px 48px rgba(0,0,0,.28);
  z-index: 6;
}
.mobile-btn { padding: 12px 8px; min-height: 44px; border-radius: 14px; font-size: 13px; }

@media (max-width: 900px) {
  body { grid-template-rows: auto 1fr; }
  header { align-items: flex-start; flex-direction: column; gap: 10px; }
  .toolbar { width: 100%; justify-content: flex-start; }
  .toolbar button { flex: 1 1 auto; min-width: 76px; }
  .toolbar label { background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.08); padding: 8px 9px; border-radius: 12px; }
  .mobile-pad { display: grid; }
  #btnTogglePanel { display: none; }
  .side-panel { display: none; }
  footer { display: none; }
}

@media (max-width: 520px) {
  header { padding-left: 10px; padding-right: 10px; }
  .title span { font-size: 11px; }
  button { padding: 9px 10px; font-size: 12px; }
  .toolbar { gap: 6px; }
  .toolbar button { min-width: 68px; }
  .mobile-pad { grid-template-columns: repeat(2, 1fr); bottom: 10px; }
  .panel-title span, .panel-actions label { display: none; }
}
