:root {
  --bg: #f4f2ea;
  --surface: #ffffff;
  --ink: #1f1d2b;
  --muted: #6b6878;
  --line: #e2ddcf;
  --accent: #5b3fd1;
  --accent-ink: #ffffff;
  --top: #2b2350;
  --top-ink: #f5f2ff;
  --panel-w: 330px;
  --radius: 12px;
  --font: "Noto Sans", "Noto Sans Devanagari", system-ui, -apple-system, "Segoe UI", sans-serif;
  --deva: "Noto Sans Devanagari", "Noto Sans", "Nirmala UI", "Mangal", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17151f; --surface: #221f2d; --ink: #ece9f6; --muted: #a29fb2; --line: #34304a;
    --accent: #8f7bff; --top: #120f1d;
  }
}
:root[data-theme="dark"] { --bg: #17151f; --surface: #221f2d; --ink: #ece9f6; --muted: #a29fb2; --line: #34304a; --accent: #8f7bff; --top: #120f1d; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 15px; -webkit-text-size-adjust: 100%; }
button { font: inherit; }

/* ---------- top bar ---------- */
.topbar {
  height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 12px;
  padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right));
  background: var(--top); color: var(--top-ink); position: relative; z-index: 5;
}
.brand { min-width: 0; flex: 1; }
.brand h1 { margin: 0; font-size: 16px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: .2px; }
.brand h1 span { font-weight: 400; opacity: .8; }
.status { margin: 1px 0 0; font-size: 12px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 6px; }
.btn { border: 1px solid rgba(255,255,255,.28); background: transparent; color: inherit; border-radius: 8px; padding: 7px 12px; cursor: pointer; font-size: 13px; }
.btn:hover { background: rgba(255,255,255,.1); }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); display: grid; place-items: center; cursor: pointer; font-size: 18px; font-weight: 600; line-height: 1; }
.topbar .icon-btn { background: transparent; color: var(--top-ink); border-color: rgba(255,255,255,.28); }
.icon-btn:hover { border-color: var(--accent); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: var(--panel-w) 1fr; height: calc(100vh - 56px); height: calc(100dvh - 56px); }
.panel { overflow-y: auto; overflow-x: hidden; padding: 12px; border-right: 1px solid var(--line); background: var(--bg); overscroll-behavior: contain; }
body.panel-collapsed .layout { grid-template-columns: 0 1fr; }
body.panel-collapsed .panel { padding: 0; overflow: hidden; border: 0; }
.stage { position: relative; min-width: 0; min-height: 0; }
.graph { position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; background: rgb(252,252,225); outline: none; }
.graph-svg { position: absolute; inset: 0; display: block; }
.graph-svg .grid-minor { stroke: rgba(192,192,192,.45); stroke-width: .6; }
.graph-svg .grid-major { stroke: rgb(192,192,192); stroke-width: 1; }
.graph-svg .axis-num text { font-family: var(--font); }
.graph-overlay { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.g-text, .g-label { position: absolute; white-space: pre; line-height: 1.22; font-family: var(--deva); }
.g-text.has-bg { padding: 0 2px; }
.g-label sub { font-size: .7em; vertical-align: -0.25em; line-height: 0; }
.graph .loading { position: absolute; inset: 0; display: grid; place-items: center; color: #6b6878; font-size: 14px; }
.graph .error { padding: 24px; color: #a00; }

.zoom-bar { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; z-index: 3; }
.zoom-bar .icon-btn { box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.zoom-bar .icon-btn[data-act="original"] { font-size: 12px; }

/* ---------- panel cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.field { margin-bottom: 12px; }
.field[hidden] { display: none; }
.field label { display: flex; justify-content: space-between; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.field .val { font-weight: 400; color: var(--muted); font-variant-numeric: tabular-nums; }
.field-row { display: flex; align-items: center; gap: 6px; }
.num { width: 100%; font: inherit; font-size: 16px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-variant-numeric: tabular-nums; }
.num:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.unit { color: var(--muted); min-width: 10px; }
.range { width: 100%; margin: 8px 0 0; accent-color: var(--accent); height: 22px; }
.field.small label { font-size: 13px; font-weight: 500; }

.groups { display: grid; gap: 10px; }
.group { border: 0; margin: 0; padding: 0; }
.group legend { font-size: 12px; font-weight: 700; color: var(--muted); padding: 0 0 4px; }
.cb { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 8px; cursor: pointer; min-height: 36px; }
.cb:hover { background: var(--bg); }
.cb[hidden] { display: none; }
.cb input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; flex: none; }
.cb .cap { position: relative; padding-left: 12px; font-size: 14px; }
.cb .cap::before { content: ""; position: absolute; left: 0; top: 50%; width: 6px; height: 6px; border-radius: 50%; background: var(--c); transform: translateY(-50%); }
.advanced summary { cursor: pointer; font-weight: 600; font-size: 14px; }
.advanced .hint { color: var(--muted); font-size: 12.5px; }
.adv-grid { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 0 6px; }
.adv-grid .cb { min-width: 0; }
.adv-grid .cb .cap { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group[hidden] { display: none; }
.adv-grid .cb { min-height: 30px; padding: 3px 4px; }
.adv-grid .cb .cap { font-size: 13px; }
.adv-sliders { margin-top: 10px; display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 0 12px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); background: var(--top); color: var(--top-ink); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; z-index: 20; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- tablet / phone ---------- */
@media (max-width: 900px) {
  :root { --panel-w: 290px; }
}
@media (max-width: 760px) {
  .hide-sm { display: none; }
  .brand h1 span { display: none; }
  .layout { display: flex; flex-direction: column; height: auto; }
  .stage { order: -1; position: sticky; top: 0; height: 58vh; height: 58svh; z-index: 2; border-bottom: 1px solid var(--line); }
  .panel { border-right: 0; overflow: visible; padding: 12px max(12px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  body.panel-collapsed .panel { display: none; }
  body.panel-collapsed .stage { height: calc(100svh - 56px); }
  .zoom-bar { right: 8px; bottom: 8px; }
  .icon-btn { width: 40px; height: 40px; }
}
@media (max-width: 420px) {
  .groups { grid-template-columns: 1fr; }
  .top-actions .btn { padding: 7px 9px; }
}

/* ---------- print: graph only ---------- */
@media print {
  .topbar, .panel, .zoom-bar, .toast { display: none !important; }
  .layout { display: block; height: auto; }
  .stage { position: relative; height: 18cm; }
  body { background: #fff; }
}

/* ---------- chakra switch & layer groups ---------- */
.chakra-card { padding: 10px 14px; }
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; min-height: 40px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { flex: none; width: 46px; height: 26px; border-radius: 13px; background: #8a8698; position: relative; transition: background .2s; }
.switch .thumb { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track .thumb { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-text { display: flex; flex-direction: column; line-height: 1.25; }
.switch-text b { font-size: 15px; }
.switch-text small { color: var(--muted); font-size: 12px; }
.group { border-top: 1px solid var(--line); padding-top: 8px; }
.group:first-child { border-top: 0; padding-top: 0; }
.group legend { font-size: 13px; color: var(--ink); float: left; width: 100%; padding: 2px 0 4px; }
.group legend + * { clear: both; }
.group-slider { margin: 6px 4px 4px; }
.adv-grid .cb.orig .cap { font-weight: 700; }

/* ---------- 45 Devta description (beside the plot) ---------- */
.desc-wrap { position: absolute; z-index: 2; display: flex; flex-direction: column; gap: 4px; font-family: var(--deva); color: #1f1d2b; overflow: auto; pointer-events: auto; width: max-content; }
.desc-wrap[hidden] { display: none; }
.desc-title { font-weight: 700; font-size: 1.05em; color: #2b2350; letter-spacing: .02em; }
.desc-box { white-space: pre-line; line-height: 1.4; background: rgba(255,255,248,.96); border: 1.5px solid #6b5bd2; border-radius: 8px; padding: .55em .75em; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.chakra-size { margin: 10px 0 0; }
.chakra-size label { font-size: 13px; }

/* ---------- Export menu ---------- */
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 190px; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25); padding: 6px; z-index: 30; display: flex; flex-direction: column; }
.menu[hidden] { display: none; }
.menu button { text-align: left; background: none; border: 0; color: inherit; padding: 10px 12px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.menu button:hover, .menu button:focus-visible { background: var(--bg); outline: none; }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }

/* ---------- Plot inputs on/off ---------- */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-head h2 { margin: 0; }
.inputs-card #inputs-body { margin-top: 10px; }
#inputs-body[hidden] { display: none; }
.small-switch { min-height: 0; gap: 0; }
.small-switch .track { width: 38px; height: 22px; border-radius: 11px; }
.small-switch .thumb { width: 16px; height: 16px; }
.small-switch input:checked + .track .thumb { transform: translateX(16px); }
