:root {
  --bg: #0e0e16;
  --bg-2: #16162400;
  --surface: #191926;
  --surface-2: #20202f;
  --border: #2c2c3e;
  --text: #ececf5;
  --muted: #9a9ab2;
  --accent: #3dc7ff;
  --danger: #ff5d73;
  --radius: 16px;
  --radius-sm: 10px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f3f8;
    --surface: #ffffff;
    --surface-2: #f0f0f6;
    --border: #d8d8e4;
    --text: #14141f;
    --muted: #6a6a82;
    --accent: #0b8fcc;
    color-scheme: light;
  }
}
html[data-theme="dark"] {
  --bg: #0e0e16; --surface: #191926; --surface-2: #20202f;
  --border: #2c2c3e; --text: #ececf5; --muted: #9a9ab2;
  --accent: #3dc7ff; color-scheme: dark;
}
html[data-theme="light"] {
  --bg: #f3f3f8; --surface: #ffffff; --surface-2: #f0f0f6;
  --border: #d8d8e4; --text: #14141f; --muted: #6a6a82;
  --accent: #0b8fcc; color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(120% 120% at 0% 0%, #1a1a2e 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
@media (prefers-color-scheme: light) {
  body { background: radial-gradient(120% 120% at 0% 0%, #ffffff 0%, var(--bg) 55%); }
}

.app {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 60px -24px rgba(0,0,0,.6), 0 2px 6px rgba(0,0,0,.2);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  font-size: 26px;
  line-height: 1;
  color: var(--accent);
  filter: drop-shadow(0 2px 6px rgba(61,199,255,.35));
}
.topbar h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.stats { display: flex; gap: 6px; flex-shrink: 0; }
.chip {
  font-size: 11px; font-weight: 600;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}

.stage {
  padding: 18px;
  display: flex;
  justify-content: center;
}
.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 360px;
  aspect-ratio: 1 / 1;
}
.grid {
  --n: 16;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
}
.cell {
  background: var(--surface-2);
  transition: background-color 60ms linear;
}
.cell.filled { box-shadow: inset 0 0 0 0 transparent; }
.grid:active .cell { transition: none; }

.hint {
  position: absolute;
  bottom: 8px; left: 50%;
  transform: translateX(-50%);
  font-size: 11px;
  color: var(--muted);
  background: var(--surface);
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  pointer-events: none;
  opacity: .9;
  transition: opacity .3s;
}
.canvas-wrap.touched .hint { opacity: 0; }

.dock {
  padding: 14px 18px 18px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.palette {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 7px;
  margin-bottom: 12px;
}
.swatch {
  aspect-ratio: 1;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  padding: 0;
  transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease;
  position: relative;
}
.swatch:hover { transform: translateY(-2px); }
.swatch:active { transform: translateY(0); }
.swatch.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3px var(--accent);
}

.tools { display: flex; gap: 8px; }
.tool {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 8px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .08s;
}
.tool:hover { background: var(--surface-2); }
.tool:active { transform: translateY(1px); }
.tool.active {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.tool.danger { color: var(--danger); }
.tool.danger:hover { border-color: var(--danger); }
.tool:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hashnote {
  margin: 12px 0 0;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 360px) {
  .topbar { flex-wrap: wrap; }
  .palette { grid-template-columns: repeat(8, 1fr); gap: 5px; }
  .tool { font-size: 12px; padding: 9px 6px; }
}
