:root {
  --bg: #121214;
  --panel: rgba(30, 30, 34, 0.94);
  --panel-solid: #1e1e22;
  --line: rgba(255, 255, 255, 0.08);
  --text: #e8e8ea;
  --dim: #9a9aa2;
  --accent: #4ea1ff;
  --accent-dim: rgba(78, 161, 255, 0.18);
  --r: 14px;
}
* { box-sizing: border-box; }
html, body { -webkit-touch-callout: none; -webkit-user-select: none; touch-action: none; overscroll-behavior: none; margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.35 "Segoe UI", system-ui, -apple-system, sans-serif; overflow: hidden; user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, select { font: inherit; color: var(--text); }
#viewport { position: fixed; inset: 0; }
#gl { width: 100%; height: 100%; display: block; touch-action: none; cursor: none; }
#viewport.nav #gl { cursor: grab; }
#viewport.nav.dragging #gl { cursor: grabbing; }
#viewport.picking #gl { cursor: crosshair; }
#cursor { position: fixed; pointer-events: none; border-radius: 50%; border: 1px solid rgba(255,255,255,0.85); box-shadow: 0 0 0 1px rgba(0,0,0,0.6); transform: translate(-50%, -50%); display: none; }
#cursor::after { content: ""; position: absolute; left: 50%; top: 50%; width: 2px; height: 2px; margin: -1px; background: #fff; border-radius: 50%; }

/* top bar */
#topbar { position: fixed; top: calc(10px + env(safe-area-inset-top)); left: calc(10px + env(safe-area-inset-left)); right: calc(10px + env(safe-area-inset-right)); height: 44px; display: flex; justify-content: space-between; pointer-events: none; z-index: 10; }
#topbar > div { display: flex; align-items: center; gap: 4px; pointer-events: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px 6px; backdrop-filter: blur(12px); }
#title { padding: 0 10px 0 4px; color: var(--dim); }
.icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; }
.icon:hover { background: rgba(255,255,255,0.07); }
.icon.active { background: var(--accent-dim); color: var(--accent); }
.icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.icon.small { width: 32px; height: 32px; }
#btnMaterial { width: 38px; height: 34px; display: grid; place-items: center; }
#swatch { width: 26px; height: 26px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.9); box-shadow: 0 0 0 1px rgba(0,0,0,0.5); display: block; }

