/* SPDX-License-Identifier: Apache-2.0 */
/* MonzVector — a charcoal bar and tool rail around a warm grey pasteboard, the artboard as paper, terracotta for what is
   chosen. The chrome follows the system's light/dark; the artboard keeps its own colour. */
:root {
  --bar: #1f2228; --bar-ink: #eceae4; --bar-ink-2: #9a978f; --bar-hover: #2f333b; --bar-line: #3a3e46;
  --panel: #ffffff; --ink: #1f2228; --ink-2: #6b665d; --line: #e2ddd3; --hover: #f3f0ea; --field: #faf8f4;
  --accent: #e0572b; --accent-ink: #ffffff; --accent-soft: #fbe3d9;
  --shadow: 0 6px 24px rgba(31, 34, 40, .14), 0 1px 3px rgba(31, 34, 40, .12);
  --font: "Sarabun", "Noto Sans Thai", "Leelawadee UI", Tahoma, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --panel: #23272e; --ink: #eceae4; --ink-2: #a39f96; --line: #363b44; --hover: #2d323a; --field: #1c1f25; --accent-soft: #4a2a1e; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overscroll-behavior: none; }
body { display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); background: var(--bar); color: var(--ink); font: 14px/1.4 var(--font); overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.ic { width: 20px; height: 20px; display: block; flex: none; }

/* ---- top bar ---- */
.bar { min-width: 0; overflow: hidden; display: flex; align-items: center; gap: 4px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); background: var(--bar); color: var(--bar-ink); min-height: 48px; z-index: 5; }
.brand { font-size: 16px; letter-spacing: .01em; margin: 0 6px 0 2px; white-space: nowrap; }
.brand b { color: var(--accent); font-weight: 700; }
.bname { background: transparent; border: 1px solid transparent; border-radius: 6px; color: var(--bar-ink); padding: 4px 8px; width: min(240px, 28vw); min-width: 60px; }
.bname::placeholder { color: var(--bar-ink-2); }
.bname:hover { border-color: var(--bar-line); } .bname:focus { outline: none; border-color: var(--accent); background: #2a2e35; }
.grow { flex: 1; }
.bar .ib { color: var(--bar-ink); }
.bar .ib:hover:not(:disabled) { background: var(--bar-hover); }
.bar .ib.on { background: #4a2a1e; color: #ffb59a; }
.bar .ib:disabled { opacity: .35; cursor: default; }
.zoomg { display: flex; align-items: center; }
.pct { min-width: 52px; height: 34px; border: 0; background: none; cursor: pointer; font-variant-numeric: tabular-nums; border-radius: 8px; color: var(--bar-ink); }
.pct:hover { background: var(--bar-hover); }

.ib { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 32px; height: 32px; padding: 0 5px; border: 0; border-radius: 8px; background: none; cursor: pointer; color: var(--ink); flex: none; }
.ib:hover:not(:disabled) { background: var(--hover); }
.ib.on { background: var(--accent-soft); color: var(--accent); }
.ib:disabled { opacity: .35; cursor: default; }
.tb { height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; color: var(--ink); }
.tb:hover { background: var(--hover); }
.tb.on { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.tb.sm { height: 28px; padding: 0 8px; font-size: 13px; }
.tb.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tb.primary:hover { filter: brightness(1.06); }
.tb .ic { width: 18px; height: 18px; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- the work area: rail | canvas | panel ---- */
.work { display: grid; grid-template-columns: auto minmax(0, 1fr) 288px; min-height: 0; }
body.nopanel .work { grid-template-columns: auto minmax(0, 1fr) 0; }
body.nopanel .panel { display: none; }
.rail { display: flex; flex-direction: column; gap: 2px; padding: 6px 5px; background: var(--bar); overflow-y: auto; scrollbar-width: none; z-index: 4; }
.rail::-webkit-scrollbar { display: none; }
.tool { display: flex; flex-direction: column; align-items: center; gap: 1px; width: 50px; padding: 6px 2px 4px; border: 0; border-radius: 10px; background: none; cursor: pointer; color: var(--bar-ink); flex: none; }
.tool:hover { background: var(--bar-hover); }
.tool.on { background: var(--accent); color: var(--accent-ink); }
.tool .lbl { font-size: 10.5px; line-height: 1.1; white-space: nowrap; opacity: .8; }

.stage { position: relative; overflow: hidden; touch-action: none; background: #e4e1da; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
#cv.grabbing { cursor: grabbing !important; }
.stage.drop::after { content: ''; position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 14px; background: rgba(224, 87, 43, .05); pointer-events: none; }
.editor { position: absolute; left: 0; top: 0; margin: 0; padding: 0; border: 0; outline: 1px dashed var(--accent); background: transparent; color: transparent; caret-color: var(--accent); resize: none; overflow: hidden; transform-origin: 0 0; z-index: 3; white-space: pre; }
.editor::selection { background: rgba(224, 87, 43, .25); color: transparent; }

/* the options strip over the canvas */
.opts { position: absolute; left: 10px; top: 10px; right: 10px; display: flex; align-items: center; gap: 6px; padding: 5px 8px; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); z-index: 4; width: max-content; max-width: calc(100% - 20px); overflow-x: auto; scrollbar-width: none; white-space: nowrap; }
.opts::-webkit-scrollbar { display: none; }
.hint { color: var(--ink-2); font-size: 13px; padding: 0 4px; }
.fld { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.fld input[type=number], .fld input[type=text], .lin { width: 64px; height: 28px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); padding: 0 6px; color: var(--ink); }
.fld input[type=range] { width: 90px; accent-color: var(--accent); }
.n3 { width: 56px !important; } .n4 { width: 76px !important; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.chk input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---- the panel ---- */
.panel { background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; overflow-x: hidden; min-width: 0; padding-bottom: env(safe-area-inset-bottom); }
.sec { border-bottom: 1px solid var(--line); }
.sec summary { list-style: none; cursor: pointer; padding: 10px 14px 8px; font-weight: 600; font-size: 13px; letter-spacing: .02em; color: var(--ink-2); display: flex; align-items: center; gap: 6px; user-select: none; }
.sec summary::-webkit-details-marker { display: none; }
.sec summary::before { content: '▸'; font-size: 10px; transition: transform .15s; }
.sec[open] summary::before { transform: rotate(90deg); }
.secb { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.prow { display: flex; align-items: center; gap: 6px; min-width: 0; }
.prow.wrap { flex-wrap: wrap; gap: 2px; }
.plbl { font-size: 13px; color: var(--ink-2); min-width: 46px; }
.pct2 { font-size: 12.5px; color: var(--ink-2); width: 38px; text-align: right; font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; background: var(--field); border: 1px solid var(--line); border-radius: 9px; padding: 1px; }
.seg .ib { height: 28px; min-width: 30px; border-radius: 7px; }
.clr { width: 40px; height: 30px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); cursor: pointer; flex: none; }
.clr::-webkit-color-swatch-wrapper { padding: 0; } .clr::-webkit-color-swatch { border: 0; border-radius: 5px; }
.prow input[type=range] { accent-color: var(--accent); min-width: 0; flex: 1; }
.grad { height: 14px; border-radius: 7px; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
.stop .clr { width: 34px; height: 26px; }
.sel { height: 30px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); padding: 0 6px; min-width: 0; color: var(--ink); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.grid2 .fld { justify-content: space-between; }
.sep { width: 1px; align-self: stretch; margin: 4px 3px; background: var(--line); flex: none; }

.layers { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; max-height: 46vh; overflow-y: auto; }
.lrow, .nrow { display: flex; align-items: center; gap: 0; padding: 1px 6px 1px 2px; cursor: pointer; min-height: 34px; border-bottom: 1px solid var(--line); }
.lrow:last-child, .nrow:last-child { border-bottom: 0; }
.lrow:hover, .nrow:hover { background: var(--hover); }
.lrow.cur { background: var(--accent-soft); }
.lrow.cur .lname { font-weight: 600; }
.nrow { padding-left: 26px; font-size: 13px; min-height: 30px; }
.nrow.on { box-shadow: inset 3px 0 0 var(--accent); background: var(--hover); }
.nrow .ib, .lrow .ib { min-width: 28px; height: 28px; padding: 0 3px; }
.nrow .ib .ic, .lrow .ib .ic { width: 17px; height: 17px; }
.lname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 4px; }
.lin { flex: 1; width: auto; }
.lcount { font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.caret { width: 22px; height: 28px; border: 0; background: none; cursor: pointer; color: var(--ink-2); font-size: 11px; transition: transform .15s; flex: none; }
.caret.open { transform: rotate(90deg); }

/* ---- pop-ups ---- */
.pop { position: fixed; z-index: 20; background: var(--panel); color: var(--ink); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; max-width: calc(100vw - 16px); }
.pop .pad { padding: 6px 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.row.gap { gap: 18px; }
.menu { display: flex; flex-direction: column; min-width: 230px; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }
.mi { display: flex; justify-content: space-between; align-items: center; gap: 18px; padding: 8px 10px; border: 0; border-radius: 8px; background: none; cursor: pointer; text-align: left; }
.mi:hover { background: var(--hover); }
.mi kbd { font: 12px ui-monospace, Consolas, monospace; color: var(--ink-2); }

.toast { position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%); background: var(--bar); color: var(--bar-ink); padding: 8px 14px; border-radius: 10px; box-shadow: var(--shadow); z-index: 6; max-width: calc(100% - 24px); text-align: center; pointer-events: none; white-space: pre-line; }

.dlg { border: 0; border-radius: 16px; box-shadow: var(--shadow); background: var(--panel); color: var(--ink); max-width: min(640px, calc(100vw - 24px)); padding: 18px 20px; }
.dlg::backdrop { background: rgba(20, 22, 26, .4); }
.dlg h2 { margin: 0 0 12px; font-size: 18px; }
.help { max-height: 64vh; overflow: auto; }
.help table { border-collapse: collapse; width: 100%; }
.help td { padding: 4px 8px 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.help td:first-child { white-space: nowrap; color: var(--ink-2); font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.right { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }

/* ---- tablets: the panel floats over the canvas when opened ---- */
@media (max-width: 1100px) {
  .work { grid-template-columns: auto minmax(0, 1fr) 0; }
  .panel { position: fixed; right: 0; top: 48px; bottom: 0; width: min(300px, 86vw); z-index: 8; box-shadow: var(--shadow); }
}
/* ---- phones: the rail goes along the bottom ---- */
@media (max-width: 640px) {
  .bar { gap: 1px; padding-left: 4px; padding-right: 4px; }
  .brand, .zoomg .ib:first-child, .zoomg .ib:nth-child(3) { display: none; }
  .bname { width: auto; flex: 1 1 0; min-width: 0; }
  .bar .ib { min-width: 30px; padding: 0 3px; }
  .bar .grow { display: none; }
  .bar .tb { padding: 0 8px; }
  .work { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  body.nopanel .work { grid-template-columns: minmax(0, 1fr); }
  .rail { grid-row: 2; flex-direction: row; overflow-x: auto; overflow-y: hidden; padding: 4px 6px max(4px, env(safe-area-inset-bottom)); }
  .stage { grid-row: 1; }
  .tool { width: 48px; }
  .panel { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-height: 62vh; border-left: 0; border-top: 1px solid var(--line); border-radius: 14px 14px 0 0; }
}
