/* 숏폼 플레이어: 세로 화면 한 장에 메시지 하나, 옆으로 넘긴다 */

html, body { height: 100%; }

body.short-page {
  --h: 100vh;
  --h: 100dvh;
  overflow: hidden;
  background: #07080a;
}

.stage {
  position: relative;
  height: var(--h);
  width: min(100vw, calc(var(--h) * 0.5625));
  margin: 0 auto;
  overflow: hidden;
  background: var(--bg);
  container-type: size;
}

/* 넓은 화면에서는 세로 화면을 가운데에 띄운다 */
@media (min-width: 700px) and (min-height: 560px) {
  body.short-page { --h: min(100dvh - 40px, 900px); }
  .stage {
    top: calc((100dvh - var(--h)) / 2);
    border-radius: 28px;
    box-shadow: 0 0 0 1px var(--line), 0 30px 80px rgba(0, 0, 0, 0.5);
  }
}

.deck {
  display: flex;
  height: 100%;
  margin: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  font-size: clamp(14px, 4.4cqw, 22px);
}

.deck::-webkit-scrollbar { display: none; }

.card {
  flex: 0 0 100%;
  height: 100%;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  justify-content: safe center;
  gap: 1.1em;
  padding: 4.8em 1.5em 2.6em;
  overflow-y: auto;
  scrollbar-width: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.card::-webkit-scrollbar { display: none; }

/* --- 글 --- */

.card h2 {
  margin: 0;
  font-size: 1.85em;
  line-height: 1.24;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.card p {
  margin: 0;
  line-height: 1.62;
  color: var(--soft);
  text-wrap: pretty;
}

.card em { font-style: normal; color: var(--accent); }
.card h2 em { white-space: nowrap; }
.card strong { color: var(--text); font-weight: 700; }

.card .kicker {
  font-size: 0.78em;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
}

.card .note {
  font-size: 0.82em;
  color: var(--muted);
}

.c-q { color: var(--accent); }
.c-k { color: var(--key); }
.c-v { color: var(--value); }

/* 첫 장: 질문 하나만 크게 */
.card.hook {
  background: radial-gradient(120% 55% at 0% 0%, rgba(255, 216, 77, 0.12), transparent 62%);
}

.card.hook h2 { font-size: 2.5em; line-height: 1.18; }

.card .hint {
  margin-top: 1.4em;
  font-size: 0.8em;
  color: var(--muted);
}

/* 끝 장: 다음 편으로 */
.card.end {
  background: radial-gradient(120% 55% at 100% 100%, rgba(255, 216, 77, 0.12), transparent 62%);
}

.next-link {
  display: block;
  margin-top: 0.6em;
  padding: 1em 1.1em;
  border-radius: 1em;
  background: var(--accent);
  color: var(--on-accent);
  text-decoration: none;
}

.next-link small { display: block; font-size: 0.78em; font-weight: 700; opacity: 0.7; }
.next-link b { display: block; margin-top: 0.15em; font-size: 1.12em; line-height: 1.35; }
.next-link b::after { content: "  →"; white-space: pre; }

.up-link {
  align-self: flex-start;
  font-size: 0.85em;
  color: var(--muted);
  text-underline-offset: 0.25em;
}

.next-link:focus-visible,
.up-link:focus-visible,
.hud a:focus-visible,
.nav:focus-visible,
.pick button:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}

/* --- 그림 부품 --- */

.box {
  padding: 1em;
  border: 1px solid var(--line);
  border-radius: 1em;
  background: var(--surface);
}

.box > .label {
  display: block;
  margin-bottom: 0.6em;
  font-size: 0.76em;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--muted);
}

.stack { display: grid; gap: 0.7em; }

.arrow {
  font-size: 1.1em;
  line-height: 1;
  text-align: center;
  color: var(--muted);
}

/* 단어 칩 */
.tokens {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4em;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tokens > * {
  padding: 0.34em 0.7em;
  border-radius: 0.6em;
  background: var(--surface-2);
  font-size: 0.92em;
  font-weight: 600;
  line-height: 1.4;
}

.tokens .on { background: var(--accent); color: var(--on-accent); }
.tokens .dim { opacity: 0.32; }
.tokens .fade-1 { opacity: 0.75; }
.tokens .fade-2 { opacity: 0.5; }
.tokens .fade-3 { opacity: 0.28; }
.tokens .fade-4 { opacity: 0.14; }

/* 벡터: 숫자 묶음 */
.vec {
  display: inline-flex;
  gap: 0.25em;
  font-family: var(--mono);
  font-size: 0.8em;
  vertical-align: middle;
}

.vec i {
  padding: 0.3em 0.5em;
  border: 1px solid var(--line);
  border-radius: 0.4em;
  background: var(--surface-2);
  font-style: normal;
}

.vec.on i { border-color: var(--accent); color: var(--accent); }

.pairs { display: grid; gap: 0.6em; }

.pairs > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6em;
}

.pairs > div > span { font-weight: 600; }

/* 막대: --v 는 0~1 */
.bars {
  display: grid;
  gap: 0.5em;
  margin: 0;
  padding: 0;
  list-style: none;
}

.bars li {
  display: grid;
  grid-template-columns: 4.4em 1fr 2.9em;
  align-items: center;
  gap: 0.6em;
  font-size: 0.86em;
}

.bars span { font-weight: 600; color: var(--muted); white-space: nowrap; }
.bars b { font-family: var(--mono); font-size: 0.92em; font-weight: 600; text-align: right; }

.bars i {
  position: relative;
  height: 0.95em;
  overflow: hidden;
  border-radius: 0.3em;
  background: var(--surface-2);
}

