:root {
  --paper: #f2f6ef;
  --paper-deep: #e7eee3;
  --ink: #12231d;
  --muted: #66756f;
  --forest: #1f6b54;
  --forest-dark: #174c3e;
  --mint: #d9efe6;
  --lime: #d9ee88;
  --white: #fffefa;
  --line: rgba(18, 35, 29, 0.11);
  --danger: #b8463f;
  --danger-soft: #f8e3df;
  --success: #257657;
  --success-soft: #def2e7;
  --shadow: 0 24px 72px rgba(27, 56, 45, 0.13);
  --radius-xl: 36px;
  --radius-lg: 26px;
  --radius-md: 18px;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 8%, rgba(217, 238, 136, .36), transparent 25%),
    radial-gradient(circle at 92% 90%, rgba(31, 107, 84, .15), transparent 28%),
    var(--paper);
  font-family: Inter, ui-rounded, "SF Pro Rounded", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; }
button, [role="button"] { -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid rgba(31, 107, 84, .28); outline-offset: 3px; }
.hidden { display: none !important; }

.app-shell { width: 100%; height: 100dvh; }
.screen { width: 100%; height: 100%; }
.loading-screen, .error-screen { display: grid; place-items: center; text-align: center; }
.loading-screen { color: var(--muted); gap: 16px; align-content: center; }
.loader-mark, .brand-mark {
  display: grid;
  place-items: center;
  color: var(--white);
  background: var(--forest);
  font-family: Georgia, serif;
  font-weight: 700;
}
.loader-mark { width: 68px; height: 68px; border-radius: 24px; font-size: 2rem; animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: translateY(-5px); box-shadow: 0 18px 38px rgba(31, 107, 84, .25); } }

.library-screen {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: clamp(18px, 3vh, 34px);
  max-width: 1280px;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) clamp(22px, 5vw, 72px) max(20px, env(safe-area-inset-bottom));
}
.library-header, .quiz-header { display: flex; align-items: center; justify-content: space-between; }
.brand-lockup { display: flex; align-items: center; gap: 12px; font-size: .77rem; font-weight: 900; letter-spacing: .14em; }
.brand-mark { width: 38px; height: 38px; border-radius: 13px; font-size: 1.05rem; }
.today-stat { display: flex; align-items: baseline; gap: 10px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255, 254, 250, .68); }
.today-stat span { color: var(--muted); font-size: .78rem; font-weight: 750; }
.today-stat strong { color: var(--forest); font-size: .92rem; }
.library-copy { max-width: 760px; }
.eyebrow { margin: 0 0 10px; color: var(--forest); font-size: .72rem; font-weight: 900; letter-spacing: .15em; }
.library-copy h1 { margin: 0; max-width: 680px; font-size: clamp(2.45rem, 6vw, 5.6rem); line-height: .98; letter-spacing: -.065em; }
.library-copy h1 em { color: var(--forest); font-family: Georgia, "Times New Roman", serif; font-weight: 600; }
.library-copy > p:last-child { margin: 16px 0 0; color: var(--muted); font-size: clamp(.98rem, 1.6vw, 1.16rem); line-height: 1.6; }
.book-grid { min-height: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: clamp(12px, 2vw, 22px); align-items: stretch; }
.book-card {
  min-height: 0;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  text-align: left;
  padding: clamp(18px, 2.4vw, 30px);
  border: 1px solid rgba(255, 255, 255, .8);
  border-radius: var(--radius-xl);
  color: var(--ink);
  background: rgba(255, 254, 250, .78);
  box-shadow: 0 14px 42px rgba(27, 56, 45, .08);
  cursor: pointer;
  transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease;
}
.book-card:not(:disabled):hover { transform: translateY(-5px); box-shadow: var(--shadow); border-color: rgba(31, 107, 84, .22); }
.book-card.ready { background: linear-gradient(145deg, #235f4e, #174638); color: var(--white); }
.book-card.ready::after { content: ""; position: absolute; width: 170px; height: 170px; right: -60px; bottom: -68px; border-radius: 50%; background: rgba(217, 238, 136, .22); }
.book-card:disabled { opacity: .64; cursor: default; }
.book-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 20px; background: rgba(255, 255, 255, .86); font-size: 1.65rem; }
.book-card.ready .book-icon { background: rgba(255, 255, 255, .13); }
.book-card h2 { margin: auto 0 7px; padding-top: 18px; font-size: clamp(1.22rem, 2vw, 1.7rem); letter-spacing: -.04em; }
.book-card p { margin: 0; color: var(--muted); line-height: 1.45; font-size: .91rem; }
.book-card.ready p { color: rgba(255, 255, 255, .7); }
.book-card footer { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 20px; font-size: .82rem; font-weight: 850; }
.book-card footer span:last-child { position: relative; z-index: 1; }
.book-status { padding: 7px 10px; border-radius: 999px; background: var(--paper-deep); color: var(--muted); font-size: .72rem; }
.book-card.ready .book-status { background: var(--lime); color: var(--forest-dark); }
.library-footer { display: flex; align-items: center; justify-content: center; gap: 9px; color: var(--muted); font-size: .82rem; }
.verified-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--forest); box-shadow: 0 0 0 5px rgba(31, 107, 84, .1); }

