:root {
  color-scheme: light;
  --navy: #0b1736;
  --text: #2c3854;
  --muted: #66728a;
  --blue: #1769e8;
  --blue-dark: #0f55c2;
  --blue-soft: #edf5ff;
  --border: #dce4f0;
  --panel: rgba(255, 255, 255, 0.96);
  --shadow: 0 18px 50px rgba(32, 67, 121, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f7fbff;
  color: var(--text);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; background: radial-gradient(circle at 0 18%, #eef7ff 0, transparent 34%), linear-gradient(180deg, #fff 0, #f7fbff 48%, #fff 100%); }
button, input, textarea, select { font: inherit; }
button, select, input, textarea { outline: none; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible, summary:focus-visible { box-shadow: 0 0 0 3px rgba(23, 105, 232, 0.22); border-radius: 8px; }

.site-header { position: sticky; top: 0; z-index: 20; min-height: 68px; display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 12px max(24px, calc((100vw - 1220px) / 2)); background: rgba(255,255,255,.9); border-bottom: 1px solid rgba(220,228,240,.8); backdrop-filter: blur(14px); }
.brand { display: inline-flex; align-items: center; gap: 12px; color: var(--navy); font-weight: 760; font-size: 20px; text-decoration: none; white-space: nowrap; }
.brand-mark { width: 34px; height: 34px; display: grid; grid-template-columns: 1fr 1fr; border: 2px solid var(--blue); border-radius: 7px; overflow: hidden; }
.brand-mark span { border: .5px dashed var(--blue); }
nav { display: flex; align-items: center; gap: 30px; }
nav a { color: var(--text); text-decoration: none; font-weight: 600; }
nav a:hover { color: var(--blue); }
.github-link { padding: 9px 15px; border: 1px solid var(--border); border-radius: 10px; background: #fff; }

main { width: min(1220px, calc(100% - 36px)); margin: 0 auto; }
.hero { text-align: center; padding: 58px 16px 30px; }
.hero h1 { margin: 0; color: var(--navy); font-size: clamp(36px, 5vw, 60px); line-height: 1.05; letter-spacing: -0.045em; }
.hero p { max-width: 810px; margin: 20px auto 0; color: var(--muted); font-size: clamp(16px, 2vw, 20px); line-height: 1.65; }

.generator-card { background: var(--panel); border: 1px solid rgba(220,228,240,.9); border-radius: 20px; box-shadow: var(--shadow); padding: 22px; }
.settings-layout { display: grid; gap: 14px; }
.settings-section { min-width: 0; padding: 17px; border: 1px solid #e2e9f3; border-radius: 14px; background: linear-gradient(180deg, #fff 0%, #fbfdff 100%); }
.settings-section__title { margin: 0 0 14px; color: var(--navy); font-size: 13px; line-height: 1; letter-spacing: .04em; }
.settings-fields { display: grid; gap: 14px; align-items: start; }
.settings-fields--content { grid-template-columns: minmax(230px, 420px); }
.settings-fields--grid { grid-template-columns: minmax(300px, 1.2fr) minmax(300px, 1.2fr) minmax(220px, .8fr); }
.settings-fields--practice { grid-template-columns: repeat(4, minmax(170px, 1fr)); }
.settings-fields--page { grid-template-columns: repeat(3, minmax(180px, 1fr)); }
.control { min-width: 0; }
.title-control,
.text-control { grid-column: 1 / -1; }
.settings-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding-top: 2px; }
.control label, .control legend { display: block; padding: 0; margin: 0 0 7px; color: var(--navy); font-weight: 700; font-size: 13px; }
.control fieldset, fieldset.control { border: 0; padding: 0; margin: 0; }
textarea, input[type="text"], select { width: 100%; min-height: 42px; border: 1px solid var(--border); border-radius: 9px; background: #fff; color: var(--navy); padding: 9px 12px; transition: border-color .18s, box-shadow .18s; }
textarea { min-height: 69px; resize: vertical; }
textarea:hover, input[type="text"]:hover, select:hover { border-color: #adc4e5; }
.field-help { margin: 5px 0 0; min-height: 18px; color: var(--muted); font-size: 12px; }
.segmented { display: flex; width: 100%; border: 1px solid var(--border); border-radius: 9px; padding: 3px; background: #f9fbfe; }
.segmented button { flex: 1; min-height: 34px; border: 0; border-radius: 6px; background: transparent; color: var(--text); font-size: 12px; font-weight: 650; cursor: pointer; white-space: nowrap; }
.segmented button[aria-pressed="true"] { color: var(--blue-dark); background: #fff; box-shadow: 0 0 0 1px #6da5fa, 0 3px 8px rgba(23,105,232,.12); }
.segmented.compact button { padding-inline: 7px; }
.label-row { display: flex; justify-content: space-between; align-items: center; }
input[role="switch"] { appearance: none; width: 38px; height: 22px; border-radius: 999px; background: #b8c5d8; position: relative; cursor: pointer; transition: background .2s; }
input[role="switch"]::after { content: ""; position: absolute; width: 17px; height: 17px; left: 3px; top: 2.5px; background: #fff; border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.2); transition: transform .2s; }
input[role="switch"]:checked { background: var(--blue); }
input[role="switch"]:checked::after { transform: translateX(15px); }
.button { min-height: 43px; border-radius: 9px; border: 1px solid transparent; font-weight: 750; cursor: pointer; transition: transform .18s, box-shadow .18s, background .18s; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: #fff; background: var(--blue); box-shadow: 0 8px 18px rgba(23,105,232,.2); }
.button.primary:hover { background: var(--blue-dark); }
.button.secondary { background: #fff; border-color: #a9c6f1; color: var(--navy); }
.status { min-height: 24px; padding-top: 8px; color: #8a4d00; font-size: 13px; }

.preview-shell { margin-top: 4px; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: #f1f5fb; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: #fff; }
.preview-toolbar h2 { display: inline; margin: 0 10px 0 0; font-size: 15px; color: var(--navy); }
.preview-toolbar span { color: var(--muted); font-size: 13px; }
.preview-actions { display: flex; align-items: center; gap: 7px; }
.preview-actions button { min-width: 36px; min-height: 34px; border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--navy); cursor: pointer; }
.preview-actions button:disabled { opacity: .4; cursor: not-allowed; }
.preview-viewport { overflow: auto; min-height: 560px; max-height: 760px; padding: 26px; }
.preview-pages { display: flex; flex-direction: column; align-items: center; transform-origin: top center; transition: transform .18s ease; }
.worksheet-page { background: #fff; box-shadow: 0 10px 28px rgba(28,45,77,.16); flex: none; }
.worksheet-page svg { display: block; max-width: none; }
.empty-preview { max-width: 520px; margin: 170px auto; text-align: center; color: var(--muted); }
.empty-preview strong { display: block; color: var(--navy); font-size: 21px; margin-bottom: 8px; }

.feature-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin: 18px 0 70px; }
.feature-grid > h2 { grid-column: 1 / -1; margin: 48px 0 4px; }
.feature-grid article { display: flex; gap: 16px; padding: 22px; border: 1px solid var(--border); border-radius: 15px; background: #fff; }
.feature-grid h3 { margin: 1px 0 6px; color: var(--navy); }
.feature-grid p { margin: 0; color: var(--muted); line-height: 1.55; }
.feature-icon { width: 52px; height: 52px; flex: 0 0 52px; display: grid; place-items: center; border-radius: 12px; border: 2px solid currentColor; font-weight: 800; }
.feature-icon.tian { color: #1769e8; }.feature-icon.mi { color: #0da86f; }.feature-icon.size { color: #ee7d17; }
.section-heading, .content-section h2 { color: var(--navy); letter-spacing: -.025em; }
.content-section { padding: 36px 5%; margin-bottom: 24px; border: 1px solid var(--border); border-radius: 18px; background: #fff; }
.content-section li, .content-section p { color: var(--muted); line-height: 1.7; }
.split-content { display: grid; grid-template-columns: 1fr 1fr; gap: 50px; }
.faq-section details { border-top: 1px solid var(--border); padding: 17px 0; }
.faq-section summary { color: var(--navy); font-weight: 750; cursor: pointer; }
.faq-section details p { margin-bottom: 0; }

#friendly-dialog { width: min(500px, calc(100% - 32px)); border: 0; border-radius: 16px; box-shadow: 0 24px 70px rgba(11,23,54,.25); padding: 26px; }
#friendly-dialog::backdrop { background: rgba(11,23,54,.48); backdrop-filter: blur(3px); }
#friendly-dialog h2 { margin: 0 0 10px; color: var(--navy); }
#friendly-dialog p { color: var(--muted); line-height: 1.55; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.dialog-actions .button { padding: 0 20px; }

@media (max-width: 1100px) {
  .site-header { position: static; }
  nav a:not(.github-link) { display: none; }
  .settings-fields--content { grid-template-columns: minmax(220px, 420px); }
  .settings-fields--grid,
  .settings-fields--practice,
  .settings-fields--page { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pattern-control,
  .title-control,
  .text-control { grid-column: 1 / -1; }
  .preview-viewport { min-height: 460px; }
}

@media (max-width: 680px) {
  main { width: min(100% - 20px, 1220px); }
  .site-header { padding: 12px 15px; }
  .brand { min-width: 0; font-size: 15px; }
  .brand-mark { width: 29px; height: 29px; flex: 0 0 29px; }
  .hero { padding: 38px 8px 22px; }
  .hero h1 { font-size: clamp(32px, 10vw, 38px); }
  .generator-card { padding: 12px; border-radius: 15px; }
  .settings-layout { gap: 12px; }
  .settings-section { padding: 14px; border-radius: 12px; }
  .settings-fields,
  .settings-fields--content,
  .settings-fields--grid,
  .settings-fields--practice,
  .settings-fields--page { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .pattern-control,
  .title-control,
  .text-control { grid-column: 1; }
  .settings-actions { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .button { min-height: 46px; }
  .segmented button { min-height: 38px; padding-inline: 7px; }
  .preview-toolbar { align-items: flex-start; flex-wrap: wrap; }
  .preview-toolbar > div:first-child { width: 100%; }
  .preview-actions { width: 100%; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .preview-actions button { min-width: 0; }
  .preview-viewport { min-height: 400px; padding: 12px; }
  .feature-grid, .split-content { grid-template-columns: 1fr; }
  .feature-grid > h2 { margin-top: 30px; }
  .content-section { padding: 24px 20px; }
}

@media (max-width: 560px) {
  .site-header nav { display: none; }
}

.worksheet-page[hidden] { display: none; }
