:root {
  --purple: #753f97; --purple-2: #8e55b3; --green: #61ba46; --blue: #00a7e5;
  --ink: #1d2330; --muted: #6b7484; --line: #e3e7ee; --bg: #f4f6f9; --card: #ffffff;
  --radius: 14px; --ease: cubic-bezier(0.22, 1, 0.36, 1);
  font-family: 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink); background: var(--bg); color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; flex-direction: column; overflow: hidden; overflow: clip; }
html { overflow: hidden; overflow: clip; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top { height: 56px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; background: var(--card); border-bottom: 1px solid var(--line); flex: none; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.logo { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-weight: 700; color: #fff;
  background: conic-gradient(from 200deg, var(--green), var(--blue), var(--purple), var(--green)); }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text b { letter-spacing: .04em; }
.brand-text small { color: var(--muted); font-size: calc(11px * var(--fs, 1)); }
.top-links { display: flex; gap: 10px; align-items: center; font-size: calc(14px * var(--fs, 1)); }
.top-links a { color: var(--muted); text-decoration: none; }
.top-links a:hover { color: var(--purple); }
.top-links .btn-line { background: #06c755; color: #fff; padding: 7px 14px; border-radius: 999px; font-weight: 600; }
.top-links .btn-line:hover { color: #fff; filter: brightness(1.05); }

.app { flex: 1; display: grid; grid-template-columns: calc(360px * (0.55 + 0.45 * var(--fs, 1))) 1fr; min-height: 0; overflow: hidden; }
.side { position: relative; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 12px; border-right: 1px solid var(--line); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.card h3 { margin: 0; font-size: calc(14px * var(--fs, 1)); font-weight: 600; color: var(--purple); }
.lbl { font-size: calc(13px * var(--fs, 1)); color: var(--muted); }
.muted { color: var(--muted); font-size: calc(13px * var(--fs, 1)); margin: 0; }
.tiny { font-size: calc(11.5px * var(--fs, 1)); }
textarea, select, input[type=number] { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fbfcfd; outline: none; transition: border-color .2s; }
textarea:focus, select:focus, input[type=number]:focus { border-color: var(--purple); background: var(--card); }
textarea { resize: vertical; font-size: calc(18px * var(--fs, 1)); font-weight: 600; }
.row { display: flex; gap: 8px; align-items: center; }
.row.two > * { flex: 1; }
.row select { flex: 1; }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 9px 12px; cursor: pointer; font-weight: 600; font-size: calc(14px * var(--fs, 1));
  transition: transform .15s var(--ease), background .2s, border-color .2s; text-align: center; white-space: nowrap; }
.btn:hover { border-color: var(--purple); color: var(--purple); }
.btn:active { transform: scale(.97); }
.btn.small { padding: 6px 10px; font-size: calc(12.5px * var(--fs, 1)); }
.btn.ghost { background: transparent; }
.btn.primary { background: linear-gradient(135deg, var(--purple), var(--purple-2)); color: #fff; border: 0; padding: 12px; font-size: calc(15px * var(--fs, 1)); box-shadow: 0 6px 18px rgba(117,63,151,.3); }
.btn.primary:hover { color: #fff; filter: brightness(1.06); }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

.seg { display: flex; background: #eef1f5; border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 8px; padding: 7px 6px; cursor: pointer; font-weight: 600; font-size: calc(13.5px * var(--fs, 1)); color: var(--muted); transition: background .2s, color .2s; }
.seg button.on { background: var(--card); color: var(--purple); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.seg.small button { font-size: calc(12.5px * var(--fs, 1)); padding: 5px; }
.seg.dark { background: rgba(20,24,32,.72); backdrop-filter: blur(8px); }
.seg.dark button { color: #cfd6e0; }
.seg.dark button.on { background: var(--purple); color: #fff; }

.slider, .param { display: grid; grid-template-columns: 1fr 1.1fr auto; align-items: center; gap: 8px; font-size: calc(13px * var(--fs, 1)); }
.slider output { min-width: 56px; text-align: right; color: var(--purple); font-variant-numeric: tabular-nums; }
.param { grid-template-columns: 1fr 1fr 64px 22px; }
.param span { color: #3c4453; }
.param input[type=number] { padding: 4px 6px; text-align: right; }
.param em { font-style: normal; color: var(--muted); font-size: calc(11px * var(--fs, 1)); }
input[type=range] { width: 100%; accent-color: var(--purple); }

.num { display: flex; flex-direction: column; gap: 4px; font-size: calc(13px * var(--fs, 1)); color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot.w { background: #ef4444; } .dot.h { background: var(--green); } .dot.d { background: var(--blue); }

.struct-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.struct { border: 1.5px solid var(--line); background: var(--card); border-radius: 10px; padding: 4px; cursor: pointer; position: relative; transition: border-color .2s, transform .15s var(--ease); }
.struct svg { width: 100%; display: block; }
.struct span { display: block; margin-top: 3px; font-size: calc(10.5px * var(--fs, 1)); line-height: 1.25; color: var(--ink); text-align: center; min-height: 2.5em;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.struct.on span { color: var(--purple); font-weight: 700; }
.struct:hover { transform: translateY(-1px); border-color: #c9b3d8; }
.struct.on { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(117,63,151,.15); }
.struct-hint { margin: 0; font-size: calc(12.5px * var(--fs, 1)); color: var(--muted); line-height: 1.5; }
.struct-hint b { color: var(--ink); }

.colors { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.colors label { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: calc(11.5px * var(--fs, 1)); color: var(--muted); }
.colors input { width: 100%; height: 30px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--card); cursor: pointer; }

.drop { border: 2px dashed #cdbbdb; border-radius: 12px; padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; text-align: center; color: var(--purple); }
.drop small { color: var(--muted); }
.drop:hover { background: #faf6fd; }

.summary .srow { display: flex; justify-content: space-between; gap: 8px; font-size: calc(12.5px * var(--fs, 1)); padding: 4px 0; border-bottom: 1px dashed var(--line); }
.summary .srow:last-child { border-bottom: 0; }
.summary b { font-weight: 600; text-align: right; }
.foot { font-size: calc(11px * var(--fs, 1)); color: var(--muted); text-align: center; padding: 4px 0 10px; }

.stage { position: relative; min-width: 0; min-height: 0; }
.viewport { position: absolute; inset: 0; }
.viewport canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.hud { position: absolute; display: flex; gap: 8px; align-items: center; }
.hud.top-left { top: 12px; left: 12px; }
.hud.top-right { top: 12px; right: 12px; }
.hud.bottom { bottom: 14px; left: 50%; transform: translateX(-50%); flex-wrap: wrap; justify-content: center; width: max-content; max-width: calc(100% - 24px); }
.badge, .status { background: rgba(255,255,255,.9); backdrop-filter: blur(8px); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; font-size: calc(13px * var(--fs, 1)); font-variant-numeric: tabular-nums; }
.badge small { color: var(--muted); }
.status.busy { color: var(--purple); }
.status.busy::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--purple); margin-right: 6px; animation: pulse 1s infinite; }
.status.ok { color: #2f8a1d; } .status.err { color: #c0362c; }
@keyframes pulse { 50% { opacity: .25; } }
.btn.pill { border-radius: 999px; background: rgba(20,24,32,.72); color: #fff; border: 0; backdrop-filter: blur(8px); }
.btn.pill:hover { color: #fff; background: rgba(20,24,32,.85); }
.btn.pill.on { background: #f5b301; color: #1d2330; }
.explode { display: flex; align-items: center; gap: 8px; background: rgba(20,24,32,.72); color: #fff; padding: 7px 12px; border-radius: 999px; font-size: calc(13px * var(--fs, 1)); backdrop-filter: blur(8px); }
.explode input { width: 110px; }
.warnings { position: absolute; top: 56px; left: 12px; max-width: min(520px, calc(100% - 24px)); background: #fff8e6; border: 1px solid #f5d68a; color: #7a5300; border-radius: 12px; padding: 8px 12px; font-size: calc(12.5px * var(--fs, 1)); line-height: 1.5; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: calc(14px * var(--fs, 1)); opacity: 0; transition: all .3s var(--ease); z-index: 99; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #b42318; }

@media (max-width: 700px) {
  html { overflow: auto; }
  body { overflow: auto; }
  .app { overflow: visible; }
  .app { grid-template-columns: 1fr; grid-template-rows: 52vh auto; grid-template-rows: 52dvh auto; }
  .stage { order: -1; }
  .side { border-right: 0; overflow: visible; }
  .top-links a:not(.btn-line) { display: none; }
  .struct-grid { grid-template-columns: repeat(4, 1fr); }
  .explode input { width: 80px; }
  .stage { position: sticky; top: 0; z-index: 3; }
}

.panel { display: flex; flex-direction: column; gap: 12px; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 1 30%; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: calc(13.5px * var(--fs, 1)); cursor: pointer; margin-right: 12px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--purple); }
.colors.two { grid-template-columns: repeat(2, 1fr); }
.param select { grid-column: span 3; padding: 5px 8px; }
.cut table { width: 100%; border-collapse: collapse; font-size: calc(12.5px * var(--fs, 1)); }
.cut th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 4px 2px; }
.cut td { border-bottom: 1px dashed var(--line); padding: 5px 2px; vertical-align: top; }
.cut td small { display: block; color: var(--muted); font-size: calc(11px * var(--fs, 1)); }
.cut td:nth-child(2), .cut td:nth-child(3), .cut th:nth-child(2), .cut th:nth-child(3) { text-align: right; white-space: nowrap; }
.cut .srow { display: flex; justify-content: space-between; font-size: calc(12.5px * var(--fs, 1)); padding-top: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }


/* v2.0 — job selector (UI selection) */
.jobs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.job { --c1: #753f97; --c2: #a855f7; position: relative; display: flex; align-items: center; gap: 10px; text-align: left;
  border: 1.5px solid var(--line); background: var(--card); border-radius: 16px; padding: 10px 12px; cursor: pointer; overflow: hidden;
  transition: transform .25s var(--ease), box-shadow .25s var(--ease), border-color .2s, background .25s; }
.job.j-letters { grid-column: span 2; }
.job.j-lightbox { --c1: #be185d; --c2: #f472b6; }
.job.j-stand { --c1: #15803d; --c2: #61ba46; }
.job.j-keychain { --c1: #c2410c; --c2: #fb923c; }
.job.j-parts { --c1: #0369a1; --c2: #00a7e5; }
.job-ic { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--c1);
  background: color-mix(in srgb, var(--c2) 16%, #fff); transition: background .25s, color .25s, transform .3s var(--ease); }
.job-ic svg { width: 26px; height: 26px; }
.job-tx { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.job-tx b { font-size: calc(14.5px * var(--fs, 1)); color: var(--ink); }
.job-tx small { font-size: calc(11.5px * var(--fs, 1)); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--c2) 55%, #fff); box-shadow: 0 8px 20px -10px var(--c1); }
.job:hover .job-ic { transform: rotate(-6deg) scale(1.06); }
.job.on { border-color: transparent; background: linear-gradient(135deg, var(--c1), var(--c2)); box-shadow: 0 10px 24px -10px var(--c1); }
.job.on .job-ic { background: rgba(255,255,255,.22); color: #fff; }
.job.on .job-tx b, .job.on .job-tx small { color: #fff; }
.job.on::after { content: ''; position: absolute; inset: 0; background: linear-gradient(115deg, transparent 30%, rgba(255,255,255,.28) 45%, transparent 60%);
  transform: translateX(-100%); animation: shine 1.1s var(--ease) .05s 1; pointer-events: none; }
@keyframes shine { to { transform: translateX(100%); } }

/* visual pickers (structure / stand / keychain / part types) */
.picker { display: grid; gap: 8px; }
.picker.cols2 { grid-template-columns: repeat(2, 1fr); }
.picker.cols3 { grid-template-columns: repeat(3, 1fr); }
.pick { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 6px 7px; border: 1.5px solid var(--line);
  border-radius: 14px; background: var(--card); cursor: pointer; transition: transform .2s var(--ease), border-color .2s, box-shadow .2s; }
.pick-ic { width: 100%; aspect-ratio: 60 / 42; border-radius: 10px; background: linear-gradient(180deg, #f6f3fa, #eef3f8); display: grid; place-items: center; overflow: hidden; }
.pick-ic svg { width: 88%; height: auto; }
.pick-lb { font-size: calc(12px * var(--fs, 1)); font-weight: 600; line-height: 1.25; text-align: center; color: #3c4453; }
.pick:hover { transform: translateY(-2px); border-color: #c9b3d8; box-shadow: 0 6px 16px -10px rgba(117,63,151,.6); }
.pick.on { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(117,63,151,.14); }
.pick.on .pick-lb { color: var(--purple); }
.pick.on::after { content: '✓'; position: absolute; top: 5px; right: 5px; width: 18px; height: 18px; border-radius: 50%; background: var(--purple); color: #fff;
  font-size: calc(11px * var(--fs, 1)); display: grid; place-items: center; font-weight: 700; }

/* structure grid (letters) uses the same look */
.struct-grid { grid-template-columns: repeat(4, 1fr); gap: 8px; }
.struct { border-radius: 12px; padding: 5px; background: linear-gradient(180deg, #fff, #f6f3fa); }
.struct.on::after { content: '✓'; position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%; background: var(--purple); color: #fff; font-size: calc(11px * var(--fs, 1)); display: grid; place-items: center; font-weight: 700; }

.panel { display: flex; flex-direction: column; gap: 12px; }
.seg.wrap { flex-wrap: wrap; }
.seg.wrap button { flex: 1 1 30%; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: calc(13.5px * var(--fs, 1)); cursor: pointer; margin-right: 12px; user-select: none; position: relative; }
.toggle input { position: absolute; left: 0; top: 50%; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.toggle .sw { width: 34px; height: 20px; border-radius: 999px; background: #d5dbe3; position: relative; transition: background .2s; flex: none; }
.toggle .sw::after { content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .25s var(--ease); }
.toggle input:checked + .sw { background: var(--purple); }
.toggle input:checked + .sw::after { transform: translateX(14px); }
.toggle input:focus-visible + .sw { outline: 2px solid var(--blue); outline-offset: 2px; }
.colors.two { grid-template-columns: repeat(2, 1fr); }
.swatch { display: flex; align-items: center; gap: 8px; font-size: calc(12.5px * var(--fs, 1)); color: var(--muted); }
.swatch input { width: 38px; height: 30px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--card); cursor: pointer; flex: none; }
.param.sel { grid-template-columns: 1fr 2fr; }
.param select { grid-column: span 3; padding: 5px 8px; }
.param.sel select { grid-column: auto; }
input.txt { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fbfcfd; font-size: calc(16px * var(--fs, 1)); font-weight: 600; outline: none; }
input.txt:focus { border-color: var(--purple); background: var(--card); }
.row.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: flex; flex-direction: column; align-items: flex-start; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 5px 10px; cursor: pointer; font-weight: 600; font-size: calc(13px * var(--fs, 1)); line-height: 1.2; }
.chip small { font-weight: 500; font-size: calc(10.5px * var(--fs, 1)); color: var(--muted); }
.chip.on { border-color: var(--green); background: #f3fbf0; color: #2f7d1d; }
.card h3 small { font-weight: 500; margin-left: 6px; }

/* cut list table */
.cut table { width: 100%; border-collapse: collapse; font-size: calc(12.5px * var(--fs, 1)); }
.cut th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--line); padding: 4px 2px; }
.cut td { border-bottom: 1px dashed var(--line); padding: 5px 2px; vertical-align: top; }
.cut td small { display: block; color: var(--muted); font-size: calc(11px * var(--fs, 1)); }
.cut td:nth-child(2), .cut td:nth-child(3), .cut th:nth-child(2), .cut th:nth-child(3) { text-align: right; white-space: nowrap; }
.cut .srow { display: flex; justify-content: space-between; font-size: calc(12.5px * var(--fs, 1)); padding-top: 6px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small.on, #glyphBtn.on { border-color: var(--purple); color: var(--purple); background: #faf6fd; }

/* glyph positioning tool */
.glyph-panel { border: 1px dashed #cdbbdb; border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 10px; background: #fcfaff; }
.glyphs { display: flex; flex-wrap: wrap; gap: 4px; }
.glyph { min-width: 34px; height: 36px; border: 1.5px solid var(--line); background: var(--card); border-radius: 9px; font-size: calc(18px * var(--fs, 1)); font-weight: 600; cursor: pointer; padding: 0 6px; }
.glyph.mark { color: var(--purple); background: #f6f0fb; font-size: calc(16px * var(--fs, 1)); }
.glyph.moved { border-style: dashed; border-color: var(--blue); }
.glyph.on { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(117,63,151,.16); }
.nudge { display: flex; gap: 12px; align-items: center; }
.pad { display: grid; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(3, 34px); gap: 3px; flex: none; }
.pad button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; cursor: pointer; font-size: calc(13px * var(--fs, 1)); }
.pad button:hover { border-color: var(--purple); color: var(--purple); }
.pad b { display: grid; place-items: center; font-size: calc(20px * var(--fs, 1)); color: var(--purple); }
.nudge-info { display: flex; flex-direction: column; gap: 6px; font-size: calc(12.5px * var(--fs, 1)); flex: 1; min-width: 0; }

/* v2.0 — picture tiles (stand / keychain / parts pickers) */
.tiles { display: grid; grid-template-columns: repeat(var(--cols, 3), minmax(0, 1fr)); gap: 6px; }
.tile { display: flex; flex-direction: column; align-items: center; gap: 4px; border: 1.5px solid var(--line); background: var(--card); border-radius: 12px;
  padding: 8px 4px 6px; cursor: pointer; color: #475569; font-size: calc(11.5px * var(--fs, 1)); font-weight: 600; line-height: 1.2; text-align: center;
  transition: transform .15s var(--ease), border-color .2s, box-shadow .2s, background .2s; }
.tile svg { width: 34px; height: 30px; }
.tile span { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.tile:hover { transform: translateY(-2px); border-color: #c9b3d8; box-shadow: 0 6px 16px -10px rgba(117,63,151,.6); }
.tile.on { border-color: var(--purple); color: var(--purple); background: linear-gradient(180deg, #faf6fd, #f3eafa); box-shadow: 0 0 0 3px rgba(117,63,151,.14); }
.tile.on svg { transform: scale(1.06); }
.color-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: calc(13px * var(--fs, 1)); color: #3c4453; }
.color-row input { width: 46px; height: 30px; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--card); cursor: pointer; }
.chip { flex-direction: row; align-items: center; gap: 6px; }
.chip svg { width: 22px; height: 22px; }

.card h4.sub { margin: 4px 0 0; font-size: calc(13px * var(--fs, 1)); color: var(--purple); }

/* ===== Night mode (dark UI + night scene) ===== */
html.night { --ink: #e6e9f0; --muted: #9aa3b5; --line: #2b3242; --bg: #0d111a; --card: #161b27; color-scheme: dark; }
html.night .top, html.night .side { background: var(--card); }
html.night .pick-ic { background: linear-gradient(180deg, #1f2533, #1a2030); }
html.night .pick-lb, html.night .tile { color: #cfd5e2; }
html.night input[type=number], html.night input[type=text], html.night input.txt, html.night select, html.night textarea { background: #0f141e; color: var(--ink); border-color: var(--line); }
html.night input[type=color] { background: #0f141e; border-color: var(--line); }
html.night h3, html.night .card h3, html.night h4.sub { color: #c39be0; }
html.night .seg { background: #0f141e; }
html.night .seg button { color: #9aa3b5; }
html.night .seg button.on { background: #2a2140; color: #e2c8f5; box-shadow: none; }
html.night .seg.dark { background: rgba(20,24,32,.72); }
html.night .seg.dark button.on { background: var(--purple); color: #fff; }
html.night .param span, html.night .slider span, html.night .color-row, html.night label { color: #cfd5e2; }
html.night .badge, html.night .status { background: rgba(22,27,39,.85); border-color: var(--line); color: var(--ink); }
html.night .status.ok { color: #7bd660; } html.night .status.err { color: #ff8a80; }
html.night .slider output { color: #c39be0; }
html.night .struct { background: linear-gradient(180deg, #1f2533, #1a2030); }
html.night .tile.on, html.night .btn.small.on, html.night #glyphBtn.on { background: #2a2140; color: #e2c8f5; }
html.night .chip.on { background: #1d3318; color: #9be07f; }
html.night .drop:hover, html.night .glyph-panel { background: #1a1f2c; }
html.night .glyph.mark { background: #2a2140; }
html.night .btn:hover { color: #e2c8f5; }
html.night .job:not(.on) .job-tx small { color: var(--muted); }
html.night .warnings { background: #3a2f12; border-color: #6b5420; color: #f5d68a; }
html.night .toggle .sw { background: #3a4254; }
#nightBtn.on { background: #1e2a4a; color: #ffd76a; }

/* LED plan */
.led-svg { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 6px; max-height: 320px; overflow: auto; }
.led-svg svg { width: 100%; height: auto; display: block; }

/* ===== iPad / tablet & touch (v2.4.1) ===== */
.struct-grid { grid-template-columns: repeat(3, 1fr); }
html, body { height: 100%; }
body { height: 100dvh; }
@media (min-width: 701px) and (max-width: 1100px) {
  .app { grid-template-columns: calc(320px * (0.55 + 0.45 * var(--fs, 1))) 1fr; }          /* iPad portrait keeps the 3D view beside the panel */
  .top-links a:not(.btn-line) { display: none; }
}
@media (max-width: 1366px) {
  /* one scrollable row of view buttons instead of two rows covering the model */
  .hud.bottom { flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start; max-width: calc(100% - 20px); padding: 2px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .hud.bottom::-webkit-scrollbar { display: none; }
  .hud.bottom > * { flex: 0 0 auto; }
  .hud.bottom button { white-space: nowrap; }
  .explode span { display: none; }
  .explode input { width: 90px; }
}
@media (pointer: coarse) {
  input[type=number], input[type=text], input.txt, select, textarea { font-size: calc(16px * var(--fs, 1)); }   /* iOS zooms the page on smaller inputs */
  input[type=range] { height: 32px; }
  input[type=range]::-webkit-slider-thumb { width: 26px; height: 26px; }
  button, .btn, .seg button, .pick, .struct, .tile, .job, label.toggle, select { touch-action: manipulation; }
  .seg button, .btn.small, .btn.pill { min-height: 40px; }
  .struct:hover { transform: none; }
  .toggle .sw { transform: scale(1.15); }
  .side { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
}

/* ===== LED catalog (v2.5) ===== */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head h3 { margin: 0; }
.led-item { display: flex; align-items: center; gap: 6px; }
.led-item i, .cat-colors i, .cat-list i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.15); flex: none; }
dialog.catalog { border: 0; border-radius: 16px; padding: 0; width: min(860px, 96vw); max-height: 92vh; max-height: 92dvh; background: var(--card); color: var(--ink); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
dialog.catalog::backdrop { background: rgba(10,14,22,.55); backdrop-filter: blur(3px); }
.cat-wrap { display: flex; flex-direction: column; max-height: 92vh; max-height: 92dvh; }
.cat-wrap header, .cat-wrap footer { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.cat-wrap footer { border-top: 1px solid var(--line); border-bottom: 0; }
.cat-wrap header h3 { margin: 0; flex: 1; color: var(--purple); }
.cat-colors { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 16px 0; }
.cat-colors.small { padding: 0; }
.cat-colors button { display: inline-flex; align-items: center; gap: 5px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 4px 10px; font: inherit; font-size: calc(12.5px * var(--fs, 1)); cursor: pointer; }
.cat-colors button.on { border-color: var(--purple); color: var(--purple); font-weight: 700; }
.cat-body { display: grid; grid-template-columns: 280px 1fr; gap: 14px; padding: 12px 16px; overflow: auto; min-height: 0; }
.cat-list { display: flex; flex-direction: column; gap: 6px; overflow: auto; max-height: 56vh; }
.cat-list button[data-s] { display: flex; gap: 8px; align-items: center; text-align: left; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); border-radius: 10px; padding: 8px 10px; font: inherit; cursor: pointer; }
.cat-list button[data-s].on { border-color: var(--purple); box-shadow: 0 0 0 3px rgba(117,63,151,.12); }
.cat-list b { display: block; font-size: calc(13.5px * var(--fs, 1)); }
.cat-list small { color: var(--muted); font-size: calc(12px * var(--fs, 1)); }
.cat-edit { display: flex; flex-direction: column; gap: 8px; }
.cat-edit input[type=text] { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.cat-grid label { display: grid; grid-template-columns: 1fr 90px 36px; align-items: center; gap: 6px; font-size: calc(13px * var(--fs, 1)); }
.cat-grid input { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; width: 100%; box-sizing: border-box; }
.cat-grid em { font-style: normal; color: var(--muted); font-size: calc(12px * var(--fs, 1)); }
.cat-err { color: #b42318; font-size: calc(13px * var(--fs, 1)); margin: 0; min-height: 1em; }
.btn.danger { background: #b42318; color: #fff; border-color: #b42318; }
@media (max-width: 700px) { .cat-body { grid-template-columns: 1fr; } .cat-list { max-height: 30vh; } .cat-grid { grid-template-columns: 1fr; } }
@media (pointer: coarse) { .cat-grid input, .cat-edit input[type=text] { font-size: calc(16px * var(--fs, 1)); } .cat-list button[data-s] { min-height: 48px; } }
html.night dialog.catalog { background: var(--card); }
html.night .cat-grid input, html.night .cat-edit input[type=text] { background: #0f141e; color: var(--ink); border-color: var(--line); }
html.night .cat-colors button, html.night .cat-list button[data-s] { background: #1a2030; color: var(--ink); }

/* ===== LED page (v2.7) ===== */
.led-open { display: block; width: 100%; padding: 0; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; cursor: zoom-in; position: relative; overflow: hidden; }
.led-open svg { width: 100%; height: auto; display: block; max-height: 220px; }
.led-open span { position: absolute; right: 8px; bottom: 8px; background: rgba(17,24,39,.78); color: #fff; font-size: calc(12px * var(--fs, 1)); padding: 4px 8px; border-radius: 999px; }
.led-page-btn { width: 100%; background: linear-gradient(135deg, #facc15, #f59e0b); color: #1f2937; font-weight: 700; border: 0; }
dialog.ledpage { border: 0; padding: 0; width: 100vw; height: 100vh; height: 100dvh; max-width: 100vw; max-height: 100vh; max-height: 100dvh; background: var(--card); color: var(--ink); }
dialog.ledpage::backdrop { background: rgba(10,14,22,.6); }
.lp-wrap { display: flex; flex-direction: column; height: 100%; }
.lp-wrap header { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.lp-wrap header h3 { margin: 0; color: var(--purple); }
.lp-zoom { display: flex; gap: 6px; margin-left: auto; }
.lp-body { flex: 1; display: grid; grid-template-columns: 1fr 340px; min-height: 0; }
.lp-canvas { position: relative; overflow: hidden; background: #d9dde3; touch-action: none; cursor: crosshair; user-select: none; -webkit-user-select: none; }
.lp-canvas svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.lp-canvas[data-tool="pan"] { cursor: grab; }
.lp-canvas[data-tool="del"] { cursor: not-allowed; }
.lp-canvas.panning { cursor: grabbing !important; }
.lp-canvas svg .led { transition: opacity .1s; }
.lp-canvas[data-tool="del"] svg .led:hover, .lp-canvas[data-tool="edit"] svg .led:hover { opacity: .45; }
.lp-tools button { white-space: nowrap; }
.lp-undo { display: flex; gap: 6px; }
.lp-undo button:disabled { opacity: .4; cursor: default; }
.lp-num { margin: 0 4px; font-size: calc(13px * var(--fs, 1)); }
#lpZoomTx { min-width: 46px; text-align: center; align-self: center; }
.lp-hint { position: absolute; left: 12px; bottom: 10px; margin: 0; background: rgba(17,24,39,.8); color: #fff; font-size: calc(12.5px * var(--fs, 1)); padding: 6px 10px; border-radius: 8px; pointer-events: none; }
.lp-side { border-left: 1px solid var(--line); padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
@media (max-width: 800px) { .lp-body { grid-template-columns: 1fr; grid-template-rows: 55% 45%; } .lp-side { border-left: 0; border-top: 1px solid var(--line); } }
html.night .lp-canvas { background: #0b1020; }
html.night .led-open { background: #0f141e; }
@media (max-width: 1100px) { .hud.top-right { top: 54px; max-width: calc(100% - 130px); } .hud.top-right .status { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; } }

/* ===== LED page v2.8: move / select, legend, help ===== */
.lp-canvas[data-tool="move"] { cursor: default; }
.lp-canvas[data-tool="move"] svg .led { cursor: grab; }
.lp-canvas.moving, .lp-canvas.moving svg .led { cursor: grabbing !important; }
.lp-canvas[data-tool="add"] { cursor: copy; }
.lp-canvas svg .led.sel { stroke: #111827 !important; stroke-width: 4 !important; filter: drop-shadow(0 0 3px rgba(117,63,151,.9)); }
.lp-canvas svg .led.bad { fill: #fecaca !important; stroke: #dc2626 !important; }
.lp-canvas[data-tool="move"] svg .led:hover { opacity: .75; }
.lp-sel { border: 1.5px solid var(--purple); border-radius: 10px; padding: 8px 10px; background: rgba(117,63,151,.06); font-size: calc(13.5px * var(--fs, 1)); }
.lp-sel .row { margin-top: 6px; }
.lp-legend { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: calc(13px * var(--fs, 1)); }
.lp-legend summary { cursor: pointer; font-weight: 700; color: var(--purple); }
.lp-legend ul, .help .legend { margin: 6px 0; padding-left: 0; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.lp-legend li, .help .legend li { display: flex; gap: 8px; align-items: flex-start; }
i.lg { flex: none; width: 26px; height: 12px; margin-top: 4px; }
i.lg.solid { border-top: 3px solid #e11d48; }
i.lg.dash { border-top: 3px dashed #2563eb; }
i.lg.psu { background: #111827; border-radius: 3px; height: 12px; }
i.lg.man { border: 2px dashed #16a34a; border-radius: 3px; background: #f8fafc; }
.help-btn { border: 1.5px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: calc(14px * var(--fs, 1)); cursor: pointer; }
.help-btn:hover { border-color: var(--purple); color: var(--purple); }
dialog.help { border: 0; border-radius: 16px; padding: 0; width: min(760px, 96vw); max-height: 90vh; max-height: 90dvh; background: var(--card); color: var(--ink); box-shadow: 0 30px 80px rgba(0,0,0,.35); }
dialog.help::backdrop { background: rgba(10,14,22,.55); }
.help-wrap { display: flex; flex-direction: column; max-height: 90vh; max-height: 90dvh; }
.help-wrap header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.help-wrap header h3 { margin: 0; color: var(--purple); }
.help-wrap nav { margin: 10px 16px 0; }
.help-body { padding: 4px 16px 16px; overflow-y: auto; line-height: 1.6; font-size: calc(14px * var(--fs, 1)); }
.help-body h4 { margin: 14px 0 6px; color: var(--purple); }
.help-body ol.steps { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
table.keys { width: 100%; border-collapse: collapse; font-size: calc(13.5px * var(--fs, 1)); }
table.keys td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.keys td:first-child { white-space: nowrap; width: 1%; }
kbd { display: inline-block; min-width: 20px; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; background: #f8fafc; font: 600 12px/1.6 ui-monospace, Menlo, monospace; text-align: center; color: #111827; }
html.night kbd { background: #1f2533; color: var(--ink); }
.lp-angbtn { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.lp-angbtn .btn { padding: 4px 8px; min-height: 32px; }
.lp-ang { margin-top: 6px; }
/* LED presets */
.pchips { display: flex; flex-wrap: wrap; gap: 6px; }
.pchip { position: relative; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px; padding: 5px 10px; font: inherit; font-size: calc(12.5px * var(--fs, 1)); cursor: pointer; }
.pchip:hover { border-color: #c9b3d8; }
.pchip.on { border-color: var(--purple); background: rgba(117,63,151,.1); color: var(--purple); font-weight: 700; }
.pchip i[data-delpreset] { font-style: normal; margin-left: 6px; color: #b42318; font-weight: 700; }
.psave { display: flex; gap: 6px; }
.psave input { flex: 1; min-width: 0; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
html.night .pchip { background: #1a2030; }
html.night .psave input { background: #0f141e; color: var(--ink); border-color: var(--line); }
.undo-grp { display: inline-flex; gap: 4px; }
.help-btn:disabled { opacity: .4; cursor: default; border-color: var(--line); color: var(--muted); }
@media (max-width: 700px) { .help-btn .lbl-t { display: none; } }
/* bigger UI text (ก ก ก) */
:root { --fs: 1; }
body { font-size: calc(14px * var(--fs, 1)); }
.side { width: auto; }
.fs-grp { display: inline-flex; gap: 2px; align-items: center; }
.fs-grp .help-btn { padding: 2px 9px; line-height: 1.4; }
.fs-grp .help-btn.on { border-color: var(--purple); color: var(--purple); font-weight: 700; }
@media (max-width: 700px) { .fs-grp .help-btn:nth-child(1) { display: none; } }

/* v2.9.3 wire on/off */
.wire-tg { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin: 6px 0 2px; padding: 8px 10px; border: 1px solid var(--line, #dfe3ea); border-radius: 10px; }
.wire-tg .lbl { width: 100%; font-size: .85em; opacity: .75; }
.wire-tg .toggle { margin: 0; }

/* v2.9.4 typed values for spacing / line height */
.slider .numin { display: inline-flex; align-items: center; gap: 4px; }
.slider .numin input { width: 76px; padding: 5px 6px; border: 1px solid var(--line, #dfe3ea); border-radius: 8px; font: inherit; text-align: right; color: var(--purple); font-variant-numeric: tabular-nums; background: #fff; }
.slider .numin input:focus { outline: 2px solid #00A7E5; outline-offset: 0; }
.slider .numin i { font-style: normal; opacity: .7; min-width: 18px; }
html.night .slider .numin input { background: #0f141e; color: #c39be0; border-color: var(--line); }
@media (pointer: coarse) { .slider .numin input { width: 84px; padding: 8px; font-size: calc(16px * var(--fs, 1)); } }
