:root {
  --bg: #070a12;
  --panel: #0e1322;
  --panel-2: #141a2d;
  --line: #222a43;
  --text: #e6e9f2;
  --muted: #8e97b0;
  --accent: #5fe3ff;
  --accent-2: #7b5cff;
  --warm: #ffd166;
  --danger: #ff6b6b;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s;
}
button:hover { background: #1b2340; border-color: #33406a; }
button:active { transform: translateY(1px); }
button.primary { background: linear-gradient(135deg, #2f8fff, var(--accent-2)); border-color: transparent; color: #fff; font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.active { border-color: var(--accent); color: var(--accent); background: #10203a; }
button.recording { background: #5a1020; border-color: var(--danger); color: #fff; }
button.icon { width: 34px; padding: 6px 0; }

input[type=text], input[type=number], select, textarea {
  background: #0a0f1c;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #2f6fff55; border-color: #3d5bd8; }
input[type=range] { accent-color: var(--accent); }

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0d1220, #0a0e1a);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.logo { width: 22px; height: 22px; fill: var(--accent); filter: drop-shadow(0 0 6px #5fe3ff88); }
.transport, .actions { display: flex; align-items: center; gap: 6px; }
.actions { margin-left: auto; }
#btn-play { min-width: 74px; }
.speed { display: flex; align-items: center; gap: 8px; margin-left: 8px; color: var(--muted); }
.speed input { width: 120px; }
.speed output { min-width: 52px; color: var(--text); font-variant-numeric: tabular-nums; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  height: calc(100% - 56px);
}

.stage { position: relative; overflow: hidden; background: #05070d; }
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; display: block; }
#board.panning { cursor: grab; }
#board.stamping { cursor: copy; }

.toolbar {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: #0b1020d9;
  border: 1px solid var(--line);
  border-radius: 12px;
  backdrop-filter: blur(6px);
}
.toolbar button { text-align: left; min-width: 72px; }

.hud {
  position: absolute;
  right: 12px;
  top: 12px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #0b1020c0;
  border: 1px solid var(--line);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.hud b { color: var(--text); font-weight: 600; }

.floating {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 8px;
  max-width: calc(100% - 24px);
  background: #0b1020ee;
  border: 1px solid #3a3320;
  border-radius: 12px;
  box-shadow: 0 8px 30px #0008;
}
.floating .label { color: var(--warm); padding: 0 6px; }

.toast {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 14px;
  max-width: calc(100% - 200px);
  background: #121a33f2;
  border: 1px solid #33406a;
  border-radius: 10px;
  box-shadow: 0 8px 30px #0008;
}

.card.meta { background: linear-gradient(135deg, #16204a, #1d1640); border-color: #3a3f86; }
.card.meta .rule { color: var(--warm); }
.warn-badge {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-weight: 800;
  font-size: 12px;
  vertical-align: 1px;
}
.card .warn { display: block; margin-top: 6px; color: var(--danger); font-weight: 600; font-size: 12.5px; }

.hidden { display: none !important; }

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: var(--panel);
}
.tabs { display: flex; gap: 2px; padding: 8px 8px 0; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1;
  border: 0;
  border-radius: 8px 8px 0 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 4px;
  font-size: 13px;
}
.tabs button.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--accent); }

.panel { flex: 1; min-height: 0; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; }
.hint { margin: 0; color: var(--muted); font-size: 12.5px; }

.cards { display: flex; flex-direction: column; gap: 8px; }
.card {
  display: block;
  width: 100%;
  text-align: left;
  white-space: normal;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--panel-2);
}
.card .title { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.card .rule { color: var(--accent); font-weight: 500; font-size: 12px; font-family: ui-monospace, Consolas, monospace; }
.card .desc { display: block; margin-top: 3px; color: var(--muted); font-size: 12.5px; }
.card.current { border-color: var(--accent); }

.group { margin: 4px 0 6px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.patterns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.pattern {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  text-align: left;
  white-space: normal;
  border-radius: var(--radius);
}
.pattern canvas { width: 100%; height: 64px; border-radius: 6px; display: block; }
.pattern .name { font-weight: 600; font-size: 12.5px; }
.pattern .desc { color: var(--muted); font-size: 11.5px; line-height: 1.3; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: 12.5px; display: flex; justify-content: space-between; }
.row { display: flex; gap: 6px; align-items: center; }
.row > input[type=text] { flex: 1; font-family: ui-monospace, Consolas, monospace; }
.row > input[type=number] { width: 84px; }
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row.two input, .row.two select { width: 100%; }
.row.wrap { flex-wrap: wrap; }
.times { color: var(--muted); }
.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { padding: 3px 9px; font-size: 12px; }

.digits { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.digits button { padding: 6px 0; font-variant-numeric: tabular-nums; font-weight: 600; }
.digits button.on { background: #12325a; border-color: var(--accent); color: var(--accent); }
.digits button[disabled] { opacity: .25; cursor: default; }

textarea { min-height: 150px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }

.stats { border-top: 1px solid var(--line); padding: 10px 12px 12px; background: #0b1020; }
.numbers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; margin-bottom: 8px; }
.numbers div { display: flex; flex-direction: column; }
.numbers span { color: var(--muted); font-size: 11.5px; }
.numbers b { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 14px; }
#chart { width: 100%; height: 72px; display: block; border-radius: 8px; background: #070b16; }

dialog {
  max-width: 560px;
  width: calc(100% - 32px);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  padding: 20px 22px;
}
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 8px; }
dialog h3 { margin: 16px 0 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.keys { width: 100%; border-collapse: collapse; }
.keys td { padding: 4px 0; vertical-align: top; }
.keys td:first-child { width: 46%; }
kbd { background: #1a2140; border: 1px solid #2c3660; border-bottom-width: 2px; border-radius: 5px; padding: 0 6px; font-size: 12px; }
.small { color: var(--muted); font-size: 12px; }
dialog form { margin-top: 14px; text-align: right; }

@media (max-width: 1100px) {
  .speed span { display: none; }
  .speed input { width: 90px; }
}

@media (max-width: 820px) {
  html, body { height: auto; }
  .topbar { height: auto; flex-wrap: wrap; padding: 8px 12px; gap: 8px; }
  .transport { order: 3; width: 100%; flex-wrap: wrap; }
  .speed { margin-left: 0; flex: 1; }
  .speed input { flex: 1; width: auto; }
  .layout { display: block; height: auto; }
  .stage { height: 62vh; min-height: 320px; }
  .toolbar { flex-direction: row; flex-wrap: wrap; top: 8px; left: 8px; right: 8px; }
  .toolbar button { min-width: 0; flex: 1; padding: 6px 4px; text-align: center; }
  .hud { top: auto; bottom: 8px; right: 8px; }
  .toast { max-width: calc(100% - 24px); top: 60px; }
  .sidebar { border-left: 0; border-top: 1px solid var(--line); }
  .panel { max-height: none; overflow: visible; }
}