.quiz-screen {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 15px;
  max-width: 1180px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) clamp(14px, 3vw, 38px) max(14px, env(safe-area-inset-bottom));
}
.quiz-header { gap: 14px; }
.round-button, .filter-button { border: 1px solid var(--line); color: var(--ink); background: rgba(255, 254, 250, .74); cursor: pointer; }
.round-button { width: 46px; height: 46px; flex: 0 0 auto; border-radius: 16px; font-size: 1.25rem; }
.quiz-title { min-width: 0; flex: 1; display: grid; gap: 2px; }
.quiz-title span { color: var(--forest); font-size: .72rem; font-weight: 900; letter-spacing: .08em; }
.quiz-title strong { font-size: 1.14rem; }
.filter-button { display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 15px; border-radius: 15px; color: var(--forest); font-size: .84rem; font-weight: 850; }
.quiz-stats { display: grid; grid-template-columns: repeat(2, minmax(84px, auto)) minmax(180px, 1fr); align-items: center; gap: 10px; }
.quiz-stats > div { min-height: 58px; display: grid; align-content: center; gap: 3px; padding: 10px 15px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255, 254, 250, .63); }
.quiz-stats span { color: var(--muted); font-size: .7rem; font-weight: 750; }
.quiz-stats strong { font-size: 1.02rem; }
.cycle-progress { grid-template-columns: auto 1fr; align-items: center; column-gap: 13px !important; }
.progress-track { height: 6px; overflow: hidden; border-radius: 999px; background: rgba(31, 107, 84, .12); }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--forest); transition: width .3s ease; }

