/* OMR Sheet Builder — modern light/dark theme. System fonts only (works offline). */
:root {
  --bg: #f6f7fb; --bg-2: #eef0f7; --surface: #ffffff; --surface-2: #f8f9fc; --border: #e3e6ef; --border-2: #d3d8e6;
  --text: #171a2b; --text-2: #4b5168; --text-3: #7c829a;
  --brand: #5b4bff; --brand-2: #7c6cff; --brand-ink: #ffffff; --brand-soft: #ecebff;
  --ok: #14975a; --ok-soft: #e3f7ec; --bad: #d6374b; --bad-soft: #fde8eb; --warn: #c27a06; --warn-soft: #fff3d9; --info: #2878d8; --info-soft: #e5f0fd;
  --radius: 14px; --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 22, 50, .05), 0 6px 24px -8px rgba(20, 22, 50, .12);
  --shadow-lg: 0 24px 60px -16px rgba(20, 22, 50, .28);
  --font: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Noto Sans', 'Noto Sans Devanagari', Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --side: 248px;
  color-scheme: light;
}
:root[data-theme='dark'] {
  --bg: #0d0f1a; --bg-2: #121527; --surface: #161a2e; --surface-2: #1b2038; --border: #262c48; --border-2: #323a5c;
  --text: #eceefa; --text-2: #b4b9d3; --text-3: #8187a6;
  --brand: #8b7dff; --brand-2: #a598ff; --brand-ink: #0d0f1a; --brand-soft: #25224d;
  --ok: #3ccf8a; --ok-soft: #13332a; --bad: #ff6b7e; --bad-soft: #3a1c27; --warn: #f3b23e; --warn-soft: #3a2e14; --info: #6aa9ff; --info-soft: #172a47;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px -10px rgba(0, 0, 0, .6);
  --shadow-lg: 0 24px 60px -12px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.75rem; } h2 { font-size: 1.3rem; } h3 { font-size: 1.08rem; } h4 { font-size: .95rem; }
