/* SPDX-License-Identifier: Apache-2.0 */
/* MonzBoard — a charcoal bar over a warm paper board, terracotta for what is chosen. The board stays light (it is
   paper); the chrome follows the system. */
:root {
  --bar: #1f2228; --bar-ink: #eceae4; --bar-ink-2: #9a978f;
  --panel: #ffffff; --ink: #1f2228; --ink-2: #6b665d; --line: #e2ddd3; --hover: #f3f0ea;
  --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: #262a31; --ink: #eceae4; --ink-2: #a39f96; --line: #383d46; --hover: #30353d; --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 1fr; grid-template-columns: minmax(0, 1fr); background: #f3f1ec; 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: 6px; 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(260px, 32vw); min-width: 60px; }
.bname::placeholder { color: var(--bar-ink-2); }
.bname:hover { border-color: #3a3e46; } .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: #2f333b; }
.bar .ib:disabled { opacity: .35; cursor: default; }
.bar .tb { border-color: #3a3e46; color: var(--bar-ink); }
.bar .tb:hover { background: #2f333b; }

.ib { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 34px; height: 34px; padding: 0 6px; border: 0; border-radius: 8px; background: none; cursor: pointer; color: var(--ink); }
.ib:hover { background: var(--hover); }
.ib.on { background: var(--accent-soft); color: var(--accent); }
.tb { height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 8px; background: none; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.tb:hover { background: var(--hover); }
.tb.primary, .bar .tb.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tb.primary:hover { filter: brightness(1.06); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---- the board ---- */
.stage { position: relative; overflow: hidden; touch-action: none; }
#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; margin: 0; border: 0; outline: 1.5px solid var(--accent); resize: none; overflow: hidden; line-height: 1.3; font-family: var(--font); transform-origin: center center; z-index: 3; white-space: pre-wrap; overflow-wrap: anywhere; }
.editor.ed-frame, .editor.ed-line { border-radius: 4px; box-shadow: var(--shadow); overflow: auto; }

/* ---- tool dock (bottom centre) ---- */
.dock { position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; align-items: center; gap: 2px; padding: 5px; background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); z-index: 4; max-width: calc(100% - 16px); overflow-x: auto; scrollbar-width: none; }
.dock::-webkit-scrollbar { display: none; }
.tool { position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 52px; padding: 6px 4px 4px; border: 0; border-radius: 10px; background: none; cursor: pointer; color: var(--ink); flex: none; }
.tool:hover { background: var(--hover); }
.tool.on { background: var(--accent); color: var(--accent-ink); }
.tool .lbl { font-size: 11px; line-height: 1.1; white-space: nowrap; opacity: .85; }
.tool .dot { position: absolute; top: 5px; right: 9px; width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 0 1.5px var(--panel); }
.dock .sep, .ctxbar .sep { width: 1px; align-self: stretch; margin: 4px 3px; background: var(--line); flex: none; }

/* ---- zoom (bottom right) ---- */
.zoom { position: absolute; right: 14px; bottom: max(14px, env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 0; padding: 3px; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); z-index: 4; }
.zoom .pct { min-width: 54px; height: 34px; border: 0; background: none; cursor: pointer; font-variant-numeric: tabular-nums; border-radius: 8px; }
.zoom .pct:hover { background: var(--hover); }

/* ---- the bar over the selection ---- */
.ctxbar { position: absolute; display: flex; align-items: center; gap: 2px; padding: 4px; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); z-index: 4; white-space: nowrap; }
.ctxbar.docked { left: 8px !important; right: 8px; top: 8px !important; overflow-x: auto; scrollbar-width: none; }
.ctxbar .count { padding: 0 8px; color: var(--ink-2); font-size: 13px; }
.ctxbar select.size { height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 0 4px; cursor: pointer; }
.swatch { display: block; width: 20px; height: 20px; border-radius: 50%; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .18); }
.swatch.none, .sw.none { background: linear-gradient(135deg, transparent 45%, #d33 45%, #d33 55%, transparent 55%), var(--panel) !important; }

/* ---- pop-ups ---- */
.pop { position: fixed; z-index: 20; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; max-width: calc(100vw - 16px); }
.row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.col { display: flex; flex-direction: column; gap: 6px; }
.sw-row { max-width: 232px; }
.sw { width: 30px; height: 30px; border-radius: 50%; border: 0; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .18); }
.sw.sticky-sw { border-radius: 6px; }
.sw.on { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--accent); }
.menu { display: flex; flex-direction: column; min-width: 220px; }
.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: 96px; 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; }

.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 10px; 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; margin-top: 12px; }

/* ---- phones ---- */
@media (max-width: 640px) {
  .bar { gap: 2px; padding-left: 4px; padding-right: 4px; }
  .brand { 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; }
  .dock { left: 0; right: 0; bottom: 0; transform: none; max-width: none; border-radius: 0; padding: 4px 6px max(4px, env(safe-area-inset-bottom)); box-shadow: 0 -1px 0 var(--line); }
  .tool { min-width: 50px; }
  .zoom { bottom: calc(68px + env(safe-area-inset-bottom)); right: 8px; }
  .zoom .ib:first-child, .zoom .ib:nth-child(3) { display: none; }
  .toast { bottom: 140px; }
}
@media (pointer: fine) { .tool.multi { display: none; } }
