:root {
  --bg: #f7f1e8;
  --panel: #fffdf9;
  --panel-soft: #f7fbfd;
  --text: #2d2823;
  --muted: #425058;
  --accent: #1c7aa5;
  --accent-strong: #145f80;
  --accent-soft: rgba(28, 122, 165, 0.10);
  --line: rgba(122, 111, 100, 0.18);
  --line-strong: rgba(28, 122, 165, 0.16);
  --shadow: 0 18px 36px rgba(53, 57, 62, 0.12);
  --radius-xl: 24px;
  --radius-lg: 20px;
  --radius-md: 16px;
  --space-1: 8px;
  --space-2: 12px;
  --space-3: 16px;
  --space-4: 20px;
  --space-5: 24px;
  --touch: 48px;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(145, 210, 236, 0.22), transparent 28%),
    radial-gradient(circle at bottom right, rgba(248, 214, 146, 0.24), transparent 24%),
    linear-gradient(180deg, #fbfaf7 0%, var(--bg) 100%);
}

a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1 {
  margin-bottom: var(--space-1);
  font-size: clamp(1.7rem, 6vw, 2.6rem);
  line-height: 1.2;
}

.page {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 16px 0 32px;
}

.hero,
.panel,
.ui-card,
.control-card,
.board,
.teacher-card,
.child-card,
.option-card,
.plain-card {
  background: var(--panel);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
}

