:root {
  color-scheme: light;
  --bg: #f5f3f1;
  --surface: #ffffff;
  --surface-soft: #f4eeee;
  --text: #1a1a1a;
  --muted: #66615f;
  --line: #ded8d4;
  --primary: #c8102e;
  --primary-strong: #9f0c24;
  --ink: #111111;
  --paper: #fffdfb;
  --radius: 6px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(200, 16, 46, 0.08) 0 8px, transparent 8px 100%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter, Pretendard, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  overflow-x: hidden;
}

button {
  font: inherit;
}

h1,
h2,
h3,
h4,
h5,
p {
  overflow-wrap: break-word;
  word-break: keep-all;
}

.app-header {
  max-width: 1180px;
  margin: 0 auto;
  padding: 34px 20px 18px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(30px, 4vw, 46px);
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.25;
  letter-spacing: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.12fr) minmax(320px, 0.88fr);
  gap: 20px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 24px;
}

.question-panel,
.result-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(17, 17, 17, 0.08);
}

.question-panel {
  min-height: 560px;
  padding: 24px;
  border-top: 5px solid var(--primary);
}

.progress-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  margin-bottom: 28px;
}

#progress-label {
  color: var(--primary);
  font-size: 14px;
  font-weight: 900;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 180ms ease;
}

.question-stage {
  display: block;
}

.question-meta {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 3px 9px;
  border-radius: var(--radius);
  background: #fff0f2;
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 900;
}

#question-title {
  margin-top: 18px;
  min-height: 116px;
  font-size: clamp(22px, 2.7vw, 30px);
  line-height: 1.32;
  overflow-wrap: anywhere;
}

.scale-controls {
  display: grid;
  gap: 10px;
  margin-top: 30px;
}

.scale-option {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 54px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.scale-option:hover {
  border-color: #d77a8b;
  background: #fff7f8;
}

.scale-option[aria-checked="true"] {
  border-color: var(--primary);
  background: #fff0f2;
  box-shadow: inset 0 0 0 1px var(--primary);
}

.scale-dot {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.scale-option[aria-checked="true"] .scale-dot {
  background: var(--primary);
  color: #ffffff;
}

.nav-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 28px;
}

.primary-button,
.secondary-button {
  min-width: 120px;
  min-height: 46px;
  padding: 0 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 900;
  cursor: pointer;
}

.primary-button {
  background: var(--primary);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--primary-strong);
}

.secondary-button {
  border-color: var(--line);
  background: #ffffff;
  color: var(--text);
}

.secondary-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.result-panel {
  padding: 22px;
  border-top: 5px solid var(--ink);
}

