:root {
  --paper: #f7f4ee;
  --paper-grain: rgba(0, 0, 0, 0.025);
  --ink: #1a1a1a;
  --ink-2: #5c5955;
  --ink-3: #9a9691;
  --line: rgba(26, 26, 26, 0.12);
  --panel: rgba(255, 253, 249, 0.86);
  --panel-border: rgba(26, 26, 26, 0.1);
  --panel-shadow: 0 1px 2px rgba(26, 26, 26, 0.06), 0 12px 32px -12px rgba(26, 26, 26, 0.25);
  --accent: #1a1a1a;
  --accent-fg: #f7f4ee;
  --meter: #1a1a1a;
  --radius: 10px;
  --font: "Instrument Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13px;
  -webkit-user-select: none;
  user-select: none;
  -webkit-font-smoothing: antialiased;
}

/* Canvas fills the window. Cursor is drawn by our ring instead. */
#canvas {
  position: fixed;
  inset: 0;
  display: block;
  cursor: none;
  touch-action: none;
}

body.is-fallback #canvas { cursor: crosshair; }
body.is-fallback .cursor { display: none; }

/* Brush ring cursor */
.cursor {
  position: fixed;
  left: 0;
  top: 0;
  width: 24px;
  height: 24px;
  border: 1px solid var(--ink);
  border-radius: 50%;
  pointer-events: none;
  transform: translate(-50%, -50%);
  opacity: 0;
  transition: opacity 120ms ease;
  mix-blend-mode: multiply;
}
.cursor.is-visible { opacity: 0.55; }
.cursor.is-pressing { opacity: 0.9; }
.cursor::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 2px;
  background: var(--ink);
  border-radius: 50%;
  transform: translate(-50%, -50%);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Brand, top-left, quiet */
.brand {
  position: fixed;
  top: 18px;
  left: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-2);
  font-size: 12px;
  letter-spacing: 0.02em;
  pointer-events: none;
  transition: opacity 200ms ease;
}
.brand-mark {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink);
}
.brand-name { font-weight: 500; }

/* Hint, center, fades once the first stroke lands */
.hint {
  position: fixed;
  left: 50%;
  top: 50%;
  margin: 0;
  transform: translate(-50%, -50%);
  color: var(--ink-3);
  font-size: 15px;
  letter-spacing: 0.01em;
  pointer-events: none;
  transition: opacity 400ms ease;
}
.hint.is-hidden { opacity: 0; }

/* Toolbar */
.toolbar {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  box-shadow: var(--panel-shadow);
  -webkit-backdrop-filter: blur(14px) saturate(1.2);
  backdrop-filter: blur(14px) saturate(1.2);
  transition: opacity 180ms ease, transform 180ms ease;
  width: max-content;
  max-width: calc(100vw - 32px);
  flex-wrap: wrap;
  justify-content: center;
}
body.is-drawing .toolbar { opacity: 0.35; }
body.is-drawing .brand { opacity: 0.35; }

.group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.divider {
  width: 1px;
  height: 22px;
  background: var(--line);
}

.label {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-2);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
}
.label-max {
  font-size: 9px;
  color: var(--ink-3);
  letter-spacing: 0.06em;
  opacity: 0;
  transition: opacity 150ms ease;
}
.group-slider.is-pressure .label-max { opacity: 1; }

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(26, 26, 26, 0.04);
}
.seg {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink-2);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}
.seg[aria-checked="true"] {
  background: var(--ink);
  color: var(--accent-fg);
}