.hero {
  position: relative;
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: var(--space-3);
  align-items: start;
  padding: var(--space-3);
  background: var(--hero-gradient, linear-gradient(120deg, #d7efff 0%, #a7d4f2 54%, #668fb2 100%));
}

.hero-icon {
  width: 72px;
  height: 72px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  font-size: 36px;
  background: rgba(255, 248, 223, 0.92);
  border: 4px solid rgba(255, 255, 255, 0.55);
}

.brand-ribbon,
.ui-badge,
.read-chip,
.memo-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.2;
}

.brand-ribbon {
  position: static;
  grid-column: 1 / -1;
  width: fit-content;
  margin-bottom: var(--space-2);
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid rgba(255, 255, 255, 0.5);
  color: #2b5b72;
  box-shadow: 0 8px 16px rgba(43, 91, 114, 0.12);
}

.hero > div:not(.hero-icon):not(.brand-ribbon) {
  min-width: 0;
}

.brand-logo {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 50%;
  background: #fff;
}

.hero p,
.muted,
.status,
.teacher-answer,
.instruction,
.feedback-box,
.option-card,
.plain-card,
.memo-box {
  color: var(--muted);
  line-height: 1.75;
}

.panel {
  margin-top: 16px;
  padding: var(--space-3);
}

.ui-section-header,
.controls,
.actions,
.teacher-panel,
.problem-view,
.option-row,
.mini-grid,
.logic-grid,
.map-grid {
  display: grid;
  gap: var(--space-2);
}

.controls {
  grid-template-columns: 1fr;
}

.control-card,
.ui-input-block {
  padding: 14px;
  border-radius: var(--radius-lg);
  border: 2px solid var(--line-strong);
  background: #fff;
  box-shadow: none;
}

label {
  display: block;
  margin-bottom: var(--space-1);
  font-size: 0.95rem;
  font-weight: 700;
}

select,
input,
textarea,
button,
.ui-button {
  width: 100%;
  min-height: var(--touch);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 2px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  font: inherit;
}

textarea { resize: vertical; }

button,
.ui-button {
  cursor: pointer;
  font-weight: 700;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

button.primary,
.ui-button.is-primary {
  color: #fff;
  background: var(--accent);
  border-color: transparent;
  box-shadow: 0 10px 18px rgba(28, 122, 165, 0.18);
}

button.primary:hover,
.ui-button.is-primary:hover {
  background: var(--accent-strong);
}

button.secondary,
.ui-button.is-secondary {
  background: var(--panel-soft);
}

button:disabled,
.ui-button.is-disabled,
.ui-button[aria-disabled='true'] {
  cursor: default;
  opacity: 0.55;
  box-shadow: none;
}

.actions {
  grid-template-columns: 1fr;
  margin-top: var(--space-3);
}

.status,
.ui-card--soft {
  margin-top: var(--space-3);
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: var(--panel-soft);
  border: 1px solid rgba(28, 122, 165, 0.10);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.board,
.ui-card,
.teacher-card,
.child-card {
  padding: var(--space-3);
  border: 1px solid var(--line);
  background: #fffefb;
  box-shadow: none;
}

.instruction,
.tip-banner,
.option-card,
.plain-card,
.memo-box,
.feedback-box {
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #f4fbff 0%, #fffdfa 100%);
}

.tip-banner {
  margin-bottom: var(--space-2);
  background: linear-gradient(90deg, #fff8dd 0%, #fffdf8 100%);
  border: 2px dashed rgba(140, 113, 33, 0.28);
  font-weight: 800;
  color: #73561f;
}

.keyword {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: #fff19d;
  color: #624700;
  font-weight: 800;
  font-size: 1rem;
}

.read-chip { background: #eef8ff; color: #245b7a; }
.memo-chip { background: #fff4d8; color: #7b5a18; }

.option-row,
.map-grid,
.logic-grid,
.mini-grid {
  grid-template-columns: 1fr;
}

.option-card,
.plain-card,
.teacher-card,
.child-card {
  min-width: 0;
}

.pattern-seq {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  font-size: clamp(1.35rem, 6vw, 2rem);
  font-weight: 800;
}

.mini-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.logic-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.map-grid { grid-template-columns: 1fr; }

.mini-cell,
.logic-cell {
  min-height: 72px;
  border-radius: 14px;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  background: #fff;
  text-align: center;
  padding: 8px;
}

.logic-cell { font-size: 1.45rem; }

.memo-box {
  min-height: 88px;
  background: #fffaf3;
  border-style: dashed;
}

.feedback-box {
  background: #f1fbf5;
  border-color: rgba(30, 138, 96, 0.15);
}


.pdf-summary-card {
  margin-top: var(--space-3);
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  background: rgba(28, 122, 165, 0.08);
  border: 1px solid rgba(28, 122, 165, 0.12);
  color: var(--muted);
  line-height: 1.7;
}

.pdf-summary-card strong {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
}

.pdf-stage {
  position: fixed;
  left: -99999px;
  top: 0;
  width: 794px;
  background: #fff;
  color: #111;
}

.print-sheet { display: none; }

@media (min-width: 640px) {
  .page { width: min(1180px, calc(100% - 32px)); }
  .controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .option-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .map-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 720px) {
  .page { padding-top: 24px; }
  .hero {
    grid-template-columns: 98px 1fr;
    gap: 18px;
    align-items: center;
    padding: 22px;
  }
  .hero-icon {
    width: 98px;
    height: 98px;
    font-size: 48px;
    border-radius: 28px;
  }
  .brand-ribbon {
    position: static;
    margin-bottom: var(--space-2);
    justify-self: start;
    max-width: 100%;
  }
  .actions {
    display: flex;
    flex-wrap: wrap;
  }
  .actions > * {
    width: auto;
    min-width: 180px;
  }
  .option-row { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .mini-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .logic-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (min-width: 940px) {
  .workspace { grid-template-columns: 1.22fr 0.95fr; }
}

@media print {
  @page { size: A4 portrait; margin: 10mm; }
  body { background: #fff; }
  .page { display: none !important; }
  .print-sheet {
    display: block;
    page-break-after: always;
    min-height: 270mm;
    padding: 2mm;
  }
  .print-sheet:last-child { page-break-after: auto; }
  .print-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8mm;
  }
  .print-title { font-size: 22px; font-weight: 800; }
  .print-subtitle,
  .print-note { margin-top: 4mm; font-size: 12px; line-height: 1.8; }
  .print-meta { font-size: 12px; line-height: 1.8; text-align: right; }
  .print-brand { display: flex; align-items: center; gap: 10px; }
  .print-logo {
    width: 42px;
    height: 42px;
    object-fit: cover;
    border-radius: 50%;
    background: #fff;
    border: 1px solid rgba(0, 0, 0, 0.08);
  }
}
