:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --line: #e2e5ea;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --ok: #16803c;
  --ok-soft: #e6f6ec;
  --warn: #b54708;
  --warn-soft: #fff4e5;
  --bad: #c0262d;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Pretendard', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
#who { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px 16px 80px;
}
main.wide { max-width: 1100px; }

h1 { font-size: 22px; margin: 4px 0 4px; line-height: 1.35; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0 0 8px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin-bottom: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: #c5cad3; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 14px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn:disabled { opacity: .5; cursor: default; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spacer { flex: 1; }

label.field { display: block; margin-bottom: 12px; font-weight: 600; font-size: 14px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #cfd4dc;
  border-radius: 10px;
  font: inherit;
  font-size: 16px; /* 16px 미만이면 아이폰이 확대해 버림 */
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
input:disabled, textarea:disabled { background: #f3f4f6; color: var(--text); }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tabs button { flex: 1; }
.tabs .on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

.chip {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  background: #eef0f3;
  color: var(--muted);
  white-space: nowrap;
}
.chip.draft { background: var(--warn-soft); color: var(--warn); }
.chip.submitted { background: var(--accent-soft); color: var(--accent); }
.chip.returned { background: var(--ok-soft); color: var(--ok); }

.notice { padding: 12px 14px; border-radius: 10px; background: var(--accent-soft); color: #1e3a8a; font-size: 15px; margin-bottom: 14px; }
.notice.ok { background: var(--ok-soft); color: #14532d; }
.notice.warn { background: var(--warn-soft); color: #7a2e0e; }
.error { color: var(--bad); font-size: 14px; min-height: 1.4em; }

/* 활동지 */
.activity-list a.card { display: block; color: inherit; text-decoration: none; }
.activity-list a.card:hover { border-color: var(--accent); }

.section-title { font-size: 18px; margin: 26px 0 10px; padding-left: 10px; border-left: 4px solid var(--accent); }
.info p, .prompt p { margin: 0 0 6px; }
.figure { margin: 10px 0 4px; }
.figure-title { font-size: 14px; font-weight: 700; margin-bottom: 6px; }
.weather-map { width: 100%; height: auto; display: block; border-radius: 8px; }
.weather-legend { width: 100%; max-width: 300px; height: auto; display: block; margin-top: 10px; }

.q-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.q-no { font-weight: 700; color: var(--accent); }
.q-points { font-size: 13px; color: var(--muted); white-space: nowrap; }
.prompt { margin-bottom: 12px; }
.hint { white-space: pre-line; font-size: 14px; color: #444; background: #f7f7f2; border: 1px dashed #d8d4c0; border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; }

.choices { display: grid; gap: 8px; }
.choice {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  border: 1px solid #cfd4dc;
  border-radius: 10px;
  cursor: pointer;
}
.choice input { margin-top: 5px; width: 18px; height: 18px; flex: none; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice.correct { border-color: var(--ok); }

.answer-table { width: 100%; border-collapse: collapse; }
.answer-table th, .answer-table td { border: 1px solid var(--line); padding: 6px; vertical-align: top; }
.answer-table th { background: #f7f8fa; font-size: 14px; text-align: left; }
.answer-table td textarea { border: none; padding: 4px; min-height: 44px; }
.table-wrap { overflow-x: auto; }

.feedback {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--ok-soft);
  border: 1px solid #b7e4c7;
  font-size: 15px;
}
.feedback .score { font-weight: 700; color: var(--ok); }
.feedback p { margin: 4px 0 0; white-space: pre-line; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.savebar .inner { max-width: 860px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.save-state { font-size: 13px; color: var(--muted); flex: 1; }

/* 회로 시뮬레이션 */
.sim-help { font-size: 14px; color: #475467; margin-bottom: 8px; }
.circuit-board { max-width: 520px; margin: 0 auto; }
.circuit-svg { width: 100%; height: auto; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.circuit-svg .hit, .circuit-svg .part { cursor: pointer; }
.circuit-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.circuit-cell { min-width: 0; }
.tray { display: flex; gap: 8px; margin-top: 10px; }
.tray-item {
  flex: 1; min-height: 52px; border: 1px dashed #9aa1ab; border-radius: 10px; background: #fff;
  font: inherit; font-weight: 600; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
}
.tray-item .sub { margin: 0; font-size: 12px; font-weight: 500; }
.tray-item.on { border-style: solid; border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.tray-item:disabled { opacity: .4; cursor: default; }
.drag-ghost { position: fixed; z-index: 100; font-size: 34px; transform: translate(-50%, -50%); pointer-events: none; }
.sim-msg { margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 15px; background: var(--warn-soft); color: #7a2e0e; }
.sim-msg.ok { background: var(--ok-soft); color: #14532d; }
.gate-notice { text-align: center; }
.circuit-trio { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 12px; }
.bright-meter { margin-top: 6px; }
.bright-meter .sub { margin: 0; font-size: 12px; }
.bright-meter .bar { height: 10px; border-radius: 999px; background: #eef0f3; overflow: hidden; }
.bright-meter .bar div { height: 100%; background: #fab005; border-radius: 999px; }

@media (max-width: 560px) {
  .circuit-pair, .circuit-trio { grid-template-columns: 1fr; }
}

/* 교사 */
.list-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.list-table th, .list-table td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; }
.list-table th { font-size: 13px; color: var(--muted); font-weight: 600; }
.list-table tr.clickable { cursor: pointer; }
.list-table tr.clickable:hover { background: #f7f9ff; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 13px; color: var(--muted); }

.student-answer { background: #f7f8fa; border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; min-height: 44px; }
.student-answer.empty { color: var(--muted); font-style: italic; }
.guide { font-size: 14px; color: #475467; background: #fffbea; border: 1px solid #f3e3a1; border-radius: 8px; padding: 8px 12px; margin: 8px 0; white-space: pre-line; }
.grade-box { display: grid; grid-template-columns: 110px 1fr; gap: 8px; margin-top: 10px; align-items: start; }
.grade-box input[type=number] { text-align: center; }
.mark { font-weight: 700; margin-left: 6px; }
.mark.ok { color: var(--ok); }
.mark.no { color: var(--bad); }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 15px; cursor: pointer; }
.toggle input { width: 20px; height: 20px; }
.codes { font-family: Consolas, monospace; }
.shared-answer h3 { font-size: 15px; color: var(--muted); }

@media (max-width: 560px) {
  .grade-box { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  h1 { font-size: 20px; }
}

@media print {
  .topbar, .no-print { display: none !important; }
  body { background: #fff; }
}
