/* Dial Texture Studio. A light, paper-toned workshop round a dark stage:
   the dial is judged against black, the controls are read against paper. */
:root {
  --paper: #f3f1ec;
  --paper-2: #e9e6df;
  --card: #fbfaf7;
  --ink: #1c1d20;
  --ink-2: #4a4c52;
  --ink-3: #7a7c82;
  --line: #d9d5cc;
  --accent: #0e6b66;
  --accent-2: #0b5550;
  --accent-soft: #d5ebe8;
  --warn: #9a4b12;
  --stage: #111214;
  --stage-2: #1b1d20;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
  --sans: "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #1a1b1e; --paper-2: #222429; --card: #202226; --ink: #ecebe7; --ink-2: #c3c2bd;
    --ink-3: #8f8e8a; --line: #34363c; --accent: #4cbab2; --accent-2: #6fd0c8; --accent-soft: #20403e; --warn: #e3a05d;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--paper); color: var(--ink); font: 13px/1.45 var(--sans); }
button, input, select { font: inherit; color: inherit; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------------------------------------------------------------- bar */
.bar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand .logo { width: 28px; height: 28px; color: var(--accent); flex: none; }
.brand b { display: block; font-size: 14px; letter-spacing: .01em; }
.brand small { color: var(--ink-3); font-size: 11px; }
.name { flex: 1; min-width: 120px; max-width: 360px; }
.name input {
  width: 100%; padding: 6px 10px; border: 1px solid transparent; border-radius: 6px;
  background: transparent; font-size: 15px; font-weight: 600;
}
.name input:hover, .name input:focus { border-color: var(--line); background: var(--paper); outline: none; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; margin-left: auto; }
button { cursor: pointer; border-radius: 6px; border: 1px solid var(--line); background: var(--card); padding: 6px 11px; }
button:hover { border-color: var(--ink-3); }
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: transparent; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-2); }
button.small { padding: 5px 9px; font-size: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu {
  position: absolute; right: 16px; top: 52px; z-index: 30; width: 250px; padding: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}
.menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 9px; }
.menu button:hover { background: var(--paper-2); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.menu-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 9px; color: var(--ink-2); }

/* ---------------------------------------------------------------- app */
.app { display: grid; grid-template-columns: 270px minmax(0, 1fr) 330px; gap: 0; min-height: calc(100vh - 57px); }
.col { background: var(--paper); padding: 14px; overflow-y: auto; max-height: calc(100vh - 57px); position: sticky; top: 57px; }
.layers { border-right: 1px solid var(--line); }
.inspector { border-left: 1px solid var(--line); }
.col-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
h2 { font-size: 11px; letter-spacing: .09em; text-transform: uppercase; margin: 0; color: var(--ink-2); }
.hint { color: var(--ink-3); font-size: 11px; }

