/* ==========================================================================
   오늘의 수학 공식 - 스타일
   중학생이 폰으로도 편하게 볼 수 있도록 글씨를 크게, 여백을 넉넉하게.
   ========================================================================== */

:root {
  --bg:          #f6f7fb;
  --bg-card:     #ffffff;
  --bg-sunken:   #eef1f8;
  --text:        #1c2331;
  --text-soft:   #5b6479;
  --text-faint:  #8d95a8;
  --line:        #dfe4ef;

  --accent:      #4f46e5;
  --accent-soft: #eef0ff;
  --accent-text: #4338ca;

  --green:       #128a5c;
  --green-soft:  #e2f6ed;
  --amber:       #b4690e;
  --amber-soft:  #fdf1dc;
  --red:         #c0392f;
  --red-soft:    #fdeceb;

  --radius:      18px;
  --radius-sm:   12px;
  --shadow:      0 2px 4px rgba(20,28,50,.05), 0 12px 28px rgba(20,28,50,.07);

  --font: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", -apple-system,
          BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg:          #12151d;
  --bg-card:     #1b202b;
  --bg-sunken:   #232937;
  --text:        #e9edf6;
  --text-soft:   #a9b2c6;
  --text-faint:  #79839a;
  --line:        #2e3546;

  --accent:      #8b8cf7;
  --accent-soft: #262a44;
  --accent-text: #b3b4ff;

  --green:       #4ed3a0;
  --green-soft:  #16342a;
  --amber:       #f5bd5e;
  --amber-soft:  #382f18;
  --red:         #ff8a80;
  --red-soft:    #3a2220;

  --shadow:      0 2px 4px rgba(0,0,0,.2), 0 12px 28px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.75;
  font-size: 17px;
  transition: background .25s ease, color .25s ease;
}

/* ---------------------------------------------------------------- 상단바 */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  background: none;
  border: 0;
  padding: 4px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
}

.topbar__icon { font-size: 22px; }

.topbar__title {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.02em;
}

.topbar__actions { display: flex; gap: 8px; }

.chip {
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: var(--text-soft);
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}

.chip:hover { color: var(--accent-text); border-color: var(--accent); }
.chip--icon { padding: 8px 11px; font-size: 15px; }

/* ---------------------------------------------------------------- 레이아웃 */

.stage {
  max-width: 760px;
  margin: 0 auto;
  padding: 26px 18px 70px;
}

.view { animation: fadeUp .35s ease; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- 날짜 배지 */

.daybar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.daybar__badge {
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  padding: 5px 13px;
  border-radius: 999px;
}

.daybar__date { color: var(--text-faint); font-size: 14px; font-weight: 600; }

.daybar__today {
  background: var(--green-soft);
  color: var(--green);
  font-weight: 800;
  font-size: 13px;
  padding: 4px 11px;
  border-radius: 999px;
}

/* ---------------------------------------------------------------- 히어로 */

.hero {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 26px;
  text-align: center;
  margin-bottom: 22px;
}

.hero__title {
  margin: 0;
  font-size: clamp(26px, 6vw, 36px);
  font-weight: 900;
  letter-spacing: -.03em;
  line-height: 1.25;
}

.hero__subtitle {
  margin: 8px 0 0;
  color: var(--accent-text);
  font-weight: 700;
  font-size: 15px;
}

.hero__formula {
  margin: 26px 0 4px;
  padding: 22px 12px;
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  overflow-y: hidden;
}

/* KaTeX 수식은 화면에서 주인공이므로 크게 */
.hero__formula .katex { font-size: clamp(1.5rem, 5.2vw, 2.4rem); }
.hero__formula .katex-display { margin: 0; }

.hero__oneline {
  margin: 20px 0 0;
  font-size: 17px;
  font-weight: 600;
  color: var(--text-soft);
}

/* ---------------------------------------------------------------- 블록 */

.block {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.block__head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -.02em;
}

.block__emoji { font-size: 20px; }

.block__hint {
  margin: -8px 0 14px;
  font-size: 14px;
  color: var(--text-faint);
}

.block--story { background: linear-gradient(180deg, var(--amber-soft), var(--bg-card) 60%); }
.block--link  { background: linear-gradient(180deg, var(--accent-soft), var(--bg-card) 60%); }

.prose p { margin: 0 0 12px; }
.prose p:last-child { margin-bottom: 0; }

.bullets { margin: 0; padding-left: 22px; }
.bullets li { margin-bottom: 9px; }
.bullets li:last-child { margin-bottom: 0; }

.story__who { margin: 0 0 12px; color: var(--amber); font-size: 15px; }
.story__who strong { font-size: 17px; margin-right: 8px; }

/* 본문 속 작은 수식 */
.katex { font-size: 1.06em; }

/* ---------------------------------------------------------------- 시각화 */

.viz {
  background: var(--bg-sunken);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.viz canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  touch-action: none;
}

.viz__controls {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 14px;
}

.viz__row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.viz__label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-soft);
  min-width: 76px;
}

.viz__value {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  color: var(--accent-text);
  min-width: 62px;
  text-align: right;
  font-size: 15px;
}

.viz__slider {
  flex: 1 1 130px;
  min-width: 110px;
  accent-color: var(--accent);
  height: 26px;
  cursor: pointer;
}

.viz__btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  transition: filter .15s ease;
}