.question-stage { min-height: 0; overflow: hidden; display: grid; grid-template-rows: minmax(0, 1fr) auto; border: 1px solid rgba(255,255,255,.82); border-radius: var(--radius-xl); background: rgba(255, 254, 250, .9); box-shadow: var(--shadow); }
.question-scroller { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: clamp(22px, 4vw, 48px); scrollbar-width: thin; }
.question-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.chapter-chip { padding: 8px 12px; border-radius: 999px; color: var(--forest); background: var(--mint); font-size: .76rem; font-weight: 900; }
.question-number { color: #85908b; font-size: .7rem; font-weight: 900; letter-spacing: .13em; }
.question-text { margin: clamp(20px, 3vh, 32px) 0 clamp(22px, 3vh, 34px); max-width: 940px; font-size: clamp(1.45rem, 3.2vw, 2.65rem); line-height: 1.35; letter-spacing: -.04em; text-wrap: balance; }
.question-media { max-width: 820px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin: -4px 0 24px; }
.question-media img { width: 100%; max-height: 300px; object-fit: contain; border: 1px solid var(--line); border-radius: 20px; background: white; }
.choice-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.choice-button { min-height: 72px; display: grid; grid-template-columns: 38px minmax(0, 1fr); align-items: center; gap: 13px; padding: 13px 17px; border: 1px solid var(--line); border-radius: 21px; color: var(--ink); background: #fbfcf8; text-align: left; line-height: 1.45; cursor: pointer; transition: transform .16s ease, border-color .16s ease, background .16s ease; }
.choice-button:hover:not(:disabled) { transform: translateY(-2px); border-color: rgba(31, 107, 84, .35); }
.choice-index { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 13px; color: var(--forest); background: var(--mint); font-weight: 900; }
.choice-button.correct { border-color: rgba(37, 118, 87, .45); background: var(--success-soft); }
.choice-button.correct .choice-index { color: white; background: var(--success); }
.choice-button.wrong { border-color: rgba(184, 70, 63, .42); background: var(--danger-soft); }
.choice-button.wrong .choice-index { color: white; background: var(--danger); }
.choice-button.dimmed { opacity: .48; }
.choice-button:disabled { cursor: default; }
.feedback-panel { margin-top: 20px; padding: 20px; border-radius: 22px; background: var(--success-soft); }
.feedback-panel.is-wrong { background: var(--danger-soft); }
.feedback-head { display: flex; align-items: center; gap: 13px; }
.feedback-icon { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 15px; color: white; background: var(--success); font-size: 1.2rem; font-weight: 950; }
.is-wrong .feedback-icon { background: var(--danger); }
.feedback-head strong { display: block; font-size: 1.05rem; }
.feedback-head p { margin: 4px 0 0; color: var(--muted); line-height: 1.4; }
.explanation-text { margin: 16px 0 0; padding-top: 16px; border-top: 1px solid rgba(18, 35, 29, .09); line-height: 1.65; }
.question-actions { display: flex; justify-content: flex-end; padding: 14px clamp(16px, 3vw, 28px) max(14px, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: rgba(255, 254, 250, .95); }
.primary-action, .secondary-action { width: min(100%, 520px); min-height: 52px; border-radius: 17px; padding: 0 19px; font-weight: 900; cursor: pointer; }
.primary-action { border: 0; color: white; background: var(--forest); box-shadow: 0 12px 26px rgba(31, 107, 84, .2); }
.primary-action span { margin-left: 10px; }
.secondary-action { border: 1px solid var(--line); color: var(--forest); background: var(--mint); }

.chapter-dialog { width: min(620px, calc(100% - 24px)); max-height: min(760px, calc(100dvh - 24px)); padding: 0; border: 0; border-radius: 30px; color: var(--ink); background: var(--white); box-shadow: 0 32px 100px rgba(18,35,29,.28); }
.chapter-dialog::backdrop { background: rgba(18, 35, 29, .44); backdrop-filter: blur(5px); }
.chapter-sheet { max-height: inherit; display: grid; grid-template-rows: auto auto auto minmax(0,1fr) auto; gap: 14px; padding: 24px; }
.sheet-handle { display: none; width: 44px; height: 5px; margin: -10px auto 0; border-radius: 999px; background: rgba(18,35,29,.15); }
.chapter-sheet header { display: flex; justify-content: space-between; align-items: center; }
.chapter-sheet h2 { margin: 0; font-size: 1.55rem; }
.all-chapters-button { min-height: 44px; border: 1px solid var(--line); border-radius: 15px; color: var(--forest); background: var(--mint); font-weight: 850; cursor: pointer; }
.chapter-grid { min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.chapter-option { position: relative; }
.chapter-option input { position: absolute; opacity: 0; pointer-events: none; }
.chapter-option span { min-height: 48px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 15px; color: var(--muted); font-weight: 850; cursor: pointer; }
.chapter-option input:checked + span { color: white; border-color: var(--forest); background: var(--forest); }

.error-card { max-width: 440px; padding: 36px; border-radius: 30px; background: var(--white); box-shadow: var(--shadow); }
.error-card > span { width: 50px; height: 50px; display: grid; place-items: center; margin: 0 auto; border-radius: 18px; color: white; background: var(--danger); font-weight: 950; }
.error-card h1 { margin: 18px 0 8px; font-size: 1.55rem; }
.error-card p { margin: 0 0 20px; color: var(--muted); line-height: 1.5; }

@media (max-width: 900px) {
  .book-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quiz-stats { grid-template-columns: repeat(2, 1fr); }
  .cycle-progress { grid-column: 1 / -1; min-height: 44px !important; }
}

@media (max-width: 620px) {
  .library-screen { gap: 18px; padding: max(16px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom)); }
  .brand-lockup > span:last-child { display: none; }
  .library-copy h1 { font-size: clamp(2.35rem, 12vw, 3.6rem); }
  .library-copy > p:last-child { font-size: .9rem; }
  .book-grid { gap: 10px; }
  .book-card { min-height: 150px; padding: 16px; border-radius: 25px; }
  .book-icon { width: 44px; height: 44px; border-radius: 16px; font-size: 1.35rem; }
  .book-card h2 { font-size: 1.05rem; }
  .book-card p { display: none; }
  .book-card footer { margin-top: 10px; font-size: .7rem; }
  .library-footer { font-size: .72rem; }
  .quiz-screen { gap: 10px; padding: max(10px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .quiz-header { padding: 0 4px; }
  .quiz-title strong { font-size: 1rem; }
  .filter-button { padding: 0 11px; max-width: 128px; }
  .filter-button span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .quiz-stats { gap: 6px; }
  .quiz-stats > div { min-height: 49px; padding: 7px 10px; border-radius: 15px; }
  .quiz-stats span { font-size: .63rem; }
  .quiz-stats strong { font-size: .9rem; }
  .cycle-progress { display: none !important; }
  .question-stage { border-radius: 26px; }
  .question-scroller { padding: 20px 17px; }
  .question-text { margin: 17px 0 21px; font-size: clamp(1.34rem, 6vw, 1.8rem); line-height: 1.38; }
  .question-media { grid-template-columns: 1fr; margin-bottom: 18px; }
  .question-media img { max-height: 220px; }
  .choice-list { grid-template-columns: 1fr; gap: 9px; }
  .choice-button { min-height: 58px; grid-template-columns: 34px minmax(0, 1fr); gap: 11px; padding: 10px 12px; border-radius: 17px; font-size: .92rem; }
  .choice-index { width: 34px; height: 34px; border-radius: 11px; }
  .feedback-panel { padding: 16px; }
  .question-actions { padding: 9px 10px max(9px, env(safe-area-inset-bottom)); }
  .primary-action, .secondary-action { width: 100%; min-height: 46px; }
  .chapter-dialog { width: 100%; max-height: 82dvh; margin: auto 0 0; border-radius: 28px 28px 0 0; }
  .sheet-handle { display: block; }
  .chapter-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-height: 700px) and (max-width: 620px) {
  .library-copy > p:last-child, .library-footer { display: none; }
  .library-screen { gap: 12px; }
  .book-card { min-height: 126px; }
  .question-text { margin: 13px 0 16px; }
  .quiz-stats { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
