:root {
  --bg0: #1e1e1e; --bg1: #262626; --bg2: #2f2f2f; --bg3: #383838; --bg4: #444;
  --line: #141414; --line2: #4a4a4a;
  --fg: #e6e6e6; --fg-muted: #9a9a9a; --fg-dim: #6e6e6e;
  --accent: #31a8ff; --accent-dark: #1473e6; --danger: #e5484d; --ok: #46a758; --warn: #f5a623;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 13px/1.4 var(--font); color: var(--fg); background: var(--bg0); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
input[type=text], input[type=number], input[type=search], select, textarea {
  background: var(--bg0); border: 1px solid var(--line2); border-radius: 4px; color: var(--fg); padding: 4px 6px; min-width: 0;
}
input[type=text]:focus, input[type=number]:focus, select:focus, textarea:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
input[type=number] { width: 64px; }
input[type=range] { accent-color: var(--accent); }
input[type=color] { width: 28px; height: 22px; padding: 0; border: 1px solid var(--line2); background: none; border-radius: 4px; }
::selection { background: rgba(49, 168, 255, .35); }
.muted { color: var(--fg-muted); }
.mono { font-family: var(--mono); }
.hidden, [hidden] { display: none !important; }

/* ---------- buttons ---------- */
.btn { border: 1px solid var(--line2); background: var(--bg3); color: var(--fg); padding: 5px 10px; border-radius: 4px; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: var(--bg4); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-ghost { background: transparent; }
.btn-danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn-sm { padding: 2px 7px; font-size: 12px; }
.btn-icon { padding: 3px 6px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row > label { display: flex; gap: 4px; align-items: center; color: var(--fg-muted); white-space: nowrap; }
.grow { flex: 1; }

/* ---------- login ---------- */
.login-body { display: grid; place-items: center; background: radial-gradient(1200px 600px at 50% 0%, #0f2a45 0%, var(--bg0) 60%); }
.login-card { width: min(92vw, 420px); background: var(--bg1); border: 1px solid var(--line2); border-radius: 12px; padding: 32px 28px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.login-card h1 { margin: 12px 0 6px; font-size: 24px; }
.login-card p { margin: 0 0 18px; }
.gsi { display: flex; justify-content: center; min-height: 44px; }
.login-status { margin-top: 14px; color: var(--fg-muted); }
.login-status.error { color: var(--danger); }

/* ---------- cookie consent ---------- */
.consent { position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 10000; margin: 0 auto; max-width: 720px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 10px; padding: 14px 16px; display: flex; gap: 14px; align-items: center; box-shadow: 0 10px 40px rgba(0,0,0,.5); }
.consent p { margin: 0; flex: 1; color: var(--fg-muted); }
.consent-actions { display: flex; gap: 8px; }
@media (max-width: 640px) { .consent { flex-direction: column; align-items: stretch; } }

/* ---------- app shell ---------- */
.app-body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; user-select: none; }
#menubar { display: flex; align-items: center; height: 34px; background: var(--bg1); border-bottom: 1px solid var(--line); padding: 0 8px; gap: 4px; flex: none; }
#menus { display: flex; align-items: center; }
#menubar .brand { font-weight: 700; color: var(--accent); background: #001e36; border-radius: 4px; padding: 2px 6px; margin-right: 8px; font-size: 12px; }
.menu { position: relative; }
.menu > button { background: none; border: 0; color: var(--fg); padding: 6px 9px; border-radius: 4px; }
.menu > button:hover, .menu.open > button { background: var(--bg3); }
.menu-list { position: absolute; top: 100%; left: 0; min-width: 240px; background: var(--bg2); border: 1px solid var(--line2); border-radius: 6px; padding: 4px; z-index: 500; box-shadow: 0 12px 40px rgba(0,0,0,.6); display: none; }
.menu.open .menu-list { display: block; }
.menu-item { display: flex; justify-content: space-between; gap: 20px; padding: 5px 10px; border-radius: 4px; cursor: pointer; white-space: nowrap; }
.menu-item:hover { background: var(--accent-dark); color: #fff; }
.menu-item.disabled { opacity: .4; pointer-events: none; }
.menu-item kbd { font-family: inherit; color: var(--fg-muted); font-size: 12px; }
.menu-item:hover kbd { color: #dfefff; }
.menu-sep { height: 1px; background: var(--line2); margin: 4px 2px; }
#doc-title { color: var(--fg-muted); margin-left: auto; margin-right: 12px; font-size: 12px; }
#user { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--fg-muted); }
#user img { width: 22px; height: 22px; border-radius: 50%; }

#optionsbar { display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; background: var(--bg2); border-bottom: 1px solid var(--line); flex: none; overflow-x: auto; white-space: nowrap; }
#optionsbar label { display: inline-flex; align-items: center; gap: 4px; color: var(--fg-muted); }
#optionsbar input[type=range] { width: 100px; }
#optionsbar .tool-name { font-weight: 600; color: var(--fg); margin-right: 4px; }

#workspace { display: flex; flex: 1; min-height: 0; }
#toolbox { width: 44px; background: var(--bg1); border-right: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 6px 0; gap: 2px; flex: none; overflow-y: auto; }
#toolbox .tool { width: 34px; height: 32px; border: 0; background: none; border-radius: 4px; color: var(--fg); display: grid; place-items: center; position: relative; }
#toolbox .tool:hover { background: var(--bg3); }
#toolbox .tool.active { background: var(--bg4); color: var(--accent); }
#toolbox .tool svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#toolbox .tool .key { position: absolute; right: 3px; bottom: 1px; font-size: 8px; color: var(--fg-dim); }
#toolbox .sep { width: 26px; height: 1px; background: var(--line2); margin: 4px 0; }
#toolbox .colors { position: relative; width: 34px; height: 34px; margin-top: 8px; }
#toolbox .colors .sw { position: absolute; width: 20px; height: 20px; border: 1px solid #fff; box-shadow: 0 0 0 1px #000; cursor: pointer; }
#toolbox .colors .sw.fg { left: 2px; top: 2px; z-index: 2; }
#toolbox .colors .sw.bg { right: 2px; bottom: 2px; }
#toolbox .colors .mini { position: absolute; border: 0; background: none; color: var(--fg-muted); font-size: 10px; padding: 0; line-height: 1; }
#toolbox .colors .swap { right: -2px; top: -2px; }
#toolbox .colors .reset { left: -2px; bottom: -2px; }

#viewport { flex: 1; overflow: auto; background: #141414; position: relative; min-width: 0; }
#viewport.grab { cursor: grab; }
#viewport.grabbing { cursor: grabbing; }
#canvas-wrap { position: relative; margin: 40px; display: inline-block; box-shadow: 0 0 0 1px #000, 0 10px 40px rgba(0,0,0,.6); background: #fff; }
#canvas-wrap.checker { background-color: #fff; background-image: linear-gradient(45deg, #ccc 25%, transparent 25%), linear-gradient(-45deg, #ccc 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #ccc 75%), linear-gradient(-45deg, transparent 75%, #ccc 75%); background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0; }
#canvas-wrap.nogrid { background: #fff !important; }
#canvas-wrap canvas { display: block; }
.canvas-container { z-index: 1; }

#panels { width: 300px; background: var(--bg1); border-left: 1px solid var(--line); overflow-y: auto; flex: none; display: flex; flex-direction: column; }
.panel { border-bottom: 1px solid var(--line); }
.panel > header { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--bg2); font-weight: 600; font-size: 12px; cursor: pointer; text-transform: uppercase; letter-spacing: .3px; color: var(--fg-muted); }
.panel > header:hover { color: var(--fg); }
.panel > header .caret { transition: transform .15s; font-size: 10px; }
.panel.collapsed > header .caret { transform: rotate(-90deg); }
.panel > header .hdr-actions { margin-left: auto; display: flex; gap: 4px; }
.panel > .body { padding: 8px 10px; display: flex; flex-direction: column; gap: 8px; }
.panel.collapsed > .body { display: none; }
.field { display: flex; align-items: center; gap: 6px; }
.field > label { color: var(--fg-muted); min-width: 70px; font-size: 12px; }
.field input[type=range] { flex: 1; }
.field .val { width: 42px; text-align: right; color: var(--fg-muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.field select { flex: 1; }
.field input[type=text] { flex: 1; }
.subhead { font-size: 11px; text-transform: uppercase; color: var(--fg-dim); letter-spacing: .3px; margin-top: 4px; }
.help { font-size: 11px; color: var(--fg-dim); line-height: 1.35; }

/* color panel */
.swatch-big { display: flex; gap: 10px; align-items: center; }
.swatch-big .sw { width: 44px; height: 44px; border-radius: 6px; border: 1px solid #000; box-shadow: inset 0 0 0 1px rgba(255,255,255,.25); cursor: pointer; }
.hexrow { display: flex; gap: 6px; align-items: center; }
.hexrow input[type=text] { width: 90px; font-family: var(--mono); text-transform: uppercase; }
.slider-grid { display: grid; grid-template-columns: 14px 1fr 40px; gap: 4px 6px; align-items: center; font-size: 12px; color: var(--fg-muted); }
.slider-grid input[type=range] { width: 100%; }
.swatches { display: flex; flex-wrap: wrap; gap: 4px; }
.swatches .sw { width: 22px; height: 22px; border-radius: 3px; border: 1px solid #000; box-shadow: inset 0 0 0 1px rgba(255,255,255,.2); cursor: pointer; position: relative; }
.swatches .sw:hover { outline: 2px solid var(--accent); }
.swatches .sw.add { display: grid; place-items: center; background: var(--bg3); color: var(--fg-muted); font-size: 16px; line-height: 1; }
.sw.checker { background-image: linear-gradient(45deg, #999 25%, transparent 25%), linear-gradient(-45deg, #999 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #999 75%), linear-gradient(-45deg, transparent 75%, #999 75%); background-size: 8px 8px; background-position: 0 0, 0 4px, 4px -4px, -4px 0; background-color: #fff; }

/* contrast panel */
.contrast-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.contrast-pair .cell { background: var(--bg2); border-radius: 6px; padding: 6px; display: flex; flex-direction: column; gap: 4px; }
.contrast-pair .cell .sw { height: 28px; border-radius: 4px; border: 1px solid #000; }
.contrast-preview { height: 54px; border-radius: 6px; display: grid; place-items: center; font-size: 22px; font-weight: 700; border: 1px solid #000; letter-spacing: 1px; }
.suggest { display: flex; flex-direction: column; gap: 3px; }
.suggest .s { display: grid; grid-template-columns: 26px 1fr auto auto; gap: 8px; align-items: center; padding: 3px 4px; border-radius: 4px; cursor: pointer; font-size: 12px; }
.suggest .s:hover { background: var(--bg3); }
.suggest .s .sw { width: 24px; height: 20px; border-radius: 3px; border: 1px solid #000; }
.suggest .s .hex { font-family: var(--mono); text-transform: uppercase; }
.suggest .s .ratio { color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.suggest .s .tag { color: var(--fg-dim); font-size: 11px; }

/* layers */
.layer-tools { display: flex; gap: 4px; flex-wrap: wrap; }
.layer-tools .btn { padding: 2px 6px; font-size: 12px; }
.layers { display: flex; flex-direction: column; gap: 1px; max-height: 320px; overflow-y: auto; border: 1px solid var(--line); background: var(--bg0); border-radius: 4px; }
.layer { display: grid; grid-template-columns: 22px 44px 1fr 22px; align-items: center; gap: 6px; padding: 3px 6px; cursor: pointer; border-left: 3px solid transparent; }
.layer:hover { background: var(--bg2); }
.layer.active { background: #2a4058; border-left-color: var(--accent); }
.layer.hidden-layer { opacity: .5; }
.layer.dragover { outline: 1px dashed var(--accent); }
.layer .eye, .layer .lock { width: 20px; height: 20px; border: 0; background: none; color: var(--fg); display: grid; place-items: center; padding: 0; border-radius: 3px; }
.layer .eye:hover, .layer .lock:hover { background: var(--bg4); }
.layer .eye.off, .layer .lock.off { color: var(--fg-dim); }
.layer .thumb { width: 44px; height: 32px; border: 1px solid var(--line2); background-image: linear-gradient(45deg, #777 25%, transparent 25%), linear-gradient(-45deg, #777 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #777 75%), linear-gradient(-45deg, transparent 75%, #777 75%); background-size: 8px 8px; background-position: 0 0, 0 4px, 4px -4px, -4px 0; background-color: #bbb; display: grid; place-items: center; overflow: hidden; }
.layer .thumb img { max-width: 100%; max-height: 100%; }
.layer .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.layer .name small { color: var(--fg-dim); margin-left: 4px; }
.layer .name input { width: 100%; padding: 1px 4px; }

/* fx & textures */
.tex-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tex { aspect-ratio: 1; border: 1px solid var(--line2); border-radius: 4px; cursor: pointer; overflow: hidden; position: relative; background: #888; }
.tex img, .tex canvas { width: 100%; height: 100%; object-fit: cover; display: block; image-rendering: pixelated; }
.tex.active { outline: 2px solid var(--accent); }
.tex .del { position: absolute; top: 1px; right: 1px; background: rgba(0,0,0,.6); border: 0; color: #fff; font-size: 10px; border-radius: 3px; padding: 0 4px; display: none; }
.tex:hover .del { display: block; }
.tex-name { font-size: 10px; color: var(--fg-muted); text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pattern-preview { height: 60px; border: 1px solid var(--line2); border-radius: 4px; image-rendering: pixelated; background: #808080; }

/* history */
.history { max-height: 200px; overflow-y: auto; border: 1px solid var(--line); background: var(--bg0); border-radius: 4px; }
.history .h { padding: 3px 8px; cursor: pointer; font-size: 12px; }
.history .h:hover { background: var(--bg2); }
.history .h.current { background: #2a4058; }
.history .h.future { color: var(--fg-dim); }

/* filters list in props */
.filter-list { display: flex; flex-direction: column; gap: 2px; }
.filter-list .f { display: flex; justify-content: space-between; align-items: center; background: var(--bg2); padding: 3px 6px; border-radius: 4px; font-size: 12px; }

/* status bar */
#statusbar { display: flex; gap: 16px; align-items: center; height: 24px; padding: 0 10px; background: var(--bg1); border-top: 1px solid var(--line); font-size: 12px; color: var(--fg-muted); flex: none; }
#statusbar .zoom { display: flex; align-items: center; gap: 4px; }
#statusbar input[type=text] { width: 60px; padding: 1px 4px; font-size: 12px; }
#statusbar .sample { display: inline-block; width: 14px; height: 14px; border: 1px solid #000; vertical-align: middle; }

/* modals */
#modal-root { position: fixed; inset: 0; z-index: 2000; display: none; }
#modal-root.open { display: block; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.modal { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: var(--bg1); border: 1px solid var(--line2); border-radius: 10px; min-width: 380px; max-width: min(96vw, 1000px); max-height: 92vh; display: flex; flex-direction: column; box-shadow: 0 30px 80px rgba(0,0,0,.7); }
.modal > header { padding: 12px 16px; font-weight: 600; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal > header .close { margin-left: auto; background: none; border: 0; color: var(--fg-muted); font-size: 18px; }
.modal > .content { padding: 14px 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; user-select: text; }
.modal > footer { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.modal .field > label { min-width: 110px; }
.modal .field input[type=text], .modal .field select { flex: 1; }
.modal .field input[type=number] { width: 90px; }
.modal .preview-img { max-width: 100%; max-height: 50vh; display: block; margin: 0 auto; background: #333; }
.modal .kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 12px; }
.modal pre { background: var(--bg0); padding: 8px; border-radius: 6px; max-height: 300px; overflow: auto; font-size: 11px; user-select: text; }
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.project { border: 1px solid var(--line2); border-radius: 6px; overflow: hidden; cursor: pointer; background: var(--bg2); }
.project:hover { border-color: var(--accent); }
.project .thumb { height: 100px; background: #555 center/contain no-repeat; }
.project .meta { padding: 6px 8px; font-size: 12px; }
.project .meta small { color: var(--fg-muted); display: block; }
.project .del { float: right; }
.share-list { display: flex; flex-direction: column; gap: 6px; }
.share-item { display: grid; grid-template-columns: 48px 1fr auto auto; gap: 8px; align-items: center; font-size: 12px; background: var(--bg2); padding: 6px; border-radius: 6px; }
.share-item img { width: 48px; height: 36px; object-fit: cover; background: #444; }
.share-item .url { font-family: var(--mono); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: text; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line2); }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 6px 10px; color: var(--fg-muted); }
.tabs button.active { color: var(--fg); border-bottom-color: var(--accent); }
.tab-body { display: none; }
.tab-body.active { display: block; }
.vision-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.vision-table th, .vision-table td { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.vision-table th { color: var(--fg-muted); font-weight: 600; }
.vision-legend { display: flex; gap: 12px; font-size: 11px; color: var(--fg-muted); flex-wrap: wrap; }
.vision-legend i { display: inline-block; width: 10px; height: 10px; margin-right: 4px; vertical-align: middle; }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; }
.tag-list span { background: var(--bg3); border-radius: 12px; padding: 2px 8px; font-size: 12px; }
.tag-list span b { color: var(--fg-muted); font-weight: 400; margin-left: 4px; }

/* toast */
#toast { position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); z-index: 3000; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast-item { background: var(--bg3); border: 1px solid var(--line2); color: var(--fg); padding: 8px 14px; border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.5); pointer-events: auto; max-width: 70vw; }
.toast-item.error { border-color: var(--danger); }
.toast-item.ok { border-color: var(--ok); }

/* marching ants for selection */
@keyframes ants { to { stroke-dashoffset: -12; } }

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg0); }
::-webkit-scrollbar-thumb { background: #555; border-radius: 5px; border: 2px solid var(--bg0); }