.bars i::after {
  content: "";
  position: absolute;
  inset: 0;
  width: calc(var(--v) * 100%);
  border-radius: inherit;
  background: #6d7383;
  transition: width 0.35s ease;
}

.bars .on span { color: var(--text); }
.bars .on i::after { background: var(--accent); }

/* 계산 과정 */
.calc {
  display: grid;
  gap: 0.35em;
  font-family: var(--mono);
  font-size: 0.86em;
}

.calc > div { display: flex; justify-content: space-between; gap: 1em; }
.calc > div > span {
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
  color: var(--soft);
}

.calc .sum {
  margin-top: 0.3em;
  padding-top: 0.6em;
  border-top: 1px solid var(--line);
  font-weight: 700;
}

.calc .sum b { color: var(--accent); }

/* 단어 / 식 / 값 세 칸 */
.calc.named > div { display: grid; grid-template-columns: 4.4em 1fr auto; gap: 0.6em; }
.calc.named .sum span { grid-column: span 2; }

/* 번호 붙은 단계 */
.steps {
  display: grid;
  gap: 0.6em;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  display: grid;
  grid-template-columns: 2em 1fr;
  align-items: center;
  column-gap: 0.8em;
  padding: 0.8em 0.9em;
  border: 1px solid var(--line);
  border-radius: 0.9em;
  background: var(--surface);
  counter-increment: step;
}

.steps li::before {
  content: counter(step);
  grid-row: span 2;
  display: grid;
  place-items: center;
  width: 2em;
  height: 2em;
  border-radius: 50%;
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 0.86em;
  font-weight: 700;
  color: var(--muted);
}

.steps b { font-size: 1em; }
.steps span { font-size: 0.84em; color: var(--muted); }
.steps .on { border-color: var(--accent); }
.steps .on::before { background: var(--accent); color: var(--on-accent); }

/* 용어 풀이 */
.defs { display: grid; gap: 0.6em; margin: 0; }

.defs > div {
  display: grid;
  grid-template-columns: 3.2em 1fr;
  align-items: baseline;
  gap: 0.8em;
  padding: 0.8em 0.9em;
  border: 1px solid var(--line);
  border-radius: 0.9em;
  background: var(--surface);
}

.defs dt { font-weight: 800; }
.defs dd { margin: 0; line-height: 1.5; }
.defs small { display: block; font-size: 0.82em; color: var(--muted); }

/* 코드 한 줄 + 뜻 */
.lines {
  display: grid;
  gap: 0.35em;
  margin: 0;
  padding: 0;
  list-style: none;
}

.lines li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8em;
  padding: 0.6em 0.8em;
  border-radius: 0.6em;
  background: var(--surface);
}

.lines code { font-family: var(--mono); font-size: 0.78em; white-space: nowrap; }
.lines span { font-size: 0.78em; font-weight: 700; white-space: nowrap; color: var(--muted); }

.formula {
  font-family: var(--mono);
  font-size: 1.02em;
  line-height: 1.7;
  text-align: center;
}

/* 단어 고르기 (눌러 보는 카드) */
.pick { display: flex; flex-wrap: wrap; gap: 0.4em; }

.pick button {
  padding: 0.4em 0.7em;
  border: 1px solid var(--line);
  border-radius: 0.6em;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 0.88em;
  font-weight: 600;
  cursor: pointer;
}

.pick button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

/* --- 위쪽 진행 표시 --- */

.hud {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 5;
  padding: 0.9em 1em 1.6em;
  background: linear-gradient(var(--bg) 55%, transparent);
  font-size: clamp(14px, 4.4cqw, 22px);
  pointer-events: none;
}

.progress { display: flex; gap: 4px; }

.progress i {
  flex: 1;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.2);
  transition: background 0.25s ease;
}

.progress i.done { background: var(--text); }

.hud-row {
  display: flex;
  justify-content: space-between;
  gap: 1em;
  margin-top: 0.8em;
  font-size: 0.72em;
  color: var(--muted);
}

.hud-row a { pointer-events: auto; text-decoration: none; }
.hud-row a:hover { color: var(--text); }
.hud-count { font-family: var(--mono); white-space: nowrap; }

/* 넓은 화면용 좌우 버튼 */
.nav {
  display: none;
  position: fixed;
  top: 50%;
  width: 48px;
  height: 48px;
  margin-top: -24px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.nav:hover { border-color: var(--muted); }
.nav:disabled { opacity: 0.3; cursor: default; }
.nav.prev { right: calc(50% + var(--h) * 0.28125 + 20px); }
.nav.next { left: calc(50% + var(--h) * 0.28125 + 20px); }

@media (min-width: 900px) and (min-height: 560px) {
  .nav { display: block; }
}

/* --- 등장 효과: 스크립트가 켜졌을 때만 숨겼다가 보여 준다 --- */

.js .card > * {
  opacity: 0;
  transform: translateY(0.7em);
  transition: opacity 0.45s ease, transform 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.js .card.seen > * { opacity: 1; transform: none; }
.js .card.seen > :nth-child(2) { transition-delay: 0.07s; }
.js .card.seen > :nth-child(3) { transition-delay: 0.14s; }
.js .card.seen > :nth-child(4) { transition-delay: 0.21s; }
.js .card.seen > :nth-child(5) { transition-delay: 0.28s; }
.js .card.seen > :nth-child(n + 6) { transition-delay: 0.35s; }

.js .card:not(.seen) .bars i::after { width: 0; }
.js .card.seen .bars i::after { transition: width 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) 0.3s; }

@media (prefers-reduced-motion: reduce) {
  .js .card > *,
  .js .card.seen > * { opacity: 1; transform: none; transition: none; }
  .js .card .bars i::after,
  .js .card.seen .bars i::after { width: calc(var(--v) * 100%); transition: none; }
}