.viz__btn:hover { filter: brightness(1.1); }

.viz__btn--ghost {
  background: transparent;
  color: var(--accent-text);
  border: 1px solid var(--line);
}

.viz__readout {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  line-height: 1.9;
}

.viz__readout .katex { font-size: 1.12em; }

.viz__readout b {
  font-variant-numeric: tabular-nums;
  color: var(--accent-text);
}

/* ---------------------------------------------------------------- 퀴즈 */

.block--quiz { background: linear-gradient(180deg, var(--green-soft), var(--bg-card) 55%); }

.quiz__q {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 16px;
}

.quiz__choices { display: flex; flex-direction: column; gap: 10px; }

.quiz__choice {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  text-align: left;
  font-family: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--bg-card);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  cursor: pointer;
  transition: all .15s ease;
  line-height: 1.6;
}

.quiz__choice:hover:not(:disabled) { border-color: var(--accent); transform: translateX(3px); }
.quiz__choice:disabled { cursor: default; }

.quiz__choice-key {
  flex-shrink: 0;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  background: var(--bg-sunken);
  color: var(--text-soft);
  font-weight: 800;
  font-size: 13px;
  display: grid;
  place-items: center;
  margin-top: 2px;
}

.quiz__choice--correct {
  border-color: var(--green);
  background: var(--green-soft);
}

.quiz__choice--correct .quiz__choice-key { background: var(--green); color: #fff; }

.quiz__choice--wrong {
  border-color: var(--red);
  background: var(--red-soft);
}

.quiz__choice--wrong .quiz__choice-key { background: var(--red); color: #fff; }

.quiz__input-row { display: flex; gap: 10px; flex-wrap: wrap; }

.quiz__input {
  flex: 1 1 140px;
  font-family: inherit;
  font-size: 17px;
  padding: 12px 15px;
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
}

.quiz__input:focus { outline: none; border-color: var(--accent); }

.quiz__verdict {
  margin-top: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  animation: fadeUp .3s ease;
}

.quiz__verdict--ok { background: var(--green-soft); border: 1px solid var(--green); }
.quiz__verdict--no { background: var(--amber-soft); border: 1px solid var(--amber); }
.quiz__verdict h3 { margin: 0 0 7px; font-size: 16px; }
.quiz__verdict p  { margin: 0; color: var(--text-soft); }

.quiz__retry {
  margin-top: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  background: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  color: var(--text-soft);
  cursor: pointer;
}

/* ---------------------------------------------------------------- 잡학 */

.funfact {
  background: var(--bg-sunken);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  margin-bottom: 26px;
}

.funfact__label {
  display: block;
  font-size: 13px;
  font-weight: 800;
  color: var(--accent-text);
  margin-bottom: 5px;
}

.funfact p { margin: 0; font-size: 15px; color: var(--text-soft); }

/* ---------------------------------------------------------------- 하단 이동 */

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

.pager__btn {
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  color: var(--text);
  cursor: pointer;
  transition: all .15s ease;
}

.pager__btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-text); }
.pager__btn:disabled { opacity: .35; cursor: not-allowed; }

.pager__fav {
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  color: var(--text-soft);
  cursor: pointer;
  transition: all .15s ease;
}

.pager__fav[data-on="true"] {
  background: var(--amber-soft);
  border-color: var(--amber);
  color: var(--amber);
}

/* ---------------------------------------------------------------- 아카이브 */

.archive__title {
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -.03em;
  margin: 0 0 6px;
}

.archive__desc { margin: 0 0 20px; color: var(--text-soft); font-size: 15px; }

.archive__stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.stat {
  flex: 1 1 100px;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
}

.stat__num {
  display: block;
  font-size: 26px;
  font-weight: 900;
  color: var(--accent-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stat__label { font-size: 13px; color: var(--text-faint); font-weight: 600; }

.archive__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 11px;
}

.card {
  position: relative;
  text-align: left;
  font-family: inherit;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px;
  cursor: pointer;
  color: var(--text);
  transition: all .15s ease;
  min-height: 92px;
}

.card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: var(--shadow);
}

.card--today { border-color: var(--accent); border-width: 2px; }

.card__day {
  font-size: 12px;
  font-weight: 800;
  color: var(--text-faint);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card__name {
  margin-top: 6px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.4;
}

.archive__legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 22px;
  font-size: 13px;
  color: var(--text-faint);
}

.archive__note {
  margin: 24px 0 10px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  font-size: 13px;
  color: var(--text-faint);
}

.archive__note strong { color: var(--text-soft); }

/* ---------------------------------------------------------------- 푸터 */

.footer {
  text-align: center;
  padding: 26px 18px 40px;
  color: var(--text-faint);
  font-size: 13px;
}

.footer p { margin: 0; }

/* ---------------------------------------------------------------- 폰 화면 */

@media (max-width: 520px) {
  body { font-size: 16px; }
  .stage { padding: 20px 14px 60px; }
  .hero { padding: 26px 18px; }
  .block { padding: 18px 17px; }
  .topbar__title { font-size: 15px; }
  .pager { gap: 8px; }
  .pager__btn { flex: 1 1 44%; padding: 11px 12px; font-size: 14px; }
  .pager__fav { flex: 1 1 100%; order: 3; }
  .archive__grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); }
  .archive__legend { gap: 8px 12px; font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