.result-header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.ranking-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.rank-item {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.rank-item:first-child {
  border-color: rgba(200, 16, 46, 0.45);
  background: #fff8f9;
}

.rank-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.rank-name {
  font-weight: 900;
}

.rank-score {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.score-track {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.score-bar {
  height: 100%;
  border-radius: inherit;
  width: 0;
}

.result-detail {
  margin-top: 18px;
  padding: 16px;
  border-radius: var(--radius);
  background: #faf8f7;
  color: var(--text);
}

.locked-result {
  display: grid;
  gap: 6px;
  min-height: 132px;
  place-items: center;
  padding: 24px;
  border: 1px dashed #b9aaa6;
  border-radius: var(--radius);
  background: #faf8f7;
  color: var(--muted);
  text-align: center;
}

.locked-result strong {
  color: var(--text);
  font-size: 28px;
}

.waiting-visual {
  display: grid;
  gap: 14px;
}

.waiting-visual img {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.waiting-visual strong {
  display: block;
  margin-bottom: 6px;
  font-size: 18px;
}

.waiting-visual p {
  margin: 0;
  color: var(--muted);
}

.app-shell.is-result-mode {
  grid-template-columns: minmax(0, 1fr);
}

.app-shell.is-result-mode .question-panel {
  display: none;
}

.app-shell.is-result-mode .result-panel {
  padding: 28px;
}

.app-shell.is-result-mode .ranking-list {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.school-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.school-link {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text);
  font-weight: 900;
  cursor: pointer;
}

.school-link.is-active {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.result-hero {
  padding: 22px;
  border-left: 6px solid var(--school-color, var(--primary));
  background: #ffffff;
}

.result-hero h3 {
  margin: 4px 0 10px;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 1.08;
}

.reveal-label {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 900;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.info-block {
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.info-block h4 {
  margin: 0 0 10px;
  font-size: 18px;
}

.info-block p,
.info-block ul {
  margin: 0;
}

.info-block ul {
  padding-left: 18px;
}

.fact-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 0 !important;
  list-style: none;
}

.fact-list li {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-left: 4px solid var(--primary);
  background: #faf8f7;
}

.fact-list span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.fact-list strong {
  font-size: 14px;
}

.block-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 12px;
}

.block-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.semester-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.semester-card {
  min-height: 180px;
  padding: 14px;
  border: 1px solid #e9e2df;
  border-radius: var(--radius);
  background: #fffdfb;
}

.semester-card h5 {
  margin: 0 0 10px;
  color: var(--primary);
  font-size: 16px;
}

.semester-card p {
  margin: 8px 0 0;
  font-size: 13px;
}

.reference-note {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--muted);
}

.app-footer {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 34px;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 880px) {
  .app-header,
  .app-shell,
  .info-grid,
  .app-shell.is-result-mode .ranking-list,
  .fact-list,
  .semester-grid {
    grid-template-columns: 1fr;
  }

  .source-box {
    min-width: 0;
  }

  body {
    background: var(--bg);
  }

  .app-header {
    width: 100%;
    max-width: 100%;
    padding: 22px 16px 12px;
  }

  h1 {
    font-size: 30px;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 100%;
    gap: 14px;
    padding: 0 14px 18px;
    overflow: hidden;
  }

  .question-panel {
    width: 100%;
    max-width: 100%;
    min-height: auto;
    padding: 18px;
    box-shadow: 0 10px 28px rgba(17, 17, 17, 0.07);
  }

  .result-panel {
    width: 100%;
    max-width: 100%;
    padding: 18px;
    box-shadow: 0 10px 28px rgba(17, 17, 17, 0.07);
  }

  .progress-row {
    margin-bottom: 20px;
  }

  #question-title {
    min-height: auto;
    margin-top: 14px;
    font-size: 24px;
    word-break: normal;
    overflow-wrap: anywhere;
  }

  .scale-controls {
    margin-top: 22px;
  }

  .scale-option {
    width: 100%;
    min-height: 50px;
  }

  .locked-result {
    min-height: 82px;
    padding: 16px;
  }

  .waiting-visual img {
    max-height: 260px;
  }

  .app-shell.is-result-mode .result-panel {
    padding: 18px;
  }

  .result-hero {
    padding: 18px;
  }

}

@media (max-width: 520px) {
  body {
    min-width: 0;
  }

  .app-header {
    width: 100%;
    max-width: 100vw;
    padding: 18px 12px 10px;
  }

  h1 {
    font-size: 27px;
  }

  .app-shell {
    width: 100%;
    max-width: 100vw;
    padding: 0 10px 14px;
  }

  .question-panel,
  .result-panel {
    width: 100%;
    max-width: calc(100vw - 20px);
    border-radius: 8px;
  }

  .question-panel {
    padding: 16px;
  }

  .result-panel {
    padding: 16px;
  }

  .progress-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  #progress-label {
    font-size: 13px;
  }

  #question-title {
    font-size: 21px;
    line-height: 1.35;
  }

  .question-meta {
    min-height: 26px;
    font-size: 12px;
  }

  .scale-option {
    grid-template-columns: 30px minmax(0, 1fr);
    max-width: 100%;
    min-height: 48px;
    padding: 10px 12px;
  }

  .scale-dot {
    width: 26px;
    height: 26px;
  }

  .result-header {
    padding-bottom: 12px;
  }

  .ranking-list {
    margin-top: 12px;
  }

  .result-detail {
    margin-top: 12px;
    padding: 10px;
  }

  .waiting-visual img {
    max-width: 100%;
    max-height: 220px;
  }

  .locked-result strong {
    font-size: 24px;
  }

  .nav-row {
    flex-direction: column-reverse;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }
}

/* 1학년 내신 A비율 표 (결과 화면) */
.achievement-table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 6px;
  font-size: 0.92rem;
}
.achievement-table th,
.achievement-table td {
  border-bottom: 1px solid #ece8e4;
  padding: 7px 6px;
  text-align: center;
}
.achievement-table thead th {
  color: #8a8178;
  font-weight: 600;
  border-bottom: 2px solid #e2dcd6;
}
.achievement-table td:first-child {
  text-align: left;
  font-weight: 600;
  color: #2b2b2b;
}

/* ── 질문 이미지 ── */
.question-visual { display:none; margin:14px 0; }
.question-visual.has-img { display:block; }
.question-visual img { width:100%; max-height:230px; object-fit:cover; border-radius:14px; }

