/* Worksheet Studio — NeonHarbor Labs visual identity (Poppins, navy ink, harbor-light spectrum). */
@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 400; font-display: swap; src: url('assets/poppins-regular.woff') format('woff'); }
@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 500; font-display: swap; src: url('assets/poppins-medium.woff') format('woff'); }
@font-face { font-family: 'Poppins'; font-style: normal; font-weight: 700; font-display: swap; src: url('assets/poppins-bold.woff') format('woff'); }

:root {
  --ink: #03123e; --ink-2: #27325e; --muted: #4d5679; --line: #e3e8f6; --mist: #f5f7ff;
  --electric: #1f4bff; --electric-deep: #1a3be0; --cyan: #12c2f0; --violet: #7b3cf6; --magenta: #d43bdf; --pink: #ff4fa0; --orange: #ff8a1f;
  --danger: #b42318; --danger-bg: #fff1f0; --warn: #8a4b00; --warn-bg: #fff6e5; --ok: #0b6b3a;
  --spectrum: linear-gradient(90deg, #1f4bff 0%, #12c2f0 22%, #7b3cf6 46%, #ff4fa0 72%, #ff8a1f 100%);
  --spectrum-deep: linear-gradient(95deg, #1a3be0 0%, #6427dc 45%, #b1179c 78%, #c2410c 100%);
  --font: 'Poppins', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --topbar-h: 76px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); color: var(--ink); background: linear-gradient(#f5f7ff, #ffffff 520px) no-repeat, #fff; font-size: 15px; line-height: 1.5; }
:focus-visible { outline: 3px solid var(--electric); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3, p { margin: 0; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--ink); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 100; }
.skip:focus { left: 8px; }

/* ---------- Top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: #fff; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 20px; padding: 10px 20px; box-shadow: 0 1px 0 rgba(3,18,62,.08); }
.topbar::after { content: ''; position: absolute; left: 0; right: 0; bottom: -3px; height: 3px; background: var(--spectrum); }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo img { display: block; height: 40px; width: auto; }
.brand-text h1 { font-size: 1.15rem; line-height: 1.2; font-weight: 700; }
.brand-text p { font-size: .8rem; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn { font: inherit; font-weight: 500; font-size: .9rem; min-height: 42px; padding: 6px 18px; border-radius: 999px; border: 1.5px solid #c9d2ee; background: #fff; color: var(--ink); cursor: pointer; transition: transform .2s, box-shadow .2s, background-color .2s, border-color .2s; }
.btn:hover { border-color: var(--electric); background: var(--mist); }
.btn-primary { background: var(--spectrum-deep); border-color: transparent; color: #fff; box-shadow: 0 8px 22px -10px rgba(100,39,220,.7); }
.btn-primary:hover { background: var(--spectrum-deep); border-color: transparent; transform: translateY(-1px); box-shadow: 0 12px 26px -12px rgba(100,39,220,.8); }
.btn-quiet { border-color: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--danger); background: var(--danger-bg); border-color: transparent; }
.btn-small { min-height: 38px; padding: 4px 14px; font-size: .84rem; }
.btn-danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.banner { margin: 14px 20px 0; padding: 12px 16px; border-radius: 10px; background: var(--danger-bg); color: var(--danger); border: 1px solid #f3b8b3; font-weight: 500; }
.banner[hidden] { display: none; }
.banner.info { background: #eaf7ee; color: var(--ok); border-color: #b5e0c4; }

/* ---------- Intro ---------- */
.intro { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 24px; margin: 18px 20px 0; padding: 14px 20px; border-radius: 18px; background: linear-gradient(95deg, #eef3ff, #f3edff 60%, #fff0f7); border: 1px solid #dfe6fb; color: var(--ink-2); font-size: .92rem; }
.intro p { max-width: 78ch; }
.intro strong { color: var(--ink); }
.back { font-weight: 500; color: var(--electric-deep); text-decoration: none; white-space: nowrap; }
.back:hover { text-decoration: underline; text-underline-offset: 4px; }

/* ---------- Workspace ---------- */
.tabs { display: flex; gap: 6px; padding: 14px 20px 0; }
.tabs button { font: inherit; font-weight: 500; flex: 1; min-height: 46px; border: 1px solid var(--line); border-bottom: none; border-radius: 16px 16px 0 0; background: #fff; color: var(--muted); cursor: pointer; }
.tabs button[aria-selected="true"] { color: var(--ink); background: #fff; border-color: var(--electric); box-shadow: inset 0 3px 0 var(--electric); }
.workspace { padding: 0 20px 28px; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: 0 0 22px 22px; padding: 20px; display: none; box-shadow: 0 30px 60px -44px rgba(31,75,255,.45); }
.workspace[data-active="settings"] #panel-settings,
.workspace[data-active="editor"] #panel-editor,
.workspace[data-active="preview"] #panel-preview { display: block; }
.panel > h2, .preview-bar h2 { font-size: 1.05rem; font-weight: 700; margin-bottom: 12px; }

@media (min-width: 1180px) {
  .tabs { display: none; }
  .workspace { display: grid; grid-template-columns: 290px minmax(360px, 1fr) minmax(500px, 1.25fr); gap: 16px; padding-top: 18px; align-items: start; }
  .panel, .workspace[data-active] .panel { display: block; border-radius: 22px; max-height: calc(100vh - var(--topbar-h) - 30px); overflow-y: auto; position: sticky; top: calc(var(--topbar-h) + 12px); }
  .workspace { padding-top: 18px; }
}

/* ---------- Forms ---------- */
.field { display: grid; gap: 4px; margin-bottom: 12px; }
label { font-weight: 500; font-size: .86rem; }
.optional { color: var(--muted); font-weight: 400; }
input[type=text], input[type=number], textarea, select {
  font: inherit; font-size: .93rem; color: var(--ink); width: 100%; min-height: 40px; padding: 7px 10px; border: 1.5px solid #b9c4e6; border-radius: 9px; background: #fff;
}
textarea { resize: vertical; min-height: 64px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(31,75,255,.35); border-color: var(--electric); }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 14px; padding: 10px 12px 6px; min-width: 0; }
legend { font-weight: 700; font-size: .84rem; padding: 0 6px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 36px; font-weight: 400; font-size: .92rem; cursor: pointer; }
input[type=checkbox], input[type=radio] { width: 20px; height: 20px; accent-color: var(--electric-deep); flex: none; }
.hint { color: var(--muted); font-size: .8rem; margin: 2px 0 8px; }
.privacy { font-size: .8rem; color: var(--ink-2); background: var(--mist); border-radius: 8px; padding: 8px 10px; }
.save-status { font-size: .78rem; color: var(--muted); margin-top: 8px; min-height: 1.4em; }
.save-status.bad { color: var(--danger); }

/* ---------- Question editor ---------- */
.addbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 14px; padding: 10px 12px; background: var(--mist); border-radius: 18px; }
.addlabel { font-weight: 700; font-size: .84rem; margin-right: 2px; }
.qlist { display: grid; gap: 10px; }
.qcard { border: 1.5px solid var(--line); border-radius: 18px; background: #fff; }
.qcard:focus-within { border-color: #b9c8ff; box-shadow: 0 10px 28px -20px rgba(31,75,255,.6); }
.qcard.has-warn { border-color: #f0c987; }
.qhead { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; padding: 8px 10px; }
.qtoggle { font: inherit; flex: 1 1 200px; min-width: 0; display: flex; align-items: center; gap: 10px; text-align: left; background: none; border: none; padding: 4px; cursor: pointer; color: inherit; border-radius: 8px; }
.qn { flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--spectrum-deep); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.qmeta { display: grid; min-width: 0; }
.qtype { font-weight: 700; font-size: .84rem; }
.qsnip { color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qtools { display: flex; gap: 4px; flex-wrap: wrap; }
.qbody { padding: 4px 14px 14px; border-top: 1px solid var(--line); }
.qbody[hidden] { display: none; }
.qbody .field:first-child { margin-top: 12px; }
.qwarn { padding: 0 14px 10px; color: var(--warn); font-size: .8rem; font-weight: 500; }
.qwarn:empty { display: none; }
.qwarn::before { content: '\26A0\FE0E  '; }
.row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.row .grow { flex: 1; min-width: 0; }
.row .small { width: 84px; flex: none; }
.pairrow { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.cols2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .pairrow { grid-template-columns: 1fr auto; } .pairrow input:nth-child(2) { grid-column: 1; } .cols2 { grid-template-columns: 1fr; } }
.blanks { font-size: .8rem; color: var(--muted); margin: 4px 0 10px; }

/* ---------- Preview chrome ---------- */
.preview-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-bottom: 10px; }
.preview-bar h2 { margin: 0; }
.seg { display: inline-flex; border: 1.5px solid #b9c4e6; border-radius: 999px; overflow: hidden; }
.seg button { font: inherit; font-size: .84rem; font-weight: 500; min-height: 36px; padding: 4px 12px; border: none; background: #fff; color: var(--ink); cursor: pointer; }
.seg button + button { border-left: 1.5px solid #b9c4e6; }
.seg button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.meta { font-size: .8rem; color: var(--muted); margin-left: auto; }
.issues { background: var(--warn-bg); border: 1px solid #f0c987; color: var(--warn); border-radius: 10px; padding: 8px 12px; font-size: .82rem; margin-bottom: 10px; }
.issues[hidden] { display: none; }
.issues ul { margin: 4px 0 0; padding-left: 18px; }
.preview-scroll { background: #dfe5f7; border-radius: 16px; padding: 14px 10px; overflow-x: hidden; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 16px; transform-origin: top center; }

/* ---------- Worksheet paper (US Letter, portrait: 816 x 1056 CSS px) ---------- */
.measure { position: fixed; left: -10000px; top: 0; width: 696px; visibility: hidden; pointer-events: none; }
.ws-page { position: relative; width: 816px; height: 1054px; padding: 56px 60px 64px; background: #fff; color: #111; box-shadow: 0 6px 24px -10px rgba(3,18,62,.45); overflow: hidden; flex: none; }
.ws-body { width: 100%; height: 100%; }
.ws-foot { position: absolute; left: 60px; right: 60px; bottom: 26px; display: flex; justify-content: space-between; gap: 12px; font-size: 11px; color: #555; }
.ws-foot span:nth-child(2) { text-align: center; }
.ws-foot span:last-child { text-align: right; }
.ws-foot span { flex: 1; }

.ws-page, .measure { --fs: 14.5px; --line: 30px; --num: calc(var(--fs) * 1.75); font-family: var(--font); font-size: var(--fs); line-height: 1.45; color: #111; }
[data-fs="large"] { --fs: 17px; }
[data-fs="xlarge"] { --fs: 19.5px; }
[data-space="compact"] { --line: 24px; }
[data-space="standard"] { --line: 30px; }
[data-space="roomy"] { --line: 40px; }
[data-space="extra"] { --line: 52px; }
[data-ff="arial"] { font-family: Arial, Helvetica, sans-serif; }
[data-ff="serif"] { font-family: Georgia, 'Times New Roman', serif; }

.ws-head { padding-bottom: 14px; margin-bottom: 6px; border-bottom: 3px solid #111; position: relative; }
.ws-head::after { content: ''; position: absolute; left: 0; right: 0; bottom: -7px; border-bottom: 1px solid #111; }
.ws-head h3 { font-size: 1.75em; line-height: 1.15; font-weight: 700; letter-spacing: -.01em; }
.ws-sub { font-size: .82em; letter-spacing: .08em; text-transform: uppercase; color: #444; margin-top: 5px; font-weight: 500; }
.ws-fields { display: flex; flex-wrap: wrap; gap: 10px 24px; margin-top: 18px; font-weight: 500; }
.ws-field { display: flex; align-items: flex-end; gap: 6px; flex: 1 1 200px; }
.ws-field.short { flex: 0 1 150px; }
.ws-field.score { flex: 0 0 auto; }
.ws-field.score i { flex: none; width: 54px; }
.of { white-space: nowrap; }
.ws-field i { flex: 1; border-bottom: 1.5px solid #111; height: 1.3em; min-width: 40px; }
.ws-instr { margin-top: 16px; padding: 9px 14px; border-left: 5px solid #111; background: #f0f0f0; border-radius: 3px; font-size: .95em; white-space: pre-wrap; }
.ws-empty { padding: 40px 10px; text-align: center; color: #595959; font-style: italic; }
.ws-passage { margin-top: 16px; padding: 12px 16px 12px; border: 1.5px solid #111; border-radius: 8px; break-inside: avoid; }
.ws-passage-label { font-size: .72em; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; margin-bottom: 4px; }
.ws-passage-text { white-space: pre-wrap; overflow-wrap: anywhere; font-family: Georgia, 'Times New Roman', serif; font-size: 1.02em; line-height: 1.6; }

.q { padding: 15px 0 5px; break-inside: avoid; }
.q-head { display: flex; gap: 10px; }
.q-num { flex: none; width: var(--num); height: var(--num); line-height: var(--num); border-radius: 50%; background: #111; color: #fff; text-align: center; font-weight: 700; font-size: .82em; margin-top: .1em; }
.q-prompt { flex: 1; white-space: pre-wrap; overflow-wrap: anywhere; }
.pts { color: #555; font-size: .85em; margin-left: 6px; white-space: nowrap; }
.q-body { margin-left: calc(var(--num) + 10px); }
.q-empty { color: #595959; font-style: italic; }
.opts { display: grid; gap: 5px; margin-top: 7px; }
.ws-opt { display: flex; gap: 8px; align-items: baseline; }
.ws-opt b { flex: none; width: 1.4em; font-weight: 500; }
.bubble { display: inline-block; flex: none; width: .95em; height: .95em; border: 1.5px solid #111; border-radius: 50%; position: relative; top: .12em; }
.lines { margin-top: 4px; }
.wl { height: var(--line); border-bottom: 1.2px solid #444; }
[data-ls="primary"] .wl { background: repeating-linear-gradient(90deg, #888 0 4px, transparent 4px 9px) 0 55% / 100% 1px no-repeat; }
.hint-box { margin-top: 7px; padding: 5px 11px; border: 1.2px dashed #666; border-radius: 6px; font-size: .9em; font-style: italic; color: #222; width: fit-content; max-width: 100%; }
.hint-box b { font-style: normal; }
.blank { display: inline-block; width: 7.5em; border-bottom: 1.5px solid #111; margin: 0 .15em; height: 1em; vertical-align: baseline; }
.bank { margin: 9px 0 2px calc(var(--num) + 10px); padding: 7px 12px; border: 1.5px solid #111; border-radius: 8px; font-size: .95em; background: #f7f7f7; }
.bank b { margin-right: 6px; }
.bank span + span::before { content: '\00b7'; margin: 0 .55em; }
.mgrid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 28px; margin-top: 8px; }
.mcell { display: flex; gap: 7px; padding: 5px 0; align-items: baseline; }
.mcell .mb { display: inline-block; width: 2.2em; border-bottom: 1.5px solid #111; flex: none; height: 1em; }
.mcell b { font-weight: 500; flex: none; }
.vrow { margin-top: 8px; }
.vrow .vt { font-weight: 700; }
.vrow .vd { font-weight: 400; }
.ws-check { margin-top: 18px; padding: 10px 14px; border: 1.5px solid #111; border-radius: 8px; break-inside: avoid; }
.ws-check-item { display: flex; align-items: center; gap: 9px; padding: 2px 0; font-size: .95em; }
.box { display: inline-block; width: .95em; height: .95em; border: 1.5px solid #111; border-radius: 3px; flex: none; }

.k-title { font-size: 1.5em; font-weight: 700; }
.k-badge { display: inline-block; margin-left: 10px; padding: 2px 12px; border: 1.5px solid #111; border-radius: 99px; font-size: .5em; vertical-align: middle; letter-spacing: .1em; text-transform: uppercase; }
.k { padding: 9px 0; break-inside: avoid; display: flex; gap: 10px; border-bottom: 1px solid #ccc; }
.k-main { flex: 1; overflow-wrap: anywhere; }
.k-q { color: #666; font-size: .8em; }
.k-a { font-weight: 500; white-space: pre-wrap; }
.k-a.missing { color: #a00; font-weight: 400; font-style: italic; }
.k ul { margin: 2px 0 0; padding-left: 18px; font-weight: 500; }
.ans-fill { text-decoration: underline; font-weight: 700; }

/* ---------- Dialogs, toast ---------- */
.dlg { border: none; border-radius: 16px; padding: 22px; width: min(480px, calc(100vw - 32px)); color: var(--ink); font-family: var(--font); box-shadow: 0 30px 80px -20px rgba(3,18,62,.6); }
.dlg-wide { width: min(900px, calc(100vw - 32px)); max-height: calc(100vh - 40px); }
.dlg::backdrop { background: rgba(3,18,62,.5); }
.dlg h2 { font-size: 1.15rem; margin-bottom: 8px; }
.dlg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.tpl-level { font-size: .95rem; font-weight: 700; margin: 16px 0 8px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.tpl { border: 1.5px solid var(--line); border-radius: 12px; padding: 12px; display: grid; gap: 4px; align-content: start; }
.tpl .tag { font-size: .72rem; font-weight: 700; color: var(--electric-deep); text-transform: uppercase; letter-spacing: .04em; }
.tpl h4 { margin: 0; font-size: .95rem; }
.tpl p { font-size: .8rem; color: var(--muted); }
.tpl .btn { margin-top: 6px; justify-self: start; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 50; display: flex; align-items: center; gap: 12px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .9rem; max-width: calc(100vw - 32px); }
.toast:empty { display: none; }
.toast button { font: inherit; font-weight: 700; color: #fff; background: none; border: 1.5px solid #fff; border-radius: 8px; padding: 2px 10px; min-height: 32px; cursor: pointer; }

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .intro { margin-left: 12px; margin-right: 12px; }
  .tabs, .workspace { padding-left: 12px; padding-right: 12px; }
  .banner { margin-left: 12px; margin-right: 12px; }
  .actions .btn { flex: 1 1 auto; padding-left: 10px; padding-right: 10px; }
  .panel { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* ---------- Print: only the paper ---------- */
@page { size: 8.5in 11in; margin: 0; }
@media print {
  html, body { background: #fff !important; height: auto; }
  .skip, .topbar, .intro, .banner, .tabs, .toast, .measure, dialog, noscript,
  #panel-settings, #panel-editor, .preview-bar, .issues, .ws-empty { display: none !important; }
  .workspace { display: block !important; padding: 0 !important; }
  #panel-preview { display: block !important; position: static !important; max-height: none !important; overflow: visible !important; padding: 0 !important; box-shadow: none !important; border-radius: 0 !important; background: none !important; }
  .preview-scroll { padding: 0 !important; background: none !important; overflow: visible !important; }
  .pages { zoom: 1 !important; display: block !important; gap: 0 !important; }
  .ws-page { box-shadow: none !important; margin: 0 !important; break-after: page; page-break-after: always; }
  .ws-page:last-child { break-after: auto; page-break-after: auto; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
