:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #16181d;
  --muted: #69707d;
  --line: #dfe3e8;
  --accent: #1d5b47;
  --accent-soft: #eaf4f0;
  --danger: #a33c32;
  --ai: #f0f3f6;
  --student: #e9f1ff;
  --shadow: 0 14px 42px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", "Noto Sans KR", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
button, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 64px; }
.topbar { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 18px; }
.eyebrow { margin: 0 0 6px; font-size: 13px; font-weight: 800; letter-spacing: .08em; color: var(--accent); }
h1 { margin: 0; font-size: clamp(28px, 4vw, 42px); letter-spacing: -.04em; }
h2 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
p { line-height: 1.65; }

.session-badge { padding: 10px 14px; border: 1px solid var(--line); border-radius: 12px; background: white; text-align: right; box-shadow: 0 4px 14px rgba(0,0,0,.04); }
.session-badge span { display: block; color: var(--muted); font-size: 12px; }
.session-badge strong { font-size: 18px; letter-spacing: .08em; }

.notice { border-radius: 14px; padding: 14px 16px; margin-bottom: 18px; border: 1px solid #d8e7e1; background: var(--accent-soft); color: #2f4c42; }
.notice strong { display: inline-block; margin-right: 8px; color: #143c2f; }
.notice a { color: #165b9a; font-weight: 800; text-decoration: none; }
.notice a:hover { text-decoration: underline; }

.panel, .chat-panel, .status-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); }
.setup-panel { padding: clamp(20px, 4vw, 36px); }
.intro-copy { white-space: pre-line; line-height: 1.75; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #fafbfc; color: #333943; }
.section-heading { display: flex; gap: 12px; align-items: center; margin: 30px 0 14px; }
.section-heading.compact { margin-top: 24px; }
.section-heading p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }
.step { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: white; font-weight: 800; }

.topic-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.topic-card, .choice-btn { border: 1px solid var(--line); background: white; color: var(--ink); border-radius: 14px; padding: 16px; text-align: left; transition: .15s ease; }
.topic-card:hover, .choice-btn:hover { border-color: #9ab9ad; transform: translateY(-1px); }
.topic-card.selected, .choice-btn.selected { border: 2px solid var(--accent); background: var(--accent-soft); }
.topic-card strong { display: block; margin-bottom: 5px; }
.topic-card span { display: block; color: var(--muted); font-size: 14px; line-height: 1.5; }
.position-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice-btn { text-align: center; font-weight: 800; font-size: 17px; }
.field { display: grid; gap: 8px; margin-top: 12px; }
.field span { font-weight: 700; }
textarea { width: 100%; resize: vertical; min-height: 90px; border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; outline: none; line-height: 1.55; background: white; }
textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(29,91,71,.09); }
.primary-btn, .secondary-btn { border: 0; border-radius: 12px; padding: 12px 17px; font-weight: 800; }
.primary-btn { background: var(--accent); color: white; }
.secondary-btn { background: #edf0f3; color: var(--ink); }
.setup-panel > .primary-btn { width: 100%; margin-top: 24px; padding: 14px; }
.error-text { color: var(--danger); min-height: 1.4em; font-size: 14px; }

.debate-layout { display: grid; grid-template-columns: 280px minmax(0,1fr); gap: 18px; align-items: start; }
.status-card { padding: 18px; position: sticky; top: 18px; }
.status-row { padding: 12px 0; border-bottom: 1px solid var(--line); }
.status-row span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.status-row strong { display: block; font-size: 14px; line-height: 1.5; }
.turn-card { margin-top: 16px; padding: 16px; border-radius: 14px; background: #f6f8f9; }
.turn-card > span { color: var(--muted); font-size: 12px; }
.turn-card strong { display: block; margin: 4px 0; font-size: 24px; }
.turn-card small { color: var(--muted); line-height: 1.45; }

.chat-panel { overflow: hidden; }
.messages { min-height: 480px; max-height: 66vh; overflow-y: auto; padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.message { max-width: 86%; border-radius: 16px; padding: 13px 15px; white-space: pre-wrap; line-height: 1.65; border: 1px solid transparent; }
.message.student { align-self: flex-end; background: var(--student); border-bottom-right-radius: 5px; }
.message.ai { align-self: flex-start; background: var(--ai); border-bottom-left-radius: 5px; }
.message.notice { max-width: 100%; align-self: stretch; background: #fff8e7; border: 1px solid #f0dfb4; color: #594b27; text-align: center; font-size: 14px; }
.message.invalid { outline: 1px dashed #d59891; }
.meta { display: block; margin-bottom: 4px; color: var(--muted); font-size: 11px; font-weight: 700; }
.composer { border-top: 1px solid var(--line); padding: 16px; background: #fbfcfd; }
.composer textarea { min-height: 100px; }
.composer-bottom { margin-top: 8px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.composer-bottom span { color: var(--muted); font-size: 12px; }
.finish-bar { border-top: 1px solid var(--line); padding: 14px 16px; background: var(--accent-soft); display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.finish-bar p { margin: 0; font-size: 14px; color: #2f4c42; }

.loading { opacity: .65; pointer-events: none; }

.report-panel { padding: clamp(20px, 4vw, 34px); }
.report-heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; border-bottom: 1px solid var(--line); padding-bottom: 18px; }
.report-meta { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; margin: 20px 0; }
.report-meta > div, .score-card { padding: 15px; border: 1px solid var(--line); border-radius: 14px; }
.report-meta span, .score-card span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 5px; }
.score-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.score-card strong { font-size: 24px; }
.score-card p { margin-bottom: 0; color: #434a55; }
.grade-box { margin: 16px 0; padding: 18px; border-radius: 14px; background: var(--accent-soft); display: flex; justify-content: space-between; align-items: center; }
.grade-box strong { font-size: 30px; }
.overall { padding: 18px; border: 1px solid var(--line); border-radius: 14px; line-height: 1.8; }

@media (max-width: 780px) {
  .shell { width: min(100% - 20px, 1180px); padding-top: 20px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .session-badge { text-align: left; }
  .topic-grid, .score-grid, .report-meta { grid-template-columns: 1fr; }
  .debate-layout { grid-template-columns: 1fr; }
  .status-card { position: static; }
  .messages { min-height: 420px; max-height: 58vh; padding: 14px; }
  .message { max-width: 94%; }
  .finish-bar, .report-heading { align-items: stretch; flex-direction: column; }
}

/* 자료 기반 반론 */
.message-text { white-space: pre-wrap; }
.source-box {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid #d7dce2;
  display: grid;
  gap: 9px;
}
.source-heading { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.source-heading strong { font-size: 13px; color: #26323b; }
.source-heading span { color: var(--muted); font-size: 11px; }
.source-item {
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  border-radius: 11px;
  border: 1px solid #d8dde3;
  background: rgba(255,255,255,.8);
}
.source-item > strong { font-size: 13px; line-height: 1.5; }
.source-badge {
  width: fit-content;
  padding: 3px 7px;
  border-radius: 999px;
  background: #e8f1ed;
  color: #245343;
  font-size: 10px;
  font-weight: 800;
}
.source-publisher { color: var(--muted); font-size: 11px; }
.source-item p { margin: 3px 0; font-size: 12px; line-height: 1.55; color: #424a54; }
.source-item a { width: fit-content; color: #165b9a; font-size: 12px; font-weight: 800; text-decoration: none; }
.source-item a:hover { text-decoration: underline; }

/* 성취기준 기반 피드백 */
.standard-box {
  margin: 18px 0 24px;
  padding: 16px 18px;
  border-radius: 14px;
  background: #f6f8f9;
  border: 1px solid var(--line);
}
.standard-box span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.standard-box strong { line-height: 1.65; }
.feedback-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; margin-bottom: 24px; }
.feedback-card { padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.feedback-card h4 { margin: 0 0 14px; font-size: 17px; }
.feedback-part + .feedback-part { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.feedback-part span { display: block; color: var(--accent); font-size: 12px; font-weight: 800; margin-bottom: 5px; }
.feedback-part p { margin: 0; color: #3d444f; line-height: 1.7; }
.feedback-evidence { margin-top: 14px; color: var(--muted); font-size: 12px; }
.feedback-evidence summary { cursor: pointer; font-weight: 800; }
.feedback-evidence ul { padding-left: 18px; line-height: 1.6; }
.report-transcript-section { margin-top: 30px; padding-top: 24px; border-top: 1px solid var(--line); }
.report-help { margin: 5px 0 14px; color: var(--muted); font-size: 13px; }
.report-transcript { display: grid; gap: 10px; }
.report-transcript .message { max-width: 100%; align-self: stretch; }

@media (max-width: 780px) {
  .feedback-grid { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4 portrait; margin: 11mm 12mm; }

  html, body { background: white; font-size: 10pt; }
  body { margin: 0; }
  .shell { width: 100%; margin: 0; padding: 0; }
  .topbar, .privacy-note, .evidence-note, #setupView, #debateView, .report-heading button { display: none !important; }
  #reportView { display: block !important; border: 0; box-shadow: none; padding: 0; }

  /* 인쇄에서는 화면용 큰 카드/간격 때문에 A4가 비는 현상을 줄인다. */
  .report-heading { padding-bottom: 8px; margin-bottom: 8px; }
  .report-heading .eyebrow { margin-bottom: 2px; font-size: 9pt; }
  .report-heading h2 { font-size: 17pt; }
  .report-meta { gap: 6px; margin: 8px 0; }
  .report-meta > div { padding: 8px 10px; border-radius: 8px; }
  .report-meta span { margin-bottom: 2px; font-size: 8.5pt; }
  .report-meta strong { line-height: 1.4; }
  .standard-box { margin: 8px 0 10px; padding: 9px 11px; border-radius: 8px; }
  .standard-box span { margin-bottom: 3px; font-size: 8.5pt; }
  .standard-box strong { line-height: 1.5; }
  #reportContent > h3 { margin: 10px 0 6px; font-size: 13pt; break-after: avoid; }

  /* grid + break-inside:avoid 조합이 큰 빈 공간/빈 페이지를 만들 수 있어 인쇄 시 블록 흐름으로 전환한다. */
  .feedback-grid { display: block; margin-bottom: 10px; }
  .feedback-card { margin: 0 0 8px; padding: 10px 12px; border-radius: 8px; box-shadow: none; break-inside: auto; page-break-inside: auto; }
  .feedback-card h4 { margin: 0 0 7px; font-size: 12pt; break-after: avoid; }
  .feedback-part + .feedback-part { margin-top: 7px; padding-top: 7px; }
  .feedback-part span { margin-bottom: 2px; font-size: 8.5pt; break-after: avoid; }
  .feedback-part p { line-height: 1.55; orphans: 3; widows: 3; }
  .feedback-evidence { margin-top: 7px; font-size: 8.5pt; break-inside: auto; }
  .feedback-evidence > * { display: block; }
  .feedback-evidence ul { margin: 5px 0 0; padding-left: 16px; line-height: 1.45; }

  .overall { padding: 10px 12px; border-radius: 8px; line-height: 1.6; break-inside: auto; page-break-inside: auto; }
  .report-transcript-section { margin-top: 12px; padding-top: 10px; }
  .report-transcript-section h3 { margin: 0 0 4px; break-after: avoid; }
  .report-help { margin: 3px 0 7px; font-size: 8.5pt; }
  .report-transcript { display: block; }
  .report-transcript .message { max-width: 100%; margin: 0 0 7px; padding: 8px 10px; border-radius: 7px; background: white !important; border: 1px solid #bbb; box-shadow: none; break-inside: auto; page-break-inside: auto; line-height: 1.5; }
  .report-transcript .message.student,
  .report-transcript .message.notice { break-inside: avoid; page-break-inside: avoid; }
  .message-text { orphans: 3; widows: 3; }
  .meta { margin-bottom: 2px; font-size: 8pt; }

  .source-box { display: block; margin-top: 7px; padding-top: 7px; }
  .source-heading { margin-bottom: 5px; break-after: avoid; }
  .source-item { display: block; margin: 0 0 6px; padding: 7px 8px; border-radius: 7px; break-inside: auto; page-break-inside: auto; }
  .source-item > strong, .source-publisher, .source-badge { display: block; }
  .source-item > strong { margin: 3px 0 1px; }
  .source-item p { margin: 3px 0; line-height: 1.45; orphans: 2; widows: 2; }
  .source-claim, .source-relevance { padding-top: 4px; }

  /* 제목만 페이지 끝에 남지 않도록 하고, 카드 전체를 다음 장으로 밀지는 않는다. */
  h2, h3, h4, .source-heading, .feedback-part span { break-after: avoid; page-break-after: avoid; }

  a { color: black; text-decoration: none; word-break: break-word; overflow-wrap: anywhere; }
  /* 브라우저가 PDF 링크 자체를 보존하므로 긴 URL을 본문에 다시 인쇄하지 않는다. */
  .source-item a::after { content: none; }
}

/* 느슨한 참여 지원 + 권장 횟수 이전 종료 */
.support-hint {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f7f8fa;
  color: #59616c;
  font-size: 12px;
  line-height: 1.55;
}
.support-hint strong { color: #343b45; }
.finish-bar.early {
  background: #fff8e7;
  border-top-color: #ead8a7;
}
.finish-bar.early p { color: #654f1e; }
.finish-bar.early .secondary-btn {
  background: #fff;
  border: 1px solid #d7bd76;
}
.source-claim, .source-relevance {
  margin: 4px 0 0 !important;
  padding-top: 6px;
  border-top: 1px dashed #d8dde3;
  color: #3f4852 !important;
}
.source-relevance { color: #4f5965 !important; }
.topic-definition {
  display: block;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px dashed #dfe3e7;
  color: #59616c;
  font-size: 11px;
  line-height: 1.55;
}
