/* Steps. The controls are built like the picture: square white cells on its grid, ink text, no
   rounded corners. Labels are small white tags, like the ones on a paint sample board. */
:root {
  --ink: #0E0C24;
  --white: #FFFFFF;
  --line: rgba(14, 12, 36, 0.14);
  --muted: #4E4C66;
  --paper: #F2F0E9;
  --sans: Geist, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, Menlo, monospace;
  --dots: Doto, "Geist Mono", ui-monospace, monospace;
  --m: 48px;
  --well: 52px;
  --well-h: 52px;
  --cell: 48px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: #120F4F; color: var(--ink); font-family: var(--sans); -webkit-font-smoothing: antialiased; }
body { overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 2px solid var(--white); outline-offset: 2px; box-shadow: 0 0 0 4px var(--ink); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.stage { position: fixed; inset: 0; overflow: hidden; }
.field { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }
.ui { position: absolute; inset: 0; pointer-events: none; }
.ui > * { pointer-events: auto; position: absolute; }
.stage.bare .ui, .stage.saving .ui { display: none; }

/* Name and credit: plain text on the picture */
.brand { left: 32px; top: 24px; margin: 0; font-family: var(--dots); font-weight: 900; font-size: 30px; line-height: 1; letter-spacing: 1px; color: var(--white); text-shadow: 0 1px 12px rgba(6, 5, 20, 0.45); pointer-events: none !important; }
.credit { right: 32px; top: 30px; margin: 0; font-family: var(--mono); font-size: 12px; color: rgba(255, 255, 255, 0.9); text-shadow: 0 1px 8px rgba(6, 5, 20, 0.5); }
.credit a { color: inherit; }

/* The dock: one white bar, the tray first, then the settings, then Save */
.dock { left: 50%; bottom: 32px; transform: translateX(-50%); display: flex; align-items: stretch; background: var(--white); box-shadow: 0 0 0 1px rgba(14, 12, 36, 0.16), 0 16px 40px rgba(5, 4, 22, 0.38); }
.dock-sep { width: 1px; background: var(--line); }
.dock-item { position: relative; display: flex; }
.dock-btn { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; width: 68px; padding: 0; border: 0; background: var(--white); color: var(--ink); cursor: pointer; }
.dock-btn:hover, .dock-btn[aria-expanded="true"] { background: #EDEBF6; }
.dock-btn .lbl { font-family: var(--mono); font-size: 11px; line-height: 1; white-space: nowrap; }
.sq-glyph { display: block; background: currentColor; }
.surf-glyph { display: block; width: 18px; height: 18px; box-shadow: 0 0 0 1px var(--line); }
#wind-arrow { transition: transform 0.2s; }
.dock-save { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 0 24px; border: 0; background: var(--ink); color: var(--white); font-size: 15px; font-weight: 600; cursor: pointer; }
.dock-save:hover { background: #2A2750; }

/* Popovers above the dock: the square sizes, the surfaces */
.pop { position: absolute; left: 50%; bottom: calc(100% + 12px); transform: translateX(-50%); z-index: 3; padding: 6px; background: var(--white); box-shadow: 0 0 0 1px rgba(14, 12, 36, 0.16), 0 16px 40px rgba(5, 4, 22, 0.38); }
.cells { display: flex; gap: 0; }
.cell { position: relative; display: flex; align-items: center; justify-content: center; width: var(--cell); height: var(--cell); padding: 0; border: 0; background: var(--white); color: var(--ink); cursor: pointer; }
.cell:hover { background: #EDEBF6; }
.cell[aria-pressed="true"].size { background: var(--ink); color: var(--white); }
.size .sq { position: absolute; left: 4px; bottom: 4px; background: currentColor; }
.surf { background: transparent; }
.surf canvas { display: block; width: 100%; height: 100%; }
.surf[aria-pressed="true"] { outline: 3px solid var(--ink); outline-offset: -3px; z-index: 1; }

/* The tray, inside the dock */
.tray-wrap { position: relative; display: flex; padding: 8px 0 8px 8px; }
.wells { display: flex; }
.well { position: relative; width: var(--well); height: var(--well-h); padding: 0; border: 0; cursor: pointer; color: var(--white); }
.well.light { color: var(--ink); }
.well.pinned { box-shadow: inset 0 0 0 3px var(--white), inset 0 0 0 4px rgba(14, 12, 36, 0.25); }
.well-hex { display: none; }
.well-add { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; font-family: var(--mono); font-size: 10px; pointer-events: none; }
.well:not(.pinned):hover .well-add, .well:not(.pinned):focus-visible .well-add { display: flex; }
.well.hot::after { content: ""; position: absolute; left: 0; right: 0; bottom: -7px; height: 4px; background: var(--ink); }
.cap { width: 32px; padding: 0; border: 0; border-left: 1px dashed rgba(14, 12, 36, 0.35); margin-left: 8px; background: var(--white); color: var(--ink); cursor: ew-resize; touch-action: none; display: flex; align-items: center; justify-content: center; }
.cap:hover { background: #EDEBF6; }
.heads { position: absolute; left: 8px; top: -46px; height: 0; }
.pin { position: absolute; top: 0; width: 44px; height: 44px; padding: 0; border: 0; background: transparent; cursor: grab; touch-action: none; transform: translateY(var(--lift, 0px)); z-index: 2; }
.pin.end { cursor: pointer; }
.pin.dragging { cursor: grabbing; }
.pin::after { content: ""; position: absolute; left: 21px; top: 34px; width: 2px; height: 20px; background: var(--white); box-shadow: 0 0 0 1px rgba(14, 12, 36, 0.2); }
.pin.dragging::after { display: none; }
.pin-dot { position: absolute; left: 12px; top: 12px; width: 20px; height: 20px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 3px var(--white), 0 0 0 4px rgba(14, 12, 36, 0.35), 0 6px 14px rgba(5, 4, 22, 0.35); transition: transform 0.12s, opacity 0.12s; }
.pin:hover .pin-dot { transform: scale(1.12); }
.pin.lifting .pin-dot { opacity: 0.55; transform: scale(0.85); }
.picker { position: fixed; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }

/* Save */
.crop { position: absolute; border: 1.5px solid rgba(255, 255, 255, 0.92); box-shadow: 0 0 0 4000px rgba(6, 5, 20, 0.6); cursor: grab; touch-action: none; }
.crop:active { cursor: grabbing; }
.crop-c { position: absolute; width: 22px; height: 22px; border: 0 solid var(--white); }
.crop-c.tl { left: -4px; top: -4px; border-left-width: 4px; border-top-width: 4px; }
.crop-c.tr { right: -4px; top: -4px; border-right-width: 4px; border-top-width: 4px; }
.crop-c.bl { left: -4px; bottom: -4px; border-left-width: 4px; border-bottom-width: 4px; }
.crop-c.br { right: -4px; bottom: -4px; border-right-width: 4px; border-bottom-width: 4px; }
.crop-credit { position: absolute; font-family: var(--mono); font-weight: 500; color: rgba(255, 255, 255, 0.82); white-space: nowrap; pointer-events: none; }
.crop-band { position: absolute; left: -1.5px; right: -1.5px; top: 100%; background: var(--paper); padding: 6% 5% 0; display: flex; flex-direction: column; gap: 10%; pointer-events: none; }
.band-swatches { display: flex; gap: 2px; height: 22%; min-height: 8px; border-top: 1px solid var(--ink); padding-top: 4%; }
.band-swatches span { flex: 1; }
.band-name { font-family: var(--dots); font-weight: 900; font-size: clamp(12px, 3vw, 26px); color: var(--ink); }
.crop-hint { position: absolute; margin: 0; transform: translateX(-50%); font-family: var(--mono); font-size: 12px; color: rgba(255, 255, 255, 0.9); white-space: nowrap; pointer-events: none; }
.save-card { position: absolute; right: 40px; top: 40px; width: 360px; max-height: calc(100% - 80px); overflow: auto; padding: 22px; background: var(--white); color: var(--ink); box-shadow: 0 0 0 1px var(--line), 0 24px 60px rgba(5, 4, 22, 0.45); display: flex; flex-direction: column; gap: 16px; }
.save-card.busy .tabs, .save-card.busy .sizes, .save-card.busy .row { opacity: 0.5; pointer-events: none; }
.save-head { display: flex; align-items: center; justify-content: space-between; }
.save-head h2 { margin: 0; font-family: var(--dots); font-weight: 900; font-size: 30px; line-height: 1; }
.icon-btn { width: 44px; height: 44px; margin: -8px -8px -8px 0; border: 0; background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); box-shadow: 0 0 0 1px var(--line); }
.tabs button[hidden] { display: none; }
.tabs button { height: 44px; border: 0; background: var(--white); font-size: 15px; cursor: pointer; }
.tabs button[aria-pressed="true"] { background: var(--ink); color: var(--white); }
.sizes { display: flex; flex-direction: column; box-shadow: 0 0 0 1px var(--line); }
.sizes[hidden] { display: none; }
.sizes button { display: flex; align-items: center; gap: 14px; height: 52px; padding: 0 14px; border: 0; border-top: 1px solid var(--line); background: var(--white); text-align: left; cursor: pointer; }
.sizes button:first-child { border-top: 0; }
.sizes button[aria-pressed="true"] { background: var(--ink); color: var(--white); }
.sizes .glyph { flex: none; width: 26px; display: flex; justify-content: center; }
.sizes .glyph span { display: block; border: 1.5px solid currentColor; }
.sizes .t { display: flex; flex-direction: column; gap: 1px; }
.sizes .nm { font-size: 15px; }
.sizes .px { font-family: var(--mono); font-size: 12px; opacity: 0.75; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; }
.row[hidden] { display: none; }
.row label { display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.mono { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.seg { display: flex; box-shadow: 0 0 0 1px var(--line); }
.seg button { height: 44px; padding: 0 16px; border: 0; background: var(--white); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--white); }
.switch { -webkit-appearance: none; appearance: none; position: relative; flex-shrink: 0; width: 48px; height: 28px; margin: 0; background: #D7D5E2; cursor: pointer; }
.switch::before { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; background: var(--white); transition: transform 0.15s; }
.switch:checked { background: var(--ink); }
.switch:checked::before { transform: translateX(20px); }
.note { margin: 0; font-size: 13px; line-height: 1.5; color: var(--muted); }
.go { display: flex; align-items: center; justify-content: center; gap: 8px; height: 52px; border: 0; background: var(--ink); color: var(--white); font-size: 16px; font-weight: 600; cursor: pointer; }
.go:disabled { cursor: progress; }
.rec-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }

.toast { position: absolute; left: 50%; top: 24px; margin: 0; padding: 0 10px; height: 30px; line-height: 30px; background: var(--ink); color: var(--white); font-family: var(--mono); font-size: 12px; white-space: nowrap; transform: translateX(-50%); opacity: 0; transition: opacity 0.2s; pointer-events: none; }
.toast.show { opacity: 1; }
.fallback { position: absolute; left: 32px; top: 120px; margin: 0; color: var(--white); }

@media (max-width: 640px) {
  :root { --cell: 44px; --well-h: 48px; }
  .brand { left: 16px; top: calc(env(safe-area-inset-top) + 16px); font-size: 24px; }
  .credit { right: 16px; top: calc(env(safe-area-inset-top) + 20px); font-size: 11px; }
  .dock { left: 10px; right: 10px; bottom: calc(env(safe-area-inset-bottom) + 10px); transform: none; flex-wrap: wrap; }
  .tray-wrap { flex: 1 1 100%; padding: 6px 0 6px 6px; border-bottom: 1px solid var(--line); }
  .heads { left: 6px; }
  .cap { width: 36px; margin-left: auto; }
  .dock-sep { display: none; }
  .dock-item, .dock-btn { flex: 1; }
  .dock-btn { width: auto; height: 56px; }
  .dock-save { flex: 1.3; padding: 0 12px; }
  .pop { position: fixed; left: 10px; right: 10px; bottom: calc(env(safe-area-inset-bottom) + 136px); transform: none; display: flex; justify-content: center; }
  .save-card { left: 0; right: 0; top: auto; bottom: 0; width: auto; max-height: 72%; padding: 16px 16px max(16px, env(safe-area-inset-bottom)); gap: 12px; }
  .sizes { flex-direction: row; }
  .sizes button { flex: 1; flex-direction: column; justify-content: center; gap: 6px; height: 72px; padding: 6px 2px; border-top: 0; border-left: 1px solid var(--line); text-align: center; }
  .sizes button:first-child { border-left: 0; }
  .sizes .px { display: none; }
  .sizes .nm { font-size: 12px; }
  .save-card .note { font-size: 12px; }
  .toast { top: calc(env(safe-area-inset-top) + 60px); }
}
@media (prefers-reduced-motion: reduce) { #wind-arrow, .pin-dot, .switch::before { transition: none; } }
