:root {
  color-scheme: light;
  --ink: #17312e;
  --muted: #667a77;
  --line: #ccd9d6;
  --paper: #ffffff;
  --ground: #eef3f2;
  --teal: #149b8d;
  --teal-dark: #0c685f;
  --yellow: #f3b51b;
  --coral: #ef6659;
  --blue: #3177c8;
  --shadow: 0 20px 50px rgba(20, 57, 53, 0.12);
  font-family: Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { background: var(--ground); }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--ground);
}

button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; }

.app-header {
  min-height: 112px;
  padding: 16px clamp(18px, 4vw, 54px);
  display: grid;
  grid-template-columns: 90px minmax(230px, 1fr) 300px;
  align-items: center;
  gap: 24px;
  color: #fff;
  background: var(--ink);
  overflow: hidden;
}

.itland-link {
  width: fit-content;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  border-bottom: 2px solid var(--yellow);
  padding-bottom: 4px;
}

.brand-lockup { display: flex; align-items: center; gap: 14px; }
.brand-mark, .worksheet-brand span {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  font: 800 21px/1 "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--yellow);
  border-radius: 50%;
}
.brand-lockup h1 { margin: 0; font-size: 28px; line-height: 1; }
.brand-lockup p { margin: 7px 0 0; color: #bfd0cd; font-size: 13px; }
.app-header > img {
  width: 300px;
  height: 80px;
  object-fit: cover;
  object-position: center;
  border-radius: 6px;
}

.workspace {
  width: min(1440px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  min-height: calc(100vh - 112px);
}

.control-panel {
  padding: 30px 28px;
  background: #fff;
  border-right: 1px solid var(--line);
}

.panel-heading { display: flex; flex-direction: column; margin-bottom: 26px; }
.panel-heading span, .usage-band > div > span, .gate-copy > span {
  color: var(--teal-dark);
  font-size: 10px;
  font-weight: 800;
}
.panel-heading strong { margin-top: 5px; font-size: 22px; }

fieldset { padding: 0; margin: 0 0 24px; border: 0; }
legend, .text-field > span {
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 800;
}

.operation-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.operation-grid label, .difficulty-control label { cursor: pointer; }
.operation-grid input, .difficulty-control input { position: absolute; opacity: 0; pointer-events: none; }
.operation-grid span {
  min-height: 48px;
  padding: 9px 12px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  background: #fff;
}
.operation-grid span b { font-size: 22px; line-height: 1; color: var(--teal-dark); }
.operation-grid input:checked + span {
  color: #fff;
  border-color: var(--teal-dark);
  background: var(--teal-dark);
}
.operation-grid input:checked + span b { color: var(--yellow); }
.operation-grid input:focus-visible + span, .difficulty-control input:focus-visible + span { outline: 3px solid rgba(49,119,200,.28); outline-offset: 2px; }

.difficulty-control {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
  background: var(--ground);
  border-radius: 6px;
}
.difficulty-control span {
  min-height: 36px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 800;
}
.difficulty-control input:checked + span { color: #fff; background: var(--ink); }
.field-note, .output-note, .field-error { margin: 8px 0 0; font-size: 11px; line-height: 1.55; color: var(--muted); }
.field-error { color: #b93a30; font-weight: 700; }

.text-field { display: flex; flex-direction: column; margin-bottom: 22px; }
.text-field input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  outline: 0;
}
.text-field input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(20,155,141,.13); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; cursor: pointer; }
.switch-row span { display: flex; flex-direction: column; }
.switch-row b { font-size: 13px; }
.switch-row small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.switch-row input {
  appearance: none;
  width: 42px;
  height: 24px;
  margin: 0;
  flex: 0 0 auto;
  border: 1px solid #a9bab7;
  border-radius: 20px;
  background: #dbe5e3;
  transition: .2s ease;
}
.switch-row input::before {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  margin: 2px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .2s ease;
}
.switch-row input:checked { background: var(--teal); border-color: var(--teal); }
.switch-row input:checked::before { transform: translateX(18px); }

.primary-button, .output-actions button, .gate-action {
  border: 0;
  border-radius: 6px;
  font-weight: 800;
  cursor: pointer;
}
.primary-button {
  width: 100%;
  min-height: 48px;
  color: #fff;
  background: var(--teal-dark);
}
.primary-button:hover { background: #084f49; }
.output-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.output-actions button { min-height: 44px; background: #e1eae8; }
.output-actions button:hover { background: #d4e1df; }
.output-actions button span { color: var(--teal-dark); }

.sheet-stage { min-width: 0; padding: 26px clamp(18px, 4vw, 54px) 54px; background: #dfe9e7; }
.preview-label { display: flex; justify-content: space-between; width: min(100%, 794px); margin: 0 auto 10px; font-size: 11px; color: #49645f; }
.preview-label span { font-weight: 800; }

.worksheet {
  width: min(100%, 794px);
  aspect-ratio: 210 / 297;
  min-height: 900px;
  margin: 0 auto;
  padding: clamp(34px, 5vw, 64px);
  display: flex;
  flex-direction: column;
  color: #1c2a28;
  background: var(--paper);
  box-shadow: var(--shadow);
}
.worksheet-header { display: grid; grid-template-columns: 120px 1fr; align-items: center; gap: 24px; padding-bottom: 22px; border-bottom: 4px solid var(--ink); }
.worksheet-brand { display: flex; align-items: center; gap: 8px; }
.worksheet-brand span { width: 36px; height: 36px; font-size: 15px; }
.worksheet-brand b { font-size: 13px; }
.worksheet-header p { margin: 0 0 7px; color: var(--teal-dark); font-size: 9px; font-weight: 800; }
.worksheet-header h2 { margin: 0; font-size: 25px; line-height: 1.2; overflow-wrap: anywhere; }
.student-fields { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 28px; margin: 24px 0 8px; }
.student-fields span { display: flex; align-items: end; gap: 8px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.student-fields i { display: block; height: 19px; flex: 1; border-bottom: 1px solid #78908c; }
.student-fields b { font-size: 10px; }

.problem-list {
  list-style: none;
  padding: 0;
  margin: 22px 0 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(5, 1fr);
  grid-auto-flow: column;
  column-gap: 46px;
  flex: 1;
}
.problem {
  min-height: 104px;
  display: grid;
  grid-template-columns: 28px 1fr 52px;
  align-items: center;
  gap: 8px;
  border-bottom: 1px dashed #bdcbc8;
}
.problem:nth-child(5), .problem:nth-child(10) { border-bottom: 0; }
.problem-number {
  width: 23px;
  height: 23px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--teal);
  border-radius: 50%;
  font-size: 10px;
  font-weight: 800;
}
.equation { display: grid; grid-template-columns: 1fr 22px 1fr 20px; align-items: center; text-align: center; }
.equation b { font: 700 25px/1.2 "Segoe UI", sans-serif; }
.equation i { font: normal 18px/1 "Segoe UI", sans-serif; }
.answer-box {
  width: 48px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 2px solid #344a46;
  font: 700 20px/1 "Segoe UI", sans-serif;
}
.answers-visible .answer-box { color: var(--blue); border-color: var(--blue); background: #eff7ff; }
.answer-key { padding: 11px 14px; display: flex; align-items: center; gap: 13px; border: 1px solid #b8cbc7; background: #f1f7f6; font-size: 10px; }
.answer-key[hidden] { display: none; }
.answer-key strong { margin-right: 2px; color: var(--teal-dark); }
.worksheet-footer { padding-top: 16px; display: flex; justify-content: space-between; gap: 16px; border-top: 1px solid #c8d5d2; color: #687c78; font-size: 9px; }
.worksheet-footer b { color: var(--ink); }

.usage-band { padding: 44px max(24px, calc((100% - 1160px) / 2)); display: grid; grid-template-columns: 1fr 1fr; gap: 60px; align-items: center; background: var(--yellow); }
.usage-band h2 { margin: 6px 0 0; font-size: 24px; }
.usage-band p { margin: 0; font-size: 13px; line-height: 1.75; }
.site-footer { padding: 22px max(24px, calc((100% - 1160px) / 2)); display: flex; justify-content: space-between; gap: 20px; color: #c6d4d2; background: #102724; font-size: 10px; }
.site-footer nav { display: flex; gap: 18px; }

.output-gate {
  width: min(94vw, 480px);
  padding: 30px;
  color: var(--ink);
  border: 0;
  border-radius: 8px;
  box-shadow: 0 30px 90px rgba(0,0,0,.28);
}
.output-gate::backdrop { background: rgba(10, 29, 27, .72); }
.gate-close { position: absolute; top: 12px; right: 14px; width: 36px; height: 36px; border: 0; background: transparent; font-size: 25px; cursor: pointer; }
.gate-copy h2 { margin: 7px 30px 7px 0; font-size: 22px; }
.gate-copy p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.6; }
.ad-wrap { min-height: 132px; margin: 22px 0 18px; padding: 8px; display: grid; place-items: center; align-content: center; overflow: hidden; border: 1px solid #d6e1df; background: #f4f7f6; }
.ad-wrap small { margin-bottom: 7px; color: #8a9b98; font-size: 8px; }
.gate-status { display: grid; grid-template-columns: 54px 1fr; align-items: center; gap: 13px; }
.count-ring { width: 52px; height: 52px; display: flex; align-items: baseline; justify-content: center; padding-top: 11px; border: 2px solid var(--teal); border-radius: 50%; }
.count-ring b { font-size: 21px; }
.count-ring span { font-size: 9px; }
.gate-status strong { font-size: 12px; }
.gate-status p { margin: 4px 0 0; color: var(--muted); font-size: 10px; }
.gate-progress { height: 4px; margin: 18px 0 14px; overflow: hidden; background: #dce6e4; }
.gate-progress::before { content: ""; display: block; width: var(--progress); height: 100%; background: var(--teal); transition: width .25s linear; }
.gate-action { width: 100%; min-height: 46px; color: #fff; background: var(--ink); }
.gate-action:disabled { color: #82918f; background: #dce4e2; cursor: wait; }

@media (max-width: 900px) {
  .app-header { grid-template-columns: 70px 1fr; }
  .app-header > img { display: none; }
  .workspace { grid-template-columns: 300px minmax(0, 1fr); }
  .control-panel { padding: 24px 20px; }
  .sheet-stage { padding: 22px 16px 38px; }
  .worksheet { min-height: 760px; padding: 36px; }
  .problem { min-height: 84px; grid-template-columns: 24px 1fr 40px; }
  .equation b { font-size: 20px; }
  .answer-box { width: 38px; height: 36px; font-size: 17px; }
  .problem-list { column-gap: 24px; }
}

@media (max-width: 680px) {
  .app-header { min-height: 88px; padding: 13px 16px; grid-template-columns: 54px 1fr; gap: 10px; }
  .brand-mark { width: 42px; height: 42px; font-size: 17px; }
  .brand-lockup { gap: 10px; }
  .brand-lockup h1 { font-size: 22px; }
  .brand-lockup p { margin-top: 4px; font-size: 11px; }
  .workspace { display: block; }
  .control-panel { padding: 22px 16px 18px; border: 0; border-bottom: 1px solid var(--line); }
  .panel-heading { margin-bottom: 18px; }
  .panel-heading strong { font-size: 19px; }
  fieldset { margin-bottom: 18px; }
  .text-field, .switch-row { margin-bottom: 18px; }
  .sheet-stage { padding: 18px 10px 30px; overflow-x: hidden; }
  .preview-label { padding: 0 4px; }
  .worksheet { min-height: 0; padding: 24px 18px; }
  .worksheet-header { grid-template-columns: 86px 1fr; gap: 12px; padding-bottom: 14px; }
  .worksheet-brand span { width: 29px; height: 29px; font-size: 12px; }
  .worksheet-brand b { font-size: 10px; }
  .worksheet-header p { margin-bottom: 4px; font-size: 7px; }
  .worksheet-header h2 { font-size: 17px; }
  .student-fields { gap: 12px; margin-top: 16px; }
  .student-fields span { gap: 4px; font-size: 8px; }
  .student-fields b { font-size: 7px; }
  .problem-list { margin-top: 13px; column-gap: 10px; }
  .problem { min-height: 59px; grid-template-columns: 18px 1fr 29px; gap: 3px; }
  .problem-number { width: 17px; height: 17px; font-size: 8px; }
  .equation { grid-template-columns: 1fr 14px 1fr 12px; }
  .equation b { font-size: 14px; }
  .equation i { font-size: 11px; }
  .answer-box { width: 28px; height: 26px; border-width: 1px; font-size: 12px; }
  .answer-key { padding: 7px; gap: 6px; flex-wrap: wrap; font-size: 7px; }
  .worksheet-footer { padding-top: 9px; font-size: 6px; }
  .usage-band { padding: 32px 20px; display: block; }
  .usage-band h2 { font-size: 20px; }
  .usage-band p { margin-top: 14px; }
  .site-footer { padding: 20px; flex-direction: column; }
  .output-gate { width: 100vw; max-width: none; margin: auto 0 0; padding: 26px 18px 20px; border-radius: 8px 8px 0 0; }
  .ad-wrap { width: calc(100% + 36px); margin-inline: -18px; border-inline: 0; }
}

@media print {
  @page { size: A4 portrait; margin: 10mm; }
  html, body { width: 210mm; min-width: 0; background: #fff; }
  .app-header, .control-panel, .preview-label, .usage-band, .site-footer, .output-gate { display: none !important; }
  .workspace, .sheet-stage { display: block; width: auto; min-height: 0; margin: 0; padding: 0; background: #fff; }
  .worksheet {
    width: 190mm;
    height: 277mm;
    min-height: 0;
    margin: 0;
    padding: 11mm 12mm 8mm;
    box-shadow: none;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
  }
  .worksheet-header { grid-template-columns: 32mm 1fr; }
  .problem-list { column-gap: 11mm; }
  .problem { min-height: 25mm; }
}