/* ── 편제표 보기 버튼 ── */
.pyeonje-open-btn{ width:100%; margin:14px 0 4px; padding:14px; border:0; border-radius:12px;
  background:#1f3b5c; color:#fff; font-size:1rem; font-weight:700; cursor:pointer; }
.pyeonje-open-btn:hover{ background:#16304d; }

/* ── 편제표 모달 ── */
.pyeonje-modal{ position:fixed; inset:0; background:rgba(0,0,0,.5); z-index:50;
  display:flex; align-items:flex-start; justify-content:center; padding:20px; overflow:auto; }
.pyeonje-modal[hidden]{ display:none; }
.pyeonje-dialog{ background:#fff; border-radius:16px; width:min(1180px,96vw); max-width:1180px;
  padding:0 0 20px; box-shadow:0 12px 40px rgba(0,0,0,.3); }
.pyeonje-bar{ position:sticky; top:0; background:#2f9c9c; color:#fff; border-radius:16px 16px 0 0;
  display:flex; align-items:center; justify-content:space-between; padding:12px 18px; }
.pyeonje-bar h3{ margin:0; font-size:1.2rem; }
.pyeonje-close{ background:transparent; border:0; color:#fff; font-size:1.2rem; cursor:pointer; }
.track-buttons{ display:flex; flex-wrap:wrap; gap:6px; padding:12px 18px 4px; }
.track-btn{ border:1px solid #cdd6e0; background:#f4f6f9; border-radius:999px; padding:6px 12px;
  font-size:.86rem; cursor:pointer; }
.track-btn.is-active{ background:#1f3b5c; color:#fff; border-color:#1f3b5c; }
.pyeonje-legend{ padding:4px 18px 8px; font-size:.85rem; color:#555; }
.pyeonje-legend em{ color:#888; font-style:normal; }
.lg{ display:inline-block; width:13px; height:13px; border-radius:3px; vertical-align:middle; margin:0 2px 0 8px; border:1px solid #bbb;}
.lg-Y{ background:#f4a8a8;} .lg-G{ background:#bde3bf;} .lg-B{ background:#ffe082;}

.pj-sec-title{ font-weight:700; color:#1f3b5c; margin:14px 18px 6px; font-size:1.02rem; }
.pj-grid{ display:grid; gap:6px; padding:0 18px; }
.pj-grid-6{ grid-template-columns:repeat(6,1fr); }
.pj-grid-4{ grid-template-columns:repeat(4,1fr); }
.pj-col{ display:flex; flex-direction:column; gap:4px; }
.pj-head{ background:#1f3b5c; color:#fff; text-align:center; font-weight:700; font-size:.82rem;
  padding:6px 2px; border-radius:6px; }
.pj-cell{ font-size:.82rem; text-align:center; padding:5px 4px; border-radius:5px; }
.pj-common{ background:#e4f1df; }
.pj-cell b{ color:#1f3b5c; }
.pj-grp{ border:1px solid #d7deea; border-radius:7px; padding:5px; }
.pj-grp-label{ font-size:.74rem; font-weight:700; color:#1f3b5c; text-align:center; margin-bottom:3px; }
.pj-opt{ font-size:.8rem; text-align:center; padding:4px 3px; border-radius:4px; background:#f2f2f2; margin:2px 0; }
.pj-opt.hl-Y{ background:#f4a8a8; } .pj-opt.hl-G{ background:#bde3bf; } .pj-opt.hl-B{ background:#ffe082; }
.pj-opt.dim{ background:#f2f2f2; color:#999; }
@media (max-width:760px){ .pj-grid-6,.pj-grid-4{ grid-template-columns:repeat(2,1fr); } }

/* 선택과목 제목 옆 인라인 범례 */
.pj-leg{ font-size:.78rem; font-weight:400; color:#666; margin-left:8px; }
.pj-leg .lg{ margin:0 2px 0 6px; }

/* 편제표 버튼 강조(오버라이드) */
.pyeonje-open-btn{
  margin:20px 0 8px; padding:20px 16px; font-size:1.18rem; font-weight:800;
  background:linear-gradient(135deg,#2f9c9c 0%,#1f3b5c 100%); color:#fff;
  border:0; border-radius:14px; cursor:pointer; letter-spacing:.3px;
  box-shadow:0 6px 18px rgba(31,59,92,.35);
  animation:pjpulse 1.8s ease-in-out infinite;
}
.pyeonje-open-btn:hover{ filter:brightness(1.08); transform:translateY(-1px); }
@keyframes pjpulse{
  0%,100%{ box-shadow:0 6px 16px rgba(47,156,156,.30); }
  50%{ box-shadow:0 8px 28px rgba(47,156,156,.75); }
}

/* 완료 전 결과패널 숨김 + 버튼 아래 진행 n/20 */
#result-panel{ display:none; }
#app-shell.is-result-mode #result-panel{ display:block; }
.answer-count{ text-align:center; margin:14px 0 2px; font-weight:800; color:#1f3b5c; font-size:1.05rem; letter-spacing:.5px; }
#app-shell.is-result-mode .answer-count{ display:none; }

/* 브랜딩: 우상단 학원 / 하단 제공처 */
.app-header{ display:flex; align-items:center; justify-content:space-between; gap:10px; }
.brand-academy{ flex-shrink:0; font-weight:800; color:#1f3b5c; font-size:.92rem; background:#eef2f6; padding:6px 13px; border-radius:999px; white-space:nowrap; }
.brand-footer{ display:flex; align-items:center; justify-content:center; gap:10px; padding:18px 12px 26px; margin-top:14px; color:#6b7280; font-size:.9rem; border-top:1px solid #ececec; }
.brand-footer img{ height:28px; width:auto; }
.pyeonje-foot{ display:flex; align-items:center; justify-content:center; gap:8px; padding:14px; color:#888; font-size:.85rem; border-top:1px solid #eee; margin-top:6px; }
.pyeonje-foot img{ height:22px; width:auto; }