/* sidebar sliders (Procreate style) */
#sidebar { position: fixed; left: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 10px 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; z-index: 10; backdrop-filter: blur(12px); }
#sidebar.right { left: auto; right: 10px; }
.vslider { width: 30px; height: 170px; border-radius: 15px; background: rgba(255,255,255,0.06); position: relative; cursor: ns-resize; overflow: visible; }
.vslider .fill { position: absolute; left: 0; right: 0; bottom: 0; border-radius: 15px; background: rgba(255,255,255,0.12); }
.vslider .knob { position: absolute; left: 3px; right: 3px; height: 24px; border-radius: 12px; background: #f2f2f4; box-shadow: 0 1px 4px rgba(0,0,0,0.5); transform: translateY(50%); }
.vslider .bubble { position: absolute; left: 44px; top: 50%; transform: translateY(-50%); background: var(--panel-solid); border: 1px solid var(--line); padding: 6px 10px; border-radius: 10px; white-space: nowrap; pointer-events: none; }

/* channel bar */
#channelbar { position: fixed; bottom: calc(12px + env(safe-area-inset-bottom)); max-width: calc(100vw - 20px); overflow-x: auto; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; z-index: 10; backdrop-filter: blur(12px); }
#channelbar button { padding: 6px 11px; border-radius: 8px; color: var(--dim); }
#channelbar button:hover { color: var(--text); }
#channelbar button.active { background: var(--accent-dim); color: var(--accent); }
#channelbar .sep { width: 1px; height: 20px; background: var(--line); margin: 0 6px; }
.mini { display: flex; align-items: center; gap: 6px; color: var(--dim); padding-right: 8px; }
.mini input { width: 90px; }

/* panels */
.panel { touch-action: pan-y; position: fixed; top: calc(62px + env(safe-area-inset-top)); right: 10px; width: 300px; max-height: calc(100vh - 130px); overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; display: none; z-index: 20; backdrop-filter: blur(16px); box-shadow: 0 10px 40px rgba(0,0,0,0.45); }
.panel.open { display: block; }
.panel.wide { width: 340px; }
#menuPanel { left: 10px; right: auto; width: 270px; padding: 6px; }
#menuPanel button { display: flex; justify-content: space-between; width: 100%; text-align: left; padding: 8px 10px; border-radius: 8px; }
#menuPanel button:hover { background: rgba(255,255,255,0.07); }
#menuPanel hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
kbd { color: var(--dim); font: inherit; font-size: 11px; }
#keysPanel { left: 50%; right: auto; transform: translateX(-50%); width: 420px; top: 90px; }
#keysPanel td { padding: 4px 12px 4px 0; } #keysPanel td:first-child { color: var(--dim); }
.panel h3 { margin: 0; font-size: 13px; font-weight: 600; }
.panel h4 { margin: 12px 0 6px; font-size: 12px; color: var(--dim); font-weight: 600; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin: 2px 0 10px; gap: 8px; }
.link { color: var(--accent); }
.row { display: flex; align-items: center; }
.row.gap { gap: 6px; }
.chip { white-space: nowrap; padding: 5px 9px; border-radius: 8px; background: rgba(255,255,255,0.07); }
.chip:hover { background: rgba(255,255,255,0.12); }
.chip.on { background: var(--accent-dim); color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
select { background: rgba(255,255,255,0.07); border: 0; border-radius: 8px; padding: 5px 6px; }
select option { background: var(--panel-solid); }

/* brush library */
#brushLib { max-height: 260px; overflow: auto; margin-bottom: 12px; }
.brush-set { margin-bottom: 8px; }
.brush-set-head { display: flex; justify-content: space-between; color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; margin: 6px 0; }
.brush-set-head button { color: var(--dim); font-size: 11px; }
.brush-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.brush-cell { aspect-ratio: 1; border-radius: 10px; background: rgba(0,0,0,0.35); display: grid; place-items: center; position: relative; border: 1px solid transparent; }
.brush-cell canvas { width: 80%; height: 80%; filter: invert(0); }
.brush-cell.on { border-color: var(--accent); background: var(--accent-dim); }
.brush-cell:hover { border-color: rgba(255,255,255,0.2); }

/* settings rows */
.settings .set { display: grid; grid-template-columns: 96px 1fr 40px; align-items: center; gap: 8px; margin: 6px 0; }
.settings .set label { color: var(--dim); }
.settings .set .val { text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }
.settings .check { display: flex; align-items: center; gap: 8px; margin: 8px 0; color: var(--dim); }
.settings .group { color: var(--dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; margin: 14px 0 4px; }
input[type=range] { -webkit-appearance: none; appearance: none; height: 4px; border-radius: 2px; background: rgba(255,255,255,0.14); outline: none; width: 100%; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%; background: #f2f2f4; box-shadow: 0 1px 3px rgba(0,0,0,0.6); }
input[type=color] { width: 36px; height: 26px; border: 0; background: none; padding: 0; }
input[type=text] { background: rgba(255,255,255,0.07); border: 0; border-radius: 8px; padding: 6px 8px; width: 90px; }

/* layers */
#layerList { display: flex; flex-direction: column-reverse; gap: 4px; margin-bottom: 10px; }
.layer { display: grid; grid-template-columns: 26px 34px 1fr 34px 26px; align-items: center; gap: 6px; padding: 5px; border-radius: 10px; background: rgba(255,255,255,0.04); border: 1px solid transparent; }
.layer.on { background: var(--accent-dim); border-color: rgba(78,161,255,0.4); }
.layer .eye { opacity: 0.85; } .layer .eye.off { opacity: 0.25; }
.layer .thumb { width: 34px; height: 34px; border-radius: 7px; background: #333; display: grid; place-items: center; border: 2px solid transparent; }
.layer .thumb.sel { border-color: var(--accent); }
.layer .thumb svg { width: 18px; height: 18px; fill: none; stroke: #ddd; stroke-width: 1.7; }
.layer .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer .name small { display: block; color: var(--dim); font-size: 11px; }
.layer .maskthumb { width: 34px; height: 34px; border-radius: 7px; background: #eee; border: 2px solid transparent; display: none; }
.layer .maskthumb.has { display: block; } .layer .maskthumb.sel { border-color: var(--accent); }
.layer .more { color: var(--dim); }
.layer svg.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; }
.layer-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }

/* material panel */
.picker { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
#svPick { width: 100%; aspect-ratio: 1; border-radius: 10px; cursor: crosshair; }
#huePick { width: 100%; height: 18px; border-radius: 9px; cursor: ew-resize; }
#recent { display: flex; gap: 4px; flex-wrap: wrap; }
#recent span { width: 20px; height: 20px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.3); cursor: pointer; }
.chanrow { display: grid; grid-template-columns: 22px 80px 1fr 40px; align-items: center; gap: 8px; margin: 8px 0; }
.chanrow label { color: var(--dim); }
.chanrow .val { text-align: right; color: var(--dim); font-variant-numeric: tabular-nums; }

/* empty state, toast, drop, busy */
#empty { position: fixed; inset: 0; display: grid; place-items: center; z-index: 5; pointer-events: none; }
#empty.hidden { display: none; }
.empty-card { pointer-events: auto; text-align: center; padding: 28px 34px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; }
.empty-card .logo { font-size: 26px; font-weight: 600; letter-spacing: 0.02em; margin-bottom: 6px; }
.empty-card .row { gap: 8px; justify-content: center; margin: 16px 0 8px; }
.empty-card button { padding: 9px 14px; border-radius: 10px; background: rgba(255,255,255,0.08); }
.empty-card button.primary { background: var(--accent); color: #06121f; font-weight: 600; }
.hint { color: var(--dim); font-size: 12px; }
#toast { position: fixed; bottom: 64px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--panel-solid); border: 1px solid var(--line); padding: 9px 14px; border-radius: 10px; opacity: 0; transition: all 0.2s; pointer-events: none; z-index: 50; max-width: 70vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#drop { position: fixed; inset: 0; background: rgba(78,161,255,0.12); border: 3px dashed var(--accent); display: none; place-items: center; z-index: 60; font-size: 18px; }
#drop.show { display: grid; }
#busy { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: none; place-items: center; z-index: 70; }
#busy.show { display: flex; flex-direction: column; gap: 12px; justify-content: center; align-items: center; }
.spinner { width: 32px; height: 32px; border-radius: 50%; border: 3px solid rgba(255,255,255,0.2); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
::-webkit-scrollbar { width: 8px; } ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 4px; }

#addSmart { max-width: 150px; }

.resrow { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; color: var(--text); }
.resrow span { display: flex; gap: 2px; }
#menuPanel .resrow button { width: auto; padding: 4px 9px; border-radius: 7px; color: var(--dim); }
#menuPanel .resrow button.on { background: var(--accent-dim); color: var(--accent); }
@media (pointer: coarse) {
  .icon { width: 42px; height: 42px; }
  .vslider { width: 36px; height: 200px; }
  #channelbar button { padding: 9px 12px; }
  .settings .set { margin: 10px 0; }
  input[type=range]::-webkit-slider-thumb { width: 22px; height: 22px; }
  .layer { padding: 7px; }
}