/* layers */
.layer-list { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column-reverse; gap: 4px; }
.layer {
  display: grid; grid-template-columns: 18px 1fr auto; align-items: center; gap: 6px;
  padding: 6px 7px; border: 1px solid var(--line); border-radius: 7px; background: var(--card); cursor: pointer;
}
.layer.on { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.layer.off .ltitle { opacity: .5; text-decoration: line-through; }
.layer .ltitle { min-width: 0; }
.layer .ltitle b { display: block; font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.layer .ltitle small { color: var(--ink-3); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.layer .lbtn { display: flex; gap: 2px; }
.layer .lbtn button { padding: 1px 5px; font-size: 11px; line-height: 1.4; border-color: transparent; background: none; }
.layer .lbtn button:hover { border-color: var(--line); }
.layer input[type=checkbox] { margin: 0; }
.layer.base { cursor: pointer; }
.add { display: flex; gap: 6px; }
.add select { flex: 1; min-width: 0; padding: 5px; border: 1px solid var(--line); border-radius: 6px; background: var(--card); }
.aside-note { color: var(--ink-3); font-size: 11.5px; margin: 8px 2px 0; }

/* stage */
.stage-col { background: var(--stage); display: flex; flex-direction: column; align-items: center; padding: 18px 18px 10px; min-width: 0; }
.stage { position: relative; width: min(100%, calc(100vh - 170px)); max-width: 860px; aspect-ratio: 1 / 1; cursor: crosshair; touch-action: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#overlay { pointer-events: none; }
.sun {
  position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle, #fff7d6 0 35%, rgba(255,240,190,.35) 36% 60%, transparent 62%);
}
.busy { position: absolute; right: 8px; bottom: 8px; color: #ddd; background: rgba(0,0,0,.55); padding: 3px 8px; border-radius: 5px; font-size: 11px; }
.stage-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 12px; color: #c9c9c6; }
.stage-bar select { background: var(--stage-2); color: #ddd; border: 1px solid #333; border-radius: 5px; padding: 3px 5px; }
.seg { display: inline-flex; border: 1px solid #3a3c40; border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; color: #bbb; padding: 5px 11px; }
.seg button.on { background: #e9e6df; color: #111; }
.check { display: inline-flex; align-items: center; gap: 6px; }
.quality { display: inline-flex; align-items: center; gap: 6px; }
.stat { font: 11px var(--mono); color: #888; }
.stage-note { color: #8c8c88; font-size: 11.5px; max-width: 640px; text-align: center; margin: 8px 0 0; }

/* inspector */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.panel > summary { cursor: pointer; font-size: 11px; letter-spacing: .09em; text-transform: uppercase; color: var(--ink-2); font-weight: 600; list-style: none; }
.panel > summary::after { content: '▾'; float: right; color: var(--ink-3); }
.panel:not([open]) > summary::after { content: '▸'; }
.panel[open] > summary { margin-bottom: 10px; }
.inspect-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.inspect-head h3 { margin: 0; font-size: 14px; }
.inspect-help { color: var(--ink-3); margin: 0 0 10px; font-size: 12px; }
.f { margin-bottom: 10px; }
.f > label, .f > .lab { display: flex; justify-content: space-between; gap: 8px; color: var(--ink-2); font-size: 12px; margin-bottom: 3px; }
.f .val { font: 11.5px var(--mono); color: var(--ink); }
.f input[type=range] { width: 100%; accent-color: var(--accent); margin: 0; }
.f select, .f input[type=text], .f input[type=number] {
  width: 100%; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--paper);
}
.f input[type=color] { width: 44px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: none; }
.f .help { color: var(--ink-3); font-size: 11px; margin-top: 2px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sub { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
.sub h4 { margin: 0 0 8px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.chips button { font-size: 11px; padding: 3px 7px; }

/* gradient stops */
.gbar { height: 16px; border-radius: 4px; border: 1px solid var(--line); margin-bottom: 6px;
  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: 8px 8px; background-position: 0 0, 0 4px, 4px -4px, -4px 0; position: relative; overflow: hidden; }
.gbar i { position: absolute; inset: 0; }
.stop { display: grid; grid-template-columns: 38px 1fr 1fr 24px; gap: 6px; align-items: center; margin-bottom: 4px; }
.stop input[type=color] { width: 36px; height: 24px; }
.stop.noalpha { grid-template-columns: 38px 1fr 24px; }
.stop small { color: var(--ink-3); font: 10.5px var(--mono); display: block; }
.stop button { padding: 0 4px; border-color: transparent; background: none; }

/* light pad */
.lightpad-wrap { display: grid; grid-template-columns: 110px 1fr; gap: 10px; align-items: center; margin-bottom: 10px; }
.lightpad-wrap p { margin: 0; color: var(--ink-3); font-size: 11.5px; }
.lightpad { position: relative; width: 110px; height: 110px; border-radius: 50%; touch-action: none; cursor: grab;
  background: radial-gradient(circle, #fdfbf4 0, #e7e2d6 60%, #cfc9bb 100%); border: 1px solid var(--line); }
.lightpad span { position: absolute; width: 16px; height: 16px; margin: -8px; border-radius: 50%;
  background: radial-gradient(circle, #ffd76a 0 45%, rgba(255,200,80,.4) 46% 70%, transparent 72%); }

/* gallery */
.drawer { position: fixed; inset: 57px 0 0 0; z-index: 25; background: var(--paper); overflow-y: auto; padding: 16px 20px 40px; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.drawer .seg { border-color: var(--line); }
.drawer .seg button { color: var(--ink-2); }
.drawer .seg button.on { background: var(--accent); color: #fff; }
.gal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.gcard { text-align: left; padding: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; position: relative; }
.gcard:hover { border-color: var(--accent); }
.gcard canvas, .gcard img { width: 100%; aspect-ratio: 1; display: block; background: #111; border-radius: 6px; }
.gcard b { display: block; font-size: 12.5px; margin-top: 7px; }
.gcard small { color: var(--ink-3); font-size: 11px; }
.gcard .del { position: absolute; top: 12px; right: 12px; background: rgba(0,0,0,.6); color: #fff; border: 0; padding: 2px 7px; }
.empty { color: var(--ink-3); padding: 20px 0; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); opacity: 0; transition: .2s;
  background: var(--ink); color: var(--paper); padding: 8px 14px; border-radius: 8px; z-index: 50; pointer-events: none; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* stage tools */
.stage-bar button.dark { background: var(--stage-2); color: #ddd; border-color: #3a3c40; padding: 4px 10px; }
.stage-bar button.dark[aria-pressed="true"] { background: #e9e6df; color: #111; }
.stage-bar button.dark.rec { background: #a3261b; border-color: #a3261b; color: #fff; }
.loupe { position: absolute; width: 240px; height: 240px; margin: -120px 0 0 -120px; border-radius: 50%; overflow: hidden;
  border: 2px solid rgba(255,255,255,.85); box-shadow: 0 8px 30px rgba(0,0,0,.6); pointer-events: none; background: #000; }
.loupe canvas { width: 100%; height: 100%; display: block; }
.loupe span { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); font: 11px var(--mono); color: #fff;
  background: rgba(0,0,0,.55); padding: 1px 6px; border-radius: 4px; }
.stage.loupe-on { cursor: none; }

/* reference photo */
.btns-row { display: flex; gap: 6px; margin-bottom: 8px; }
.ref-canvas { width: 100%; border-radius: 6px; cursor: crosshair; display: block; touch-action: none; }
.ref-pick { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.ref-pick i { width: 26px; height: 26px; border-radius: 5px; border: 1px solid var(--line); display: inline-block; }
.ref-pick code { font: 11.5px var(--mono); }
.ref-pick button { font-size: 11px; padding: 3px 7px; }

/* variations */
.gcard.vary canvas { width: 100%; aspect-ratio: 1; display: block; border-radius: 6px; background: #111; }
.vary-head { grid-column: 1 / -1; display: flex; gap: 10px; align-items: center; color: var(--ink-2); }

/* ------------------------------------------------------------ modes */
.mode-seg { border-color: var(--line); }
.mode-seg button { color: var(--ink-2); padding: 5px 12px; }
.mode-seg button.on { background: var(--accent); color: #fff; }
.simple { display: none; }
body.mode-simple .app { grid-template-columns: 400px minmax(0, 1fr); }
body.mode-simple .simple { display: block; border-right: 1px solid var(--line); }
body.mode-simple .layers, body.mode-simple .inspector { display: none; }
body.mode-simple #vary-btn { display: none; }

/* the simple panel */
.sp-sec { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 12px 10px; margin-bottom: 10px; }
.sp-sec h3 { margin: 0 0 8px; font-size: 13px; }
.sp-sub { margin: -4px 0 8px; color: var(--ink-3); font-size: 11.5px; }
.sp-hello, .sp-note { border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; font-size: 12px; }
.sp-hello { background: var(--accent-soft); color: var(--ink); }
.sp-hello b { display: block; margin-bottom: 2px; }
.sp-hello p { margin: 0 0 8px; }
.sp-note { background: var(--paper-2); color: var(--ink-2); }
.sp-starts { display: grid; grid-auto-flow: column; grid-auto-columns: 92px; gap: 8px; overflow-x: auto; padding-bottom: 6px; scroll-snap-type: x mandatory; }
.sp-start, .sp-surf { padding: 5px; border-radius: 9px; background: var(--paper); text-align: center; scroll-snap-align: start; }
.sp-start canvas, .sp-surf canvas { width: 100%; aspect-ratio: 1; display: block; border-radius: 50%; background: #111; }
.sp-start small, .sp-surf small { display: block; font-size: 10.5px; line-height: 1.25; margin-top: 4px; color: var(--ink-2); }
.sp-surfaces { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.sp-surf.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.sp-palette { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.sp-sw { width: 26px; height: 26px; border-radius: 50%; padding: 0; border: 2px solid var(--card); box-shadow: 0 0 0 1px var(--line); }
.sp-sw.on { box-shadow: 0 0 0 2px var(--accent); }
.sp-own { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--ink-2); margin-left: 4px; }
.sp-own input { width: 30px; height: 26px; padding: 0; border: 1px solid var(--line); border-radius: 50%; overflow: hidden; }
.sp-slider { margin: 6px 0 10px; }
.sp-slider label { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-bottom: 3px; }
.sp-val { font: 11.5px var(--mono); color: var(--ink); }
.sp-slider input { width: 100%; accent-color: var(--accent); }
.sp-check { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 6px 0; }
.sp-inline-color { width: 44px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 5px; margin: 0 0 6px 22px; }
.sp-seg { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.sp-seg button { font-size: 12px; padding: 5px 9px; }
.sp-seg button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sp-seg.small button { font-size: 11px; padding: 3px 8px; }
.sp-subs { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 12px; color: var(--ink-2); }
.sp-hour { width: 34px; height: 34px; border-radius: 50%; padding: 0; font-weight: 600; }
.sp-hour.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.sp-light { display: flex; align-items: center; gap: 12px; }
.sp-light .lightpad { width: 96px; height: 96px; flex: none; }

/* advanced: pattern pictures and folded settings */
.picks { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.pick { padding: 3px; border-radius: 7px; background: var(--paper); text-align: center; }
.pick canvas { width: 100%; aspect-ratio: 1; display: block; border-radius: 5px; background: #111; }
.pick small { display: block; font-size: 10px; line-height: 1.2; margin-top: 3px; color: var(--ink-2); }
.pick.on { box-shadow: 0 0 0 2px var(--accent); border-color: var(--accent); }
.more { border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 6px; }
.more > summary { cursor: pointer; font-size: 12px; color: var(--accent); margin-bottom: 8px; }

/* narrow screens: stack */
@media (max-width: 1100px) {
  .app { grid-template-columns: 240px minmax(0, 1fr); }
  body.mode-simple .app { grid-template-columns: 340px minmax(0, 1fr); }
  .inspector { grid-column: 1 / -1; position: static; max-height: none; border-left: 0; border-top: 1px solid var(--line);
    display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px; }
}
@media (max-width: 720px) {
  .bar { flex-wrap: wrap; }
  .app { display: flex; flex-direction: column; }
  .col { position: static; max-height: none; }
  .stage { width: 100%; }
  .layers { border-right: 0; border-bottom: 1px solid var(--line); }
}

/* Sync between computers (cloud.js), at the top of "Your library". */
.gal-cloud { grid-column: 1 / -1; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); font-size: 13px; }
.gal-cloud p { margin: 4px 0 8px; color: var(--ink-2); line-height: 1.45; }
.gal-cloud .cloud-error { color: var(--warn); }
.gal-cloud .cloud-row { display: flex; gap: 6px; flex-wrap: wrap; }
.gal-cloud .cloud-key { flex: 1 1 160px; min-width: 0; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font: inherit; background: #fff; color: var(--ink); }
