:root {
  --ink: #243846;
  --muted: #647783;
  --paper: #fffdf8;
  --canvas: #edf3f0;
  --navy: #1f4b5e;
  --mint: #d8ede5;
  --mint-strong: #2f8067;
  --coral: #e66f51;
  --coral-soft: #fff0ea;
  --line: #d6e0dc;
  --shadow: 0 12px 30px rgba(27, 63, 75, .09);
  font-family: "BIZ UDPGothic", "Yu Gothic", "Hiragino Kaku Gothic ProN", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--canvas); }
button, select, input { font: inherit; }
button { cursor: pointer; }

.app-header {
  min-height: 92px; padding: 18px max(24px, calc((100vw - 1180px) / 2)); display: flex; align-items: center; gap: 14px;
  background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand-mark { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 16px 16px 8px 16px; background: var(--coral); color: #fff; font-size: 30px; font-weight: 800; transform: rotate(-2deg); }
.app-header h1 { margin: 1px 0 0; color: var(--navy); font-size: 24px; letter-spacing: .04em; }
.eyebrow { margin: 0; color: var(--coral); font-size: 11px; font-weight: 800; letter-spacing: .16em; }
.db-status { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #e4aa3a; box-shadow: 0 0 0 4px #fff1cf; }
.db-status.ready .status-dot { background: #45a17e; box-shadow: 0 0 0 4px #dcf2e8; }
.db-status.error .status-dot { background: #cc534c; box-shadow: 0 0 0 4px #f8dedb; }

.builder-layout { width: min(1600px, calc(100% - 28px)); margin: 20px auto 36px; display: grid; grid-template-columns: minmax(500px, 620px) minmax(650px, 1fr); align-items: start; gap: 18px; }
.workspace { width: auto; min-width: 0; margin: 0; display: grid; gap: 18px; }
.panel { min-width: 0; background: var(--paper); border: 1px solid rgba(31,75,94,.09); border-radius: 22px; box-shadow: var(--shadow); padding: 24px; }
.step-title { display: flex; align-items: center; gap: 13px; margin-bottom: 20px; }
.step-title > span { flex: 0 0 34px; height: 34px; display: grid; place-items: center; background: var(--navy); color: #fff; font-weight: 800; border-radius: 11px 11px 5px 11px; }
.step-title p { margin: 0 0 2px; color: var(--mint-strong); font-size: 11px; font-weight: 800; letter-spacing: .12em; }
.step-title h2 { margin: 0; font-size: 18px; color: var(--navy); }
.step-title .text-button, .step-title .count-badge { margin-left: auto; }
.text-button { border: 0; background: none; color: var(--mint-strong); text-decoration: underline; text-underline-offset: 3px; }
.count-badge { padding: 8px 12px; border-radius: 20px; background: var(--coral-soft); color: #a44834; font-size: 13px; }
.count-badge.distractor { background: #e6f4ef; color: #236b56; }

.format-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.format-option { position: relative; min-height: 104px; display: grid; grid-template-columns: 52px 1fr; grid-template-rows: 1fr 1fr; align-items: end; column-gap: 14px; padding: 20px; border: 2px solid var(--line); border-radius: 16px; cursor: pointer; transition: .18s ease; }
.format-option input { position: absolute; opacity: 0; }
.format-option:has(input:checked) { border-color: var(--coral); background: var(--coral-soft); box-shadow: inset 0 0 0 2px #fff; }
.format-icon { grid-row: 1 / 3; width: 52px; height: 52px; display: grid; place-items: center; background: var(--mint); color: var(--navy); border-radius: 14px; font-size: 28px; font-weight: 900; }
.format-option strong { align-self: end; color: var(--navy); font-size: 17px; }
.format-option small { align-self: start; color: var(--muted); }

.condition-heading { margin: 0 0 14px; font-size: 16px; color: var(--navy); }
.initial-picker { margin-bottom: 16px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.sound-rule-row { display: grid; grid-template-columns: repeat(2, minmax(0, 240px)); gap: 14px; align-items: start; margin-top: 14px; }
.sound-position, .sound-count { display: block; max-width: 240px; }
.length-filter { margin-bottom: 16px; }
.initial-picker summary { color: var(--navy); font-size: 14px; font-weight: 700; cursor: pointer; overflow-wrap: anywhere; }
.sound-kind-picker { margin-top: 14px; padding-bottom: 13px; border-bottom: 1px solid var(--line); }
.sound-kind-picker legend, .sound-detail-label { margin: 0 0 8px; color: var(--navy); font-size: 13px; font-weight: 800; }
.sound-detail-label { margin-top: 13px; }
.initial-rows { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 198px), 1fr)); align-items: start; gap: 16px; max-height: 230px; overflow-y: auto; padding: 8px 3px 3px; }
.sound-column { display: grid; gap: 7px; min-width: 0; }
.sound-column h4 { margin: 0 0 2px; color: var(--navy); font-size: 14px; }
.initial-rows .chip-row { flex-wrap: nowrap; }
.initial-rows .chip-row span { min-width: 34px; text-align: center; padding: 7px; font-size: 14px; }
.initial-rows input:focus-visible + span { outline: 2px solid var(--navy); outline-offset: 2px; }
.condition-switch { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; margin-bottom: 20px; }
.condition-option { position: relative; display: flex; align-items: center; gap: 10px; min-width: 0; padding: 14px 12px; border: 2px solid var(--line); border-radius: 16px; color: var(--navy); cursor: pointer; }
.condition-option input { position: absolute; opacity: 0; }
.condition-option:has(input:checked) { border-color: var(--coral); background: var(--coral-soft); box-shadow: inset 0 0 0 2px #fff; }
.condition-option:has(input:focus-visible) { outline: 3px solid var(--navy); outline-offset: 3px; }
.condition-option strong { font-size: 16px; overflow-wrap: anywhere; }
.condition-icon { flex: 0 0 36px; height: 36px; display: grid; place-items: center; border-radius: 10px; background: var(--mint); font-size: 22px; font-weight: 800; }
.condition-panel-heading { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-bottom: 14px; }
.condition-panel-heading .condition-heading { margin: 0; }
.condition-group { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.filter-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.filter-grid fieldset { grid-column: span 2; }
legend, .field > span { display: block; margin-bottom: 8px; color: var(--navy); font-size: 13px; font-weight: 800; }
.chip-row { display: flex; flex-wrap: wrap; gap: 7px; }
.chip-row label { cursor: pointer; }
.chip-row input { position: absolute; opacity: 0; }
.chip-row span { display: block; padding: 8px 11px; border: 1px solid var(--line); border-radius: 99px; background: #fff; color: var(--muted); font-size: 13px; }
.chip-row input:checked + span { color: #fff; border-color: var(--mint-strong); background: var(--mint-strong); }
.chip-row input[data-filter-state="excluded"] + span { color: #fff; border-color: #d54848; background: #d54848; }
.field select, .field input { width: 100%; height: 42px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); padding: 0 11px; }
.field select { padding-right: 34px; }
.field > small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.mini-switch { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 11px; background: #e9efec; }
.mini-switch input { position: absolute; opacity: 0; }
.mini-switch span { display: block; padding: 8px 5px; border-radius: 8px; text-align: center; color: var(--muted); font-size: 13px; cursor: pointer; }
.mini-switch input:checked + span { background: #fff; color: var(--navy); font-weight: 800; box-shadow: 0 2px 7px rgba(31,75,94,.1); }

.candidate-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: 12px 16px; padding: 12px 0 16px; border-top: 1px solid var(--line); }
.candidate-mode-switch { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; margin: -2px 0 16px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: #edf2f0; }
.candidate-mode-button { min-height: 42px; display: flex; align-items: center; justify-content: center; gap: 7px; padding: 7px 10px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; }
.candidate-mode-button > span { padding: 3px 6px; border-radius: 6px; font-size: 11px; font-weight: 900; letter-spacing: .06em; }
#showAnswerCandidates > span { background: #fde2da; color: #a44834; }
#showDistractorCandidates > span { background: #dcefe8; color: #236b56; }
.candidate-mode-button strong { font-size: 14px; text-align: left; }
.candidate-mode-button.selected { background: #fff; color: var(--navy); box-shadow: 0 2px 7px rgba(31,75,94,.1); }
#showAnswerCandidates.selected { box-shadow: inset 0 -3px 0 var(--coral), 0 2px 7px rgba(31,75,94,.1); }
#showDistractorCandidates.selected { box-shadow: inset 0 -3px 0 var(--mint-strong), 0 2px 7px rgba(31,75,94,.1); }
.candidate-mode-button:focus-visible { outline: 3px solid var(--navy); outline-offset: 2px; }
.candidate-toolbar p { margin: 0; color: var(--muted); }
.candidate-toolbar > div { display: flex; gap: 7px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.candidate-toolbar > .candidate-filter { flex: 1 1 330px; justify-content: flex-start; align-items: end; gap: 10px; }
.candidate-search { width: min(210px, 100%); }
.candidate-category { width: 180px; }
.sub-button, .shuffle-button { min-height: 36px; border: 1px solid var(--line); background: #fff; color: var(--navy); border-radius: 9px; padding: 7px 11px; font-weight: 700; }
.sub-button:hover, .shuffle-button:hover { border-color: var(--mint-strong); }
.sub-button.accent { background: var(--mint-strong); border-color: var(--mint-strong); color: #fff; }
.sub-button.danger-outline { border-color: #d99b9b; color: #a53b3b; }
.random-pick { display: flex; align-items: center; gap: 5px; padding-left: 5px; color: var(--muted); font-size: 13px; }
.random-pick input { width: 50px; height: 36px; padding: 4px; border: 1px solid var(--line); border-radius: 8px; text-align: center; }
.candidate-grid { max-height: 470px; overflow: auto; display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; padding: 3px; }
.candidate-card { position: relative; min-width: 0; padding: 10px; border: 2px solid transparent; border-radius: 14px; background: #f4f7f5; cursor: pointer; transition: .15s ease; content-visibility: auto; contain-intrinsic-size: auto 154px; }
.candidate-card:hover { transform: translateY(-1px); background: #eef5f1; }
.candidate-card.selected { border-color: var(--mint-strong); background: #eaf7f2; }
.candidate-card.random-selected { border-style: dashed; background: #f2faf7; }
.candidate-card.manual-selected { box-shadow: inset 0 0 0 1px var(--mint-strong); }
.candidate-card input { position: absolute; opacity: 0; }
.candidate-card .check { position: absolute; right: 8px; top: 8px; width: 22px; height: 22px; display: grid; place-items: center; border: 2px solid #b9c9c3; border-radius: 7px; background: #fff; color: #fff; font-size: 14px; font-weight: 900; }
.candidate-card.selected .check { border-color: var(--mint-strong); background: var(--mint-strong); }
.candidate-card.manual-selected .check { width: auto; min-width: 22px; padding: 0 5px; font-size: 10px; }
.candidate-card.excluded { border-color: #d54848; background: #fff0f0; }
.candidate-card.excluded:hover { background: #ffe8e8; }
.candidate-card.excluded .check { width: auto; min-width: 22px; padding: 0 5px; border-color: #d54848; background: #d54848; color: #fff; font-size: 11px; }
.candidate-card.excluded strong { color: #a62f2f; }
.candidate-thumb { height: 96px; display: grid; place-items: center; padding: 6px; border-radius: 10px; background: #fff; }
.candidate-thumb img { width: 100%; height: 100%; object-fit: contain; }
.candidate-card strong { display: block; margin-top: 9px; color: var(--navy); font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.candidate-card small { display: block; margin-top: 3px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notice { margin: 0 0 14px; padding: 12px 14px; border-radius: 10px; background: #fff4d9; color: #77561c; font-size: 13px; }
.selection-breakdown { margin: -7px 0 11px; color: var(--muted); font-size: 12px; }
.load-more { width: 100%; min-height: 38px; margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--navy); font-weight: 800; }
.load-more:hover { border-color: var(--mint-strong); }
.hidden { display: none !important; }

.settings-row { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; max-width: 620px; }
.simple-choice-field { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #f7faf8; }
.simple-choice-field legend { padding: 0 5px; }
.simple-condition-checks { display: flex; flex-wrap: wrap; gap: 7px; }
.condition-chip { position: relative; cursor: pointer; }
.condition-chip input { position: absolute; opacity: 0; }
.condition-chip span { display: block; padding: 8px 11px; border: 1px solid var(--line); border-radius: 99px; background: #fff; color: var(--muted); font-size: 13px; }
.condition-chip input:checked + span { border-color: var(--mint-strong); background: var(--mint-strong); color: #fff; font-weight: 800; }
.condition-chip input:focus-visible + span { outline: 2px solid var(--navy); outline-offset: 2px; }
.simple-position { display: grid; grid-template-columns: auto minmax(130px, 1fr); align-items: center; gap: 9px; margin-top: 10px; }
.simple-position > span { margin: 0; }
.helper { margin: 13px 0 0; color: var(--muted); font-size: 13px; }
.manual-box { margin-top: 18px; padding: 16px; border-radius: 14px; background: #f3f7f5; }
.manual-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 15px; margin-bottom: 12px; }
.manual-head .field { width: min(360px, 100%); }
.manual-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 9px; }
.manual-head p { margin: 0; color: var(--muted); font-size: 13px; }
.manual-filter-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(150px, 1fr); gap: 10px; align-items: end; margin: 12px 0; }
.manual-search, .manual-category { display: block; min-width: 0; }
.manual-empty { grid-column: 1 / -1; margin: 18px; color: var(--muted); text-align: center; }
.manual-slots { display: grid; grid-template-columns: repeat(3, minmax(90px, 140px)); gap: 9px; margin-bottom: 10px; }
.manual-slot { position: relative; min-height: 88px; display: grid; place-items: center; padding: 7px; border: 2px solid #b7cbc3; border-radius: 12px; background: #fff; color: #8ba097; font-size: 12px; }
.manual-slot.filled { grid-template-columns: 52px 1fr; gap: 7px; border-color: var(--mint-strong); background: #eef8f4; color: var(--navy); font-weight: 800; text-align: left; }
.manual-slot img { width: 52px; height: 58px; object-fit: contain; }
.manual-slot button { position: absolute; top: 4px; right: 4px; width: 23px; height: 23px; padding: 0; border: 0; border-radius: 50%; background: var(--coral); color: #fff; line-height: 1; }
.manual-instruction { margin: 0 0 10px; color: var(--mint-strong); font-size: 12px; font-weight: 700; }
.manual-grid { max-width: 100%; max-height: 250px; overflow-x: hidden; overflow-y: auto; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.manual-item { position: relative; width: 100%; min-width: 0; display: grid; justify-items: center; gap: 5px; padding: 7px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); cursor: pointer; content-visibility: auto; contain-intrinsic-size: auto 84px; }
.manual-item.selected { border: 2px solid var(--mint-strong); background: #e9f6f1; }
.manual-item .add-mark { position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; background: var(--mint-strong); color: #fff; font-weight: 900; }
.manual-item.selected .add-mark { background: var(--mint-strong); }
.manual-item img { width: 58px; height: 48px; object-fit: contain; }
.manual-item span { max-width: 100%; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.print-settings { display: grid; grid-template-columns: repeat(3, 1fr); gap: 13px; }

.preview-section { min-width: 0; height: calc(100vh - 132px); min-height: 560px; position: sticky; top: 112px; overflow: auto; padding: 22px 18px 40px; border-radius: 22px; background: #274653; }
.preview-bar { width: 100%; margin: 0 auto 18px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.step-title.light { margin: 0; }
.step-title.light > span { color: var(--navy); background: var(--mint); }
.step-title.light p { color: #9cd1be; }
.step-title.light h2 { color: #fff; }
.preview-actions { display: flex; align-items: center; gap: 10px; color: #c9d8dc; font-size: 13px; }
.shuffle-button { border-color: #50717c; background: transparent; color: #fff; }
.print-button { min-height: 42px; padding: 8px 22px; border: 0; border-radius: 11px; background: var(--coral); color: #fff; font-weight: 900; box-shadow: 0 5px 0 #a84833; }
.print-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #a84833; }
.print-button:disabled { cursor: not-allowed; opacity: .5; box-shadow: none; transform: none; }
.print-warning { color: #ffd8a8; font-weight: 800; }
.preview-empty { width: min(500px, 100%); margin: 70px auto; display: flex; justify-content: center; align-items: center; gap: 20px; color: #b9cbd0; text-align: left; line-height: 1.8; }
.preview-empty > div { width: 72px; height: 72px; display: grid; place-items: center; border: 2px dashed #6b8992; border-radius: 20px; font-size: 36px; }
.print-root { display: grid; justify-content: center; gap: 24px; zoom: .78; }
.print-root:has(.print-page.landscape) { zoom: .64; }
.print-page { width: 210mm; height: 297mm; padding: 13mm 14mm 12mm; display: flex; flex-direction: column; overflow: hidden; background: #fff; color: #172d38; box-shadow: 0 14px 38px rgba(0,0,0,.25); }
.print-page.landscape { width: 297mm; height: 210mm; }
.worksheet-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 5mm; padding-bottom: 4mm; border-bottom: 1.5px solid #73919d; }
.worksheet-head h3 { min-width: 0; margin: 0; font-size: 15pt; letter-spacing: .04em; line-height: 1.1; white-space: nowrap; }
.student-fields { display: flex; gap: 3mm; color: #536c77; font-size: 9pt; white-space: nowrap; }
.student-fields i { display: inline-block; width: 30mm; height: 5mm; margin-left: 1mm; border-bottom: 1px solid #536c77; }
.student-fields i.date-line { width: 22mm; }
.worksheet-instruction { margin: 4mm 0 3mm; font-size: 11pt; font-weight: 700; }
.questions { flex: 1; min-height: 0; display: grid; }
.questions.choice { gap: 1.8mm; }
.questions.choice.rows-6, .questions.choice.rows-8 { gap: 1mm; }
.questions.choice.rows-6 .choice-box, .questions.choice.rows-8 .choice-box { min-height: 0; }
.questions.choice.rows-8 .choices { padding-block: .8mm; }
.questions.choice.rows-8 .question-word { font-size: 19pt; }
.questions.choice.rows-8.font-small .question-word { font-size: 16pt; }
.questions.choice.rows-8.font-large .question-word { font-size: 22pt; }
.question-row { min-height: 0; display: grid; grid-template-columns: 24% 76%; align-items: center; border-top: 1px solid #dce5e8; }
.question-row:first-child { border-top: 0; }
.question-word { display: flex; align-items: center; gap: 4mm; font-size: 23pt; font-weight: 800; letter-spacing: .06em; }
.question-no { color: #718894; font-size: 10pt; font-weight: 500; }
.choices { height: 100%; min-height: 0; display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; align-items: center; gap: 3mm; padding: 2mm 0; }
.choice-box { height: 88%; min-height: 18mm; max-height: 41mm; display: grid; place-items: center; overflow: hidden; padding: 2mm; border: 1.2px solid #a8bbc2; border-radius: 3mm; }
.choice-box img { display: block; width: auto; height: auto; min-width: 0; min-height: 0; max-width: 100%; max-height: 100%; object-fit: contain; }
.question-picture { height: 90%; min-height: 0; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 2mm; padding: 2mm 3mm 2mm 0; }
.question-picture img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.word-choice.image-small .question-picture { height: 68%; }
.word-choice.image-large .question-picture { height: 98%; }
.word-choice .question-row { grid-template-columns: 21% 79%; }
.word-choice .choices { min-width: 0; grid-auto-columns: minmax(0, 1fr); gap: 2mm; }
.word-choice .choice-text { min-width: 0; height: 88%; padding: 1.5mm 1mm; font-size: var(--choice-text-size, 20pt); font-weight: 800; line-height: 1; text-align: center; white-space: nowrap; word-break: keep-all; overflow-wrap: normal; }
.questions.font-small .question-word { font-size: 18pt; }
.questions.font-large .question-word { font-size: 28pt; }
.questions.image-small .choice-box { height: 68%; }
.questions.image-large .choice-box { height: 98%; }
.matching-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 38% 62%; }
.match-column { display: grid; min-height: 0; }
.match-word, .match-image { position: relative; min-height: 0; display: flex; align-items: center; border-bottom: 1px solid #e2e9eb; }
.match-word { justify-content: space-between; padding: 2mm 14mm 2mm 4mm; font-size: 23pt; font-weight: 800; letter-spacing: .06em; }
.match-image { justify-content: flex-end; padding: 2mm 5mm 2mm 20mm; }
.match-image img { width: 58%; height: 100%; object-fit: contain; }
.match-dot { position: absolute; width: 3.2mm; height: 3.2mm; border: 1.2px solid #5e7985; border-radius: 50%; background: #fff; }
.match-word .match-dot { right: 5mm; }
.match-image .match-dot { left: 8mm; }
.matching-grid.font-small .match-word { font-size: 18pt; }
.matching-grid.font-large .match-word { font-size: 28pt; }
.matching-grid.image-small .match-image img { width: 44%; }
.matching-grid.image-large .match-image img { width: 72%; }
.worksheet-foot { min-height: 11mm; padding-top: 2mm; display: flex; align-items: flex-end; justify-content: flex-end; color: #718894; font-size: 8pt; }
.worksheet-brand-mark { display: block; width: 45mm; height: auto; max-height: 9mm; object-fit: contain; object-position: left bottom; }
.data-warning { margin: auto; padding: 8mm; border: 1px dashed #c48345; color: #7d572d; text-align: center; }

@media (max-width: 1250px) {
  .builder-layout { width: min(1180px, calc(100% - 36px)); grid-template-columns: 1fr; margin-top: 28px; }
  .preview-section { height: auto; min-height: 500px; position: static; overflow: visible; }
  .print-root { zoom: 1; }
  .print-root:has(.print-page.landscape) { zoom: 1; }
}
@media (max-width: 900px) {
  .filter-grid { grid-template-columns: 1fr 1fr; }
  .candidate-grid { grid-template-columns: repeat(3, 1fr); }
  .manual-grid { grid-template-columns: repeat(4, 1fr); }
  .print-settings { grid-template-columns: repeat(3, 1fr); }
  .print-root { justify-content: start; overflow-x: auto; }
}
@media (max-width: 600px) {
  .app-header { position: static; padding: 14px 18px; }
  .brand-mark { width: 44px; height: 44px; font-size: 25px; }
  .app-header h1 { font-size: 19px; }
  .db-status { font-size: 0; }
  .builder-layout { width: calc(100% - 20px); margin-top: 12px; }
  .panel { padding: 18px 14px; border-radius: 17px; }
  .step-title, .condition-panel-heading { flex-wrap: wrap; }
  .format-switch, .settings-row { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr; }
  .filter-grid fieldset { grid-column: span 1; }
  .sound-rule-row { grid-template-columns: 1fr; }
  .sound-position, .sound-count { max-width: none; }
  .candidate-toolbar, .preview-bar { align-items: flex-start; flex-direction: column; }
  .candidate-toolbar > div { width: 100%; justify-content: flex-start; }
  .candidate-search, .candidate-category { width: 100%; }
  .random-pick { flex-wrap: wrap; padding-left: 0; }
  .candidate-grid { grid-template-columns: repeat(2, 1fr); }
  .manual-grid { grid-template-columns: repeat(3, 1fr); }
  .manual-filter-row { grid-template-columns: 1fr; }
  .manual-slots { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .manual-slot.filled { grid-template-columns: 42px minmax(0, 1fr); }
  .manual-slot img { width: 42px; }
  .print-settings { grid-template-columns: 1fr 1fr; }
  .preview-actions { flex-wrap: wrap; }
  .preview-section { padding-inline: 10px; }
}

@media (max-width: 400px) {
  .condition-switch, .print-settings { grid-template-columns: 1fr; }
  .manual-grid { grid-template-columns: repeat(2, 1fr); }
  .count-badge { padding-inline: 9px; font-size: 12px; }
}

@media print {
  html, body { width: 100% !important; min-width: 0 !important; background: #fff !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .no-print { display: none !important; }
  main, .builder-layout, .preview-section, .print-root { width: auto !important; height: auto !important; margin: 0 !important; padding: 0 !important; background: #fff !important; display: block !important; overflow: visible !important; zoom: 1 !important; }
  .print-page { width: 210mm !important; height: 297mm !important; min-width: 210mm !important; min-height: 297mm !important; max-width: 210mm !important; max-height: 297mm !important; margin: 0 !important; box-shadow: none !important; overflow: hidden !important; break-inside: avoid-page; page-break-inside: avoid; break-after: page; page-break-after: always; }
  .print-page.landscape { width: 297mm !important; height: 210mm !important; min-width: 297mm !important; min-height: 210mm !important; max-width: 297mm !important; max-height: 210mm !important; }
  .questions, .question-row, .choices, .choice-box, .question-picture { min-width: 0; min-height: 0; break-inside: avoid; page-break-inside: avoid; }
  .choice-box img, .question-picture img, .worksheet-brand-mark { break-inside: avoid; page-break-inside: avoid; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
}