/* Swatches */
.swatches {
  display: flex;
  align-items: center;
  gap: 6px;
}
.swatch {
  position: relative;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 0;
  padding: 0;
  background: var(--c);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
  transition: transform 120ms ease;
}
.swatch:hover { transform: scale(1.12); }
.swatch.is-active::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
}
.swatch-rainbow {
  background: conic-gradient(from 90deg, hsl(0 85% 55%), hsl(60 85% 55%), hsl(120 85% 55%), hsl(180 85% 55%), hsl(240 85% 55%), hsl(300 85% 55%), hsl(360 85% 55%));
}
.swatch-custom {
  background: var(--c, #c9c5bd);
  overflow: hidden;
}
.swatch-custom::before {
  content: "+";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 14px;
  line-height: 1;
  color: var(--ink-2);
  pointer-events: none;
}
.swatch-custom.has-custom::before { display: none; }
.swatch-custom.is-active { --c: transparent; }
.swatch-custom input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.swatch-custom.has-custom {
  background: var(--c);
}

/* Sliders */
.group-slider input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 78px;
  height: 18px;
  background: transparent;
  margin: 0;
  cursor: pointer;
}
.group-slider input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: var(--line);
  border-radius: 1px;
}
.group-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--ink);
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--ink);
}
.group-slider output {
  min-width: 26px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--ink-2);
}

/* Pressure meter */
.meter {
  position: relative;
  width: 56px;
  height: 6px;
  border-radius: 3px;
  background: rgba(26, 26, 26, 0.08);
  overflow: visible;
}
.meter-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  border-radius: 3px;
  background: var(--meter);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 40ms linear;
}
.meter-tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 1px;
  background: var(--ink-3);
  left: 12%;
}

/* Buttons */
.btn {
  appearance: none;
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 11px;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, opacity 120ms ease;
}
.btn:hover { background: rgba(26, 26, 26, 0.05); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:disabled:hover { background: transparent; }
.btn-primary {
  background: var(--ink);
  color: var(--accent-fg);
  border-color: var(--ink);
}
.btn-primary:hover { background: #333; }
.btn-ghost { border-color: transparent; color: var(--ink-2); }

/* Safari gate */
.gate[hidden] { display: none; }
.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(247, 244, 238, 0.92);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  z-index: 10;
  padding: 24px;
}
.gate-card {
  max-width: 420px;
  padding: 32px 32px 24px;
  background: #fffdf9;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--panel-shadow);
}
.gate-glyph {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  margin-bottom: 20px;
  position: relative;
}
.gate-glyph::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  background: var(--ink);
}
.gate h2 {
  margin: 0 0 10px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.gate p {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-2);
}
.gate-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.gate-actions .btn { padding: 9px 14px; font-size: 13px; }
.gate-fine {
  min-height: 1em;
  margin: 14px 0 0 !important;
  font-size: 12px !important;
  color: var(--ink-3) !important;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Help */
.help-btn {
  position: fixed;
  top: 14px;
  right: 16px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink-2);
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: opacity 180ms ease, background 120ms ease;
}
.help-btn:hover { background: rgba(26, 26, 26, 0.05); }
body.is-drawing .help-btn { opacity: 0.35; }

.help[hidden] { display: none; }
.help {
  position: fixed;
  inset: 0;
  z-index: 9;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(247, 244, 238, 0.85);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  -webkit-user-select: text;
  user-select: text;
}
.help-inner {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  padding: 32px 36px 28px;
  background: #fffdf9;
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--panel-shadow);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink-2);
}
.help-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ink-3);
  font-size: 20px;
  cursor: pointer;
}
.help-close:hover { background: rgba(26, 26, 26, 0.05); color: var(--ink); }
.help h2 {
  margin: 0 0 10px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.help h3 {
  margin: 22px 0 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.help p { margin: 0 0 10px; }
.help ol, .help ul { margin: 0; padding-left: 20px; }
.help li { margin-bottom: 4px; }
.help dl { margin: 0; }
.help dt { font-weight: 600; color: var(--ink); margin-top: 10px; }
.help dd { margin: 2px 0 0; }
.help .keys { list-style: none; padding: 0; }
.help kbd {
  display: inline-block;
  min-width: 20px;
  padding: 1px 6px;
  margin-right: 4px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #fff;
  font: inherit;
  font-size: 12px;
  text-align: center;
  color: var(--ink);
}
.help-fine { margin-top: 20px !important; font-size: 12px; color: var(--ink-3); }
.help a { color: var(--ink); }