p { margin: 0 0 .8em; }
small, .muted { color: var(--text-3); }
code, .mono { font-family: var(--mono); font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* default icon size; specific components override */
svg.ico { width: 1.1em; height: 1.1em; vertical-align: -0.18em; flex: none; }
.alert { display: block; } .alert svg.ico { margin-right: 4px; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 18px 14px; border-right: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 800; font-size: 1.12rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, var(--brand), #c04bff); display: grid; place-items: center; box-shadow: 0 6px 16px -6px var(--brand); }
.brand-mark svg { width: 20px; height: 20px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; color: var(--text-2); font-weight: 550; }
.nav a:hover { background: var(--bg-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav svg { width: 19px; height: 19px; flex: none; }
.side-foot { margin-top: auto; display: grid; gap: 8px; padding: 8px; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 12px clamp(20px, 3vw, 40px); background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.topbar .crumbs { font-weight: 650; color: var(--text-2); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.view { padding: 24px clamp(20px, 3vw, 40px); width: 100%; }
.mobile-nav { display: none; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .78rem; font-weight: 650; background: var(--bg-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }

.icon-btn { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer; }
.icon-btn:hover { color: var(--text); border-color: var(--border-2); text-decoration: none; }
.icon-btn { flex: none; }
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: .92rem; cursor: pointer; transition: transform .06s, background .15s, border-color .15s; white-space: nowrap; }
.btn:hover { border-color: var(--text-3); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: 0 6px 16px -8px var(--brand); }
.btn-primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn-danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--bg-2); border-color: transparent; }
.btn-sm { padding: 5px 11px; font-size: .84rem; border-radius: 8px; }
.btn-lg { padding: 13px 22px; font-size: 1rem; border-radius: 12px; }
.btn-wa { background: #25d366; border-color: #25d366; color: #06301a; }

label.field { display: flex; flex-direction: column; gap: 5px; font-size: .84rem; font-weight: 600; color: var(--text-2); }
label.field code { display: inline; }
input[type=text], input[type=number], input[type=date], input[type=search], input[type=tel], input[type=email], input:not([type]), select, textarea {
  font: inherit; font-size: .93rem; line-height: 1.35; color: var(--text); background-color: var(--surface-2); border: 1px solid var(--border-2); border-radius: 9px; padding: 8px 11px; width: 100%; min-width: 0; min-height: 40px; margin: 0;
  transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover, textarea:hover { border-color: var(--text-3); }
input::placeholder, textarea::placeholder { color: var(--text-3); opacity: 1; }
/* dropdowns: same look in every browser, a clear chevron, text never under the arrow */
select {
  -webkit-appearance: none; -moz-appearance: none; appearance: none; cursor: pointer;
  padding-right: 36px; text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%234b5168' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 16px 16px;
}
:root[data-theme='dark'] select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%23b4b9d3' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
select::-ms-expand { display: none; }
select option, select optgroup { background: var(--surface); color: var(--text); font-size: .93rem; }
select:disabled, input:disabled, textarea:disabled { opacity: .6; cursor: not-allowed; }
.select-sm { width: auto; max-width: 160px; min-height: 36px; padding-top: 6px; padding-bottom: 6px; font-size: .88rem; }
input[type=number] { font-variant-numeric: tabular-nums; padding-right: 6px; }
input[type=file] { font: inherit; font-size: .85rem; color: var(--text-2); max-width: 100%; padding: 6px; border: 1px dashed var(--border-2); border-radius: 9px; background: var(--surface-2); min-height: 40px; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; font-size: .84rem; margin-right: 10px; padding: 6px 12px; border-radius: 7px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
textarea { resize: vertical; min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
input[type=color] { width: 56px; height: 40px; padding: 3px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--surface-2); cursor: pointer; }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); width: 16px; height: 16px; }
.check { display: inline-flex; align-items: flex-start; gap: 8px; font-size: .9rem; color: var(--text); font-weight: 500; cursor: pointer; line-height: 1.35; }
.check input { flex: none; margin: 1px 0 0; }
input[type=range] { accent-color: var(--brand); width: 100%; }

.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--border); gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font: inherit; font-size: .86rem; font-weight: 600; color: var(--text-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- layout ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card-h { display: flex; align-items: center; gap: 12px; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; }
.card-h h2, .card-h h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-end { justify-content: flex-end; }
.stack { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
/* grid/flex children may shrink below their content (wide tables and previews scroll inside instead) */
.grid > *, .stack > *, .row > *, .designer > *, .review > *, .help > *, .tpl-card > *, .feature > *, .panel .body > * { min-width: 0; }
.spacer { flex: 1; }
.page-h { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-h p { color: var(--text-2); margin: 0; }

.hero { position: relative; overflow: hidden; border-radius: 22px; padding: 44px; background: radial-gradient(1200px 400px at 90% -20%, color-mix(in srgb, #c04bff 30%, transparent), transparent), linear-gradient(135deg, var(--brand), #3b2bd6); color: #fff; box-shadow: var(--shadow-lg); }
.hero h1 { font-size: 2.3rem; max-width: 680px; }
.hero p { font-size: 1.08rem; opacity: .9; max-width: 620px; }
.hero .btn { border-color: rgba(255, 255, 255, .55); background: rgba(255, 255, 255, .12); color: #fff; }
.hero .btn:hover { background: rgba(255, 255, 255, .22); border-color: #fff; }
.hero .btn-primary { background: #fff; color: #2d1fc7; border-color: #fff; }
.hero-art { position: absolute; right: -30px; top: 20px; width: 360px; opacity: .95; transform: rotate(8deg); filter: drop-shadow(0 30px 40px rgba(0, 0, 0, .35)); }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 18px; }
.pill-row .badge { background: rgba(255, 255, 255, .16); color: #fff; border-color: rgba(255, 255, 255, .25); }

.feature { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; align-content: start; cursor: pointer; transition: transform .15s, box-shadow .15s; color: var(--text); }
.feature:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); text-decoration: none; }
.feature .ic { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.feature .ic svg { width: 22px; height: 22px; }
.feature p { color: var(--text-2); margin: 0; font-size: .9rem; }

.stat { padding: 16px 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); }
.stat .v { font-size: 1.6rem; font-weight: 800; letter-spacing: -.02em; }
.stat .l { font-size: .8rem; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.tabs a { padding: 10px 14px; color: var(--text-2); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }
.tabs .count { font-size: .72rem; padding: 0 7px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); }

/* ---------- tables ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 70vh; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface-2); font-weight: 700; color: var(--text-2); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; z-index: 1; cursor: default; }
th[data-sort] { cursor: pointer; }
tbody tr:hover { background: var(--bg-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.clickable { cursor: pointer; }

/* ---------- designer ---------- */
.designer { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 20px; align-items: start; }
.panel { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow: auto; padding: 0; }
.panel details { border-bottom: 1px solid var(--border); }
.panel details:last-child { border-bottom: 0; }
.panel summary { padding: 14px 18px; font-weight: 700; cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; }
.panel summary::-webkit-details-marker { display: none; }
.panel summary::after { content: '›'; transform: rotate(90deg); transition: transform .2s; color: var(--text-3); font-size: 1.2rem; }
.panel details[open] summary::after { transform: rotate(-90deg); }
.panel .body { padding: 0 18px 18px; display: grid; gap: 12px; }
.preview-wrap { background: repeating-conic-gradient(var(--bg-2) 0% 25%, var(--bg) 0% 50%) 50% / 22px 22px; border-radius: var(--radius); padding: 24px; display: grid; justify-items: center; gap: 14px; border: 1px solid var(--border); }
.page-tag { justify-self: center; font-size: .8rem; font-weight: 700; color: var(--text-2); background: var(--surface); border: 1px solid var(--border); padding: 3px 12px; border-radius: 99px; margin-top: 6px; }
.page-tag:first-child { margin-top: 0; }
.sheet-preview { width: 100%; max-width: 820px; box-shadow: var(--shadow-lg); border-radius: 4px; background: #fff; line-height: 0; }
.sheet-preview svg { width: 100%; height: auto; display: block; }
.warn-list { display: grid; gap: 6px; }
.sec-row { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(76px, .8fr) minmax(76px, .8fr) minmax(64px, .7fr) 40px; gap: 6px; align-items: center; margin-bottom: 6px; }
.ex-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 6px; margin-top: 6px; }
.sec-head { font-size: .74rem; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 0; }
.sec-row .icon-btn { width: 40px; height: 40px; }
.sec-row select { padding-right: 28px; padding-left: 10px; background-position: right 8px center; }
.sec-row input { padding-left: 10px; padding-right: 8px; }
.alert { padding: 10px 14px; border-radius: 10px; font-size: .88rem; border: 1px solid transparent; }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.alert-bad { background: var(--bad-soft); color: var(--bad); }

.tpl-card { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; color: var(--text); }
.tpl-card .thumb { display: block; aspect-ratio: 210/297; border-radius: 8px; overflow: hidden; background: #fff; border: 1px solid var(--border); line-height: 0; }
.tpl-card .thumb svg { display: block; width: 100%; height: 100%; }
.preset { text-align: left; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; cursor: pointer; font: inherit; color: var(--text); min-width: 0; height: 100%; padding: 16px; transition: border-color .15s, box-shadow .15s, transform .15s; }
.preset:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.preset-name { font-size: .98rem; line-height: 1.3; overflow-wrap: anywhere; }
.preset-meta { font-size: .84rem; color: var(--text-3); }
.preset-note { font-size: .8rem; color: var(--text-2); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.preset .pill { margin-top: auto; }
.presets { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); align-items: stretch; }
/* badges that carry a sentence wrap inside their container instead of running out of it */
.badge.pill { white-space: normal; max-width: 100%; line-height: 1.3; padding: 4px 10px; align-items: flex-start; text-align: left; }
.badge.pill svg { flex: none; margin-top: 1px; }
.badge svg.ico { width: 13px; height: 13px; vertical-align: 0; }
.preset:hover { border-color: var(--brand); }

/* ---------- key entry / bubble grids ---------- */
.key-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 4px 18px; }
.kq { display: flex; align-items: center; gap: 6px; padding: 3px 6px; border-radius: 8px; }
.kq.focus { background: var(--brand-soft); }
.kq .n { width: 34px; text-align: right; font-weight: 700; font-size: .82rem; color: var(--text-2); font-variant-numeric: tabular-nums; }
.bub { width: 26px; height: 26px; border-radius: 50%; border: 1.5px solid var(--border-2); background: var(--surface); font-size: .72rem; font-weight: 700; color: var(--text-3); cursor: pointer; display: inline-grid; place-items: center; padding: 0; font-family: inherit; }
.bub:hover { border-color: var(--brand); color: var(--brand); }
.bub.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.bub.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.bub.bad { background: var(--bad); border-color: var(--bad); color: #fff; }
.bub.key { box-shadow: 0 0 0 2px var(--ok); }
.kq .tag { font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 6px; }
.bub-lg .bub { width: 36px; height: 36px; font-size: .9rem; }

/* ---------- scanning ---------- */
.drop { border: 2px dashed var(--border-2); border-radius: var(--radius); padding: 40px 20px; text-align: center; background: var(--surface-2); transition: border-color .15s, background .15s; cursor: pointer; }
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop svg { width: 42px; height: 42px; color: var(--brand); }
.progress { height: 8px; background: var(--bg-2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), #c04bff); transition: width .2s; border-radius: inherit; }
.sheet-list { display: grid; gap: 6px; }
.sheet-item { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.sheet-item:hover { border-color: var(--border-2); }
.sheet-item.active { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.sheet-item img { width: 44px; height: 60px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); background: #fff; }
.review { display: grid; grid-template-columns: 300px minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.review-img { position: relative; background: #fff; border-radius: 8px; overflow: hidden; line-height: 0; box-shadow: var(--shadow); }
.review-img img { width: 100%; display: block; }
.review-img svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.review-img svg circle { cursor: pointer; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: .8rem; color: var(--text-2); }
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
kbd { font-family: var(--mono); font-size: .75rem; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-2); background: var(--surface-2); border-bottom-width: 2px; }

.camera { position: fixed; inset: 0; z-index: 100; background: #000; }
.camera video, .camera canvas.ov { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.camera .hud { position: absolute; top: 0; left: 0; right: 0; display: flex; justify-content: space-between; padding: 16px; gap: 10px; color: #fff; z-index: 2; }
.camera .hint { position: absolute; left: 50%; top: 70px; transform: translateX(-50%); padding: 8px 16px; border-radius: 99px; background: rgba(0, 0, 0, .55); color: #fff; font-weight: 600; z-index: 2; }
.camera .bar { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; display: flex; justify-content: center; align-items: center; gap: 22px; padding: 18px; background: linear-gradient(transparent, rgba(0, 0, 0, .7)); }
.shutter { width: 70px; height: 70px; border-radius: 50%; border: 5px solid #fff; background: rgba(255, 255, 255, .25); cursor: pointer; }
.camera .flash { position: absolute; inset: 0; display: grid; place-items: center; z-index: 3; pointer-events: none; }
.camera .flash div { background: rgba(10, 12, 24, .85); color: #fff; padding: 22px 34px; border-radius: 18px; text-align: center; font-size: 1.2rem; }
.camera .flash b { display: block; font-size: 2.4rem; }
.camera .icon-btn { background: rgba(0, 0, 0, .45); border-color: rgba(255, 255, 255, .3); color: #fff; }

/* ---------- charts ---------- */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 10px; }
.bars .b { flex: 1; background: linear-gradient(180deg, var(--brand-2), var(--brand)); border-radius: 6px 6px 2px 2px; position: relative; min-height: 2px; }
.bars .b span { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: .72rem; color: var(--text-2); font-weight: 700; }
.bars-x { display: flex; gap: 4px; font-size: .68rem; color: var(--text-3); }
.bars-x span { flex: 1; text-align: center; }
.hbar { height: 8px; border-radius: 99px; background: var(--bg-2); overflow: hidden; min-width: 80px; }
.hbar i { display: block; height: 100%; background: var(--ok); }
.heat { display: inline-block; min-width: 46px; text-align: center; padding: 2px 6px; border-radius: 6px; font-weight: 700; font-size: .8rem; }

kbd { font-family: var(--mono); font-size: .78em; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text-2); border-bottom-width: 2px; white-space: nowrap; }
.btn kbd { background: transparent; color: inherit; border-color: currentColor; opacity: .75; font-weight: 600; }

/* Field grids respond to the width of their card, not only the screen (a card in a narrow column stacks too) */
.card { container-type: inline-size; }
@container (max-width: 560px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@container (max-width: 400px) { .g3, .g4 { grid-template-columns: minmax(0, 1fr); } }
@container (max-width: 290px) { .g2 { grid-template-columns: minmax(0, 1fr); } }
@container (max-width: 440px) {
  .sec-row { grid-template-columns: repeat(3, minmax(0, 1fr)) 40px; }
  .sec-row > :first-child { grid-column: 1 / -1; }
  .sec-row:not(.sec-head) { padding-bottom: 10px; border-bottom: 1px dashed var(--border); margin-bottom: 10px; }
  .sec-head { display: none; }
}
.ch-row { display: grid; grid-template-columns: repeat(3, minmax(64px, 1fr)) minmax(120px, 2fr) auto; gap: 6px; }
@container (max-width: 520px) { .ch-row { grid-template-columns: repeat(3, minmax(0, 1fr)); } .ch-row > :nth-child(4) { grid-column: 1 / 3; } }
.field-hint { font-size: .8rem; font-weight: 500; color: var(--text-3); }

/* ---------- footer ---------- */
.app-footer { margin-top: auto; border-top: 1px solid var(--border); background: var(--surface); padding: 32px clamp(20px, 3vw, 40px) 22px; }
.foot-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) repeat(3, minmax(0, 1fr)); gap: 28px; }
.foot-brand p { color: var(--text-2); font-size: .9rem; margin: 6px 0 12px; max-width: 420px; }
.foot-brand .brand { padding: 0; }
.app-footer h4 { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin: 6px 0 10px; }
.app-footer ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.app-footer ul a { color: var(--text-2); font-size: .9rem; }
.app-footer ul a:hover { color: var(--brand); }
.foot-bottom { margin: 24px 0 0; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 8px 20px; justify-content: space-between; font-size: .8rem; color: var(--text-3); }

/* ---------- help ---------- */
.help { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 20px; align-items: start; }
.help-toc { position: sticky; top: 76px; padding: 8px; display: grid; gap: 2px; max-height: calc(100vh - 96px); overflow: auto; }
.help-toc a { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 9px; color: var(--text-2); font-weight: 550; font-size: .9rem; }
.help-toc a:hover, .help-toc a.active { background: var(--brand-soft); color: var(--brand); text-decoration: none; }
.help-toc svg { width: 17px; height: 17px; flex: none; }
.help-body { display: grid; gap: 16px; min-width: 0; }
.help-body > .card + .card { margin-top: 0; }
.help-sec { scroll-margin-top: 80px; }
.help-sec h2 { display: flex; align-items: center; gap: 10px; font-size: 1.15rem; }
.help-sec h2 svg { width: 22px; height: 22px; color: var(--brand); }
.help-sec h4 { margin: 14px 0 6px; }
.help-sec p, .help-sec li, .help-sec dd { color: var(--text-2); }
.help-sec ul, .help-sec ol { padding-left: 1.3em; margin: 0 0 .8em; display: grid; gap: 6px; }
.steps li::marker { font-weight: 800; color: var(--brand); }
.defs { margin: 0; display: grid; grid-template-columns: minmax(140px, 220px) minmax(0, 1fr); gap: 10px 18px; }
.defs dt { font-weight: 700; color: var(--text); }
.defs dd { margin: 0; }
.kb td { white-space: normal; } .kb td:last-child { text-align: right; white-space: nowrap; }
.faq { border: 1px solid var(--border); border-radius: 10px; padding: 0 14px; margin-bottom: 8px; background: var(--surface-2); }
.faq summary { cursor: pointer; padding: 12px 0; font-weight: 650; }
.faq p { margin: 0 0 12px; }
.article { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); font-weight: 600; font-size: .92rem; background: var(--surface-2); }
.article:hover { border-color: var(--brand); text-decoration: none; color: var(--brand); }
.search { position: relative; display: block; width: min(320px, 100%); }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--text-3); pointer-events: none; }
.search input { padding-left: 38px; }

/* ---------- modal / toast ---------- */
dialog.modal { border: 1px solid var(--border); border-radius: 18px; padding: 0; background: var(--surface); color: var(--text); width: min(520px, calc(100vw - 32px)); box-shadow: var(--shadow-lg); }
dialog.modal-wide { width: min(980px, calc(100vw - 32px)); }
dialog.modal::backdrop { background: rgba(10, 12, 30, .5); backdrop-filter: blur(3px); }
dialog.modal form { padding: 22px; }
.modal-body { margin: 10px 0 18px; color: var(--text-2); max-height: 70vh; overflow: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
#toasts { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: grid; gap: 8px; justify-items: center; }
.toast { max-width: min(560px, calc(100vw - 32px)); text-align: center; padding: 11px 18px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 600; font-size: .9rem; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(10px); transition: all .25s; }
.toast.show { opacity: 1; transform: none; }
.toast-ok { background: var(--ok); color: #fff; } .toast-bad { background: var(--bad); color: #fff; }

.empty { text-align: center; padding: 48px 20px; color: var(--text-3); }
.empty svg { width: 48px; height: 48px; margin-bottom: 8px; color: var(--border-2); }

.slip { width: 360px; padding: 20px; border-radius: 16px; background: linear-gradient(135deg, #5b4bff, #3b2bd6); color: #fff; }

@media (max-width: 1180px) {
  .review { grid-template-columns: 260px minmax(0, 1fr); }
  .review > :last-child { grid-column: 1 / -1; }
}
@media (max-width: 1100px) {
  .foot-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .foot-brand { grid-column: 1 / -1; }
}
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .help { grid-template-columns: 1fr; }
  .help-toc { position: static; max-height: none; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
  .app-footer { padding: 26px 20px calc(84px + env(safe-area-inset-bottom)); }
  .topbar .select-sm { max-width: 120px; }
  #toasts { bottom: calc(78px + env(safe-area-inset-bottom)); }
  #update-banner { bottom: calc(78px + env(safe-area-inset-bottom)) !important; left: 12px !important; right: 12px; }
  .side { display: none; }
  .view { padding: 18px 20px 96px; }
  .topbar { padding: 10px 20px; }
  .designer { grid-template-columns: 1fr; }
  .panel { position: static; max-height: none; }
  .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .review { grid-template-columns: 1fr; }
  .hero { padding: 28px 22px; } .hero h1 { font-size: 1.7rem; } .hero-art { display: none; }
  .mobile-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .mobile-nav a { display: grid; justify-items: center; gap: 2px; font-size: .68rem; color: var(--text-3); font-weight: 600; padding: 4px 8px; border-radius: 10px; }
  .mobile-nav a.active { color: var(--brand); }
  .mobile-nav svg { width: 22px; height: 22px; }
}
@media (max-width: 560px) {
  .g2, .g3, .g4 { grid-template-columns: 1fr; } .stat .v { font-size: 1.3rem; }
  .foot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
  .defs { grid-template-columns: 1fr; gap: 4px; } .defs dd { margin-bottom: 8px; }
  .page-h h1 { font-size: 1.45rem; }
  .card { padding: 16px; }
  .preview-wrap { padding: 12px; }
  .btn-sm { min-height: 36px; min-width: 36px; padding: 7px 12px; }
}

@media print {
  .side, .topbar, .mobile-nav, .app-footer, .no-print { display: none !important; }
  .app { display: block; } .view { padding: 0; }
  .card { box-shadow: none; border: 0; }
}
