/*
=========================================
Pulsic v2 — spec-sheet look, matches the main site
Top bar · tool rail · playing field · status strip
=========================================
*/

:root {
  --n-100: #f2f2f2;
  --n-200: #e8ebeb;
  --n-300: #9bacae;
  --n-400: #71797a;
  --n-500: #494f52;
  --n-600: #17181a;
  --acid: #ff6b00; /* signal orange */

  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --grotesk: "Space Grotesk", "Helvetica Neue", Arial, sans-serif;

  /* dark (default) */
  --bg: #0e0f10;
  --panel: #17181a;
  --fg: var(--n-100);
  --muted: var(--n-300);
  --rule: rgba(242, 242, 242, .14);
  --grid: rgba(242, 242, 242, .05);
}
:root[data-theme="light"] {
  --bg: #f2f2f2;
  --panel: #e8ebeb;
  --fg: var(--n-600);
  --muted: var(--n-500);
  --rule: rgba(23, 24, 26, .14);
  --grid: rgba(23, 24, 26, .06);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--grotesk);
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}
.label { font-family: var(--mono); font-size: 12px; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--acid); outline-offset: 2px; }

/* Bracketed buttons */
.btn {
  display: inline-block;
  padding: 6px 8px;
  font: 500 12px/1.2 var(--mono);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--fg);
  background: none;
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  transition: background .15s linear, color .15s linear;
}
.btn::before { content: "["; margin-right: .15em; }
.btn::after { content: "]"; margin-left: .15em; }
.btn:hover, .btn:focus-visible { background: var(--acid); color: var(--n-600); }
.btn[aria-pressed="true"] { background: var(--fg); color: var(--bg); }

/* ---------- Top bar ---------- */
.top {
  display: flex; align-items: center; gap: 16px;
  min-height: 52px;
  padding: 0 clamp(12px, 2vw, 24px);
  border-bottom: 1px dashed var(--rule);
}
.logo { font: 500 15px/1 var(--grotesk); color: var(--fg); text-decoration: none; }
.title { font: 400 22px/1 var(--grotesk); letter-spacing: -.02em; text-transform: uppercase; }
.title .label { margin-right: 6px; vertical-align: 3px; }
.actions { margin-left: auto; display: flex; gap: 2px; flex-wrap: wrap; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 196px 1fr; min-height: 0; }

/* Tool rail */
.rail {
  display: flex; flex-direction: column; gap: 22px;
  padding: 18px 14px;
  border-right: 1px solid var(--rule);
  background: var(--panel);
  overflow-y: auto;
}
.rail-group .label { margin: 0 0 10px; }
.palette { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.rail-hint { margin: auto 0 0; font-size: 13px; line-height: 1.5; }
.rail.drop-target { outline: 2px dashed var(--acid); outline-offset: -6px; }

/* Tools (in the rail) and items (on the field) share the same look */
.tool, .item {
  font: 500 12px/1 var(--mono);
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: grab;
  touch-action: none;
}
.tool { height: 64px; border: 1px solid var(--rule); background: var(--bg); color: var(--fg); transition: border-color .15s linear, background .15s linear; }
.tool:hover, .tool:focus-visible { border-color: var(--acid); }
.tool.src { display: grid; place-items: center; position: relative; background: var(--tone); color: var(--n-600); border-color: transparent; }
.tool.src::before, .item.src::before {
  content: ""; position: absolute; left: 6px; top: 6px; width: 6px; height: 6px; background: var(--acid);
}
.tool.note { font-size: 15px; }

/* ---------- Playing field ---------- */
.field {
  position: relative;
  min-width: 0; min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(var(--grid) 1px, transparent 1px) 0 0 / 48px 48px,
    linear-gradient(90deg, var(--grid) 1px, transparent 1px) 0 0 / 48px 48px,
    var(--bg);
}
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.field-empty {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  text-align: center; pointer-events: none; max-width: 32ch;
  transition: opacity .3s linear;
}
.field-empty p:last-child { font-size: 20px; line-height: 1.4; margin: 8px 0 0; }
.field-empty strong { font-weight: 500; color: var(--acid); }
.field.has-items .field-empty { display: none; }

/* Items placed on the field (positioned by script, by their centre) */
.item {
  position: absolute; left: 0; top: 0;
  display: grid; place-items: center;
  transform: translate(-50%, -50%);
  z-index: 2;
}
.item.src {
  width: 64px; height: 64px;
  background: var(--tone); color: var(--n-600);
  border: 1px solid transparent;
}
.item.src.selected { outline: 2px solid var(--acid); outline-offset: 3px; }
.item.note {
  width: 44px; height: 44px;
  border: 1px solid var(--fg);
  background: var(--bg); color: var(--fg);
  font-size: 13px;
  transition: background .12s linear, color .12s linear, box-shadow .3s ease;
}
.item.note.hit { background: var(--acid); color: var(--n-600); border-color: var(--acid); box-shadow: 0 0 24px 4px rgba(255, 107, 0, .55); }
.item.dragging { cursor: grabbing; z-index: 50; opacity: .9; }

/* Ghost while dragging a new tool from the rail */
.ghost { position: fixed; z-index: 100; pointer-events: none; transform: translate(-50%, -50%); }

/* Source settings popover */
.tune {
  position: absolute; z-index: 30;
  width: 220px;
  padding: 10px 12px 12px;
  background: var(--panel);
  border: 1px solid var(--rule);
  font-family: var(--mono); font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
}
.tune-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.tune label { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; margin-top: 8px; }
.tune input[type="range"] { grid-column: 1 / -1; width: 100%; accent-color: #ff6b00; }
.tune output { color: var(--muted); }

/* ---------- Help ---------- */
.help { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; background: rgba(14, 15, 16, .7); }
.help[hidden] { display: none; }
.help-card { width: min(92vw, 460px); padding: 16px 18px 20px; background: var(--panel); border: 1px solid var(--rule); }
.help-head { display: flex; justify-content: space-between; align-items: center; padding-bottom: 10px; border-bottom: 1px dashed var(--rule); }
.help ol { margin: 14px 0 0; padding-left: 20px; line-height: 1.6; }
.help li + li { margin-top: 6px; }
.help strong { font-weight: 500; }

/* ---------- Status strip ---------- */
.strip {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 24px;
  padding: 9px clamp(12px, 2vw, 24px);
  border-top: 1px dashed var(--rule);
  color: var(--muted);
}
.dot { display: inline-block; width: 7px; height: 7px; margin-right: 6px; background: var(--n-400); vertical-align: 1px; }
.dot.on { background: var(--acid); animation: blink 1.6s steps(1) infinite; }
@keyframes blink { 50% { opacity: .3; } }

/* ---------- Small screens: rail on top ---------- */
@media (max-width: 720px) {
  .title, .hide-sm { display: none; }
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .rail { flex-direction: row; gap: 14px; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--rule); overflow-x: auto; overflow-y: hidden; }
  .rail-group { flex: none; }
  .palette { display: flex; gap: 6px; }
  .tool { width: 48px; height: 48px; flex: none; }
  .tool.src span { font-size: 9px; }
  .rail-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .dot.on { animation: none; }
  .item.note { transition: none; }
}
