/* 기획서 9.1 아트 디렉션: 손그림 캐주얼 */
:root {
  --bg: #ECE9E2; /* 살짝 누런 종이 */
  --year-gray: #3F3F3F;
  --ink: #221D19;
  --ink-soft: #5a5049;
  --paper: #fdfdfc;
  --hl: #FFD43B;
  --era-modern: #A98FDB;
  --era-early-modern: #7FA9DB;
  --era-renaissance: #8DCB9C;
  --era-medieval: #F2C95B;
  --era-ancient: #EE9C72;
  --era-end: #C9A47C;
  --good: #3c9a5f;
  --bad: #d4503e;
  --r: 13px 17px 14px 18px / 17px 13px 18px 14px;
  --r2: 18px 12px 16px 13px / 12px 17px 13px 18px;
  --shadow: 0 4px 0 rgba(34, 29, 25, .12), 0 10px 24px rgba(34, 29, 25, .08);
  --f-num: 'Dela Gothic One', 'Black Han Sans', system-ui, sans-serif;
  --f-title: 'Black Han Sans', 'Jua', system-ui, sans-serif;
  --f-cute: 'Jua', 'Gowun Dodum', system-ui, sans-serif;
  --f-body: 'Gowun Dodum', 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  --era: var(--era-modern);
}

/* 종이 질감 (9.1): 큰 얼룩(mottle)은 배경에, 종이 결(부드러운 요철에 빛을 비춘 엠보스)은 화면 전체 위에 아주 옅게 덮는다 */
:root {
  --paper-mottle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='600'%3E%3Cfilter id='m'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.012' numOctaves='4' seed='3'/%3E%3CfeColorMatrix values='0 0 0 0 .45  0 0 0 0 .38  0 0 0 0 .28  0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3C/svg%3E");
  --paper-tooth: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='p' x='0' y='0' width='100%25' height='100%25'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.035' numOctaves='5' stitchTiles='stitch' result='n'/%3E%3CfeDiffuseLighting in='n' lighting-color='%23fff' surfaceScale='1.6'%3E%3CfeDistantLight azimuth='45' elevation='60'/%3E%3C/feDiffuseLighting%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23p)'/%3E%3C/svg%3E");
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  background-image: var(--paper-tooth);
  mix-blend-mode: multiply;
  opacity: .16;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  background-image: var(--paper-mottle);
  color: var(--ink);
  font-family: var(--f-body);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
.hidden { display: none !important; }
mark, .hl {
  background: linear-gradient(100deg, transparent 2%, var(--hl) 4%, var(--hl) 94%, transparent 97%) 0 72% / 100% 46% no-repeat;
  color: inherit;
  padding: 0 .1em;
}
kbd {
  font-family: var(--f-body);
  font-size: .7em;
  border: 1.5px solid currentColor;
  border-radius: 5px;
  padding: 0 .35em;
  margin-left: .35em;
  opacity: .55;
  vertical-align: middle;
}

/* ---------- ① 배경 도달 연도 ---------- */
#bg-year {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 0;
  user-select: none;
}
.bg-num {
  font-family: var(--f-num);
  font-size: min(34vw, 46vh);
  line-height: 1;
  color: var(--year-gray);
  opacity: .22;
  letter-spacing: -.02em;
  transition: color .8s, opacity .4s, transform .4s cubic-bezier(.3, 1.6, .5, 1);
  font-variant-numeric: tabular-nums;
}
.bg-bc {
  font-family: var(--f-title);
  font-size: min(9vw, 11vh);
  color: var(--year-gray);
  opacity: 0;
  transition: opacity .4s;
  margin-bottom: -.1em;
}
#bg-year.bc .bg-bc { opacity: .3; }
#bg-year.thump .bg-num { opacity: .42; transform: scale(1.04); }
#bg-year.shake .bg-num { animation: shake .4s; }
@keyframes shake {
  20% { transform: translateX(-8px) rotate(-1deg); }
  40% { transform: translateX(7px) rotate(1deg); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

/* ---------- 공통 ---------- */
.screen {
  position: relative;
  z-index: 1;
  min-height: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
}
.card {
  position: relative;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
.tape {
  position: absolute;
  top: -12px;
  left: 50%;
  width: 92px;
  height: 22px;
  transform: translateX(-50%) rotate(-3deg);
  background: rgba(255, 212, 59, .55);
  border-left: 2px dashed rgba(255, 255, 255, .6);
  border-right: 2px dashed rgba(255, 255, 255, .6);
}
.btn {
  font-family: var(--f-cute);
  font-size: 18px;
  color: var(--ink);
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: var(--r2);
  padding: 10px 18px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform .08s, box-shadow .08s, background .15s;
}
.btn:hover { background: #fff6d6; }
.btn:active, .btn.pressed { transform: translateY(3px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--hl); }
.btn.primary:hover { background: #ffdf66; }
.btn.big { font-size: 24px; padding: 14px 34px; }
.btn.mini { font-size: 14px; padding: 4px 10px; box-shadow: 0 2px 0 var(--ink); }
.btn:focus-visible { outline: 3px solid var(--era-early-modern); outline-offset: 2px; }

/* ---------- 타이틀 ---------- */
.title-wrap {
  min-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
}
.logo h1 {
  font-family: var(--f-title);
  font-size: clamp(54px, 15vw, 96px);
  font-weight: 400;
  line-height: 1;
  margin: 4px 0 0;
  letter-spacing: .03em;
  text-shadow: 3px 3px 0 var(--hl);
}
.logo-small { font-family: var(--f-cute); font-size: 18px; color: var(--ink-soft); }
.tagline { font-family: var(--f-cute); font-size: 19px; line-height: 1.6; margin: 0; }
.rules { text-align: left; padding: 18px 20px 14px; max-width: 460px; }
.rules ol { margin: 0; padding-left: 22px; line-height: 1.7; font-size: 16px; }
.best { font-family: var(--f-cute); font-size: 16px; min-height: 1em; }
.data-status { font-size: 12px; color: var(--ink-soft); max-width: 460px; line-height: 1.5; }

/* ---------- 플레이 ---------- */
#screen-play {
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100vh;
  height: 100dvh;
  min-height: 560px;
  max-width: 1240px; /* 연표는 넓게, 상태 바·카드·버튼은 760px 안에 */
}
#screen-play > .statusbar, #screen-play > .control-layer { width: 100%; max-width: 728px; margin: 0 auto; }
.statusbar {
  /* 왼쪽: 목숨·체인 / 가운데: 거슬러 올라간 햇수(기록) / 오른쪽: 설정 */
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  grid-template-areas: "left back right";
  align-items: center;
  gap: 6px 14px;
  font-family: var(--f-cute);
  font-size: 18px;
}
.hud-left { grid-area: left; display: flex; align-items: center; gap: 14px; }
.hud-back { grid-area: back; text-align: center; white-space: nowrap; }
.hud-back b { font-size: 20px; }
.hud b { font-family: var(--f-num); font-weight: 400; font-size: 16px; }
.hud-actions { grid-area: right; justify-self: end; display: flex; gap: 6px; }
#hud-lives { letter-spacing: 2px; display: inline-block; }
#hud-lives .lost { filter: grayscale(1); opacity: .3; }
#hud-lives.break { animation: shake .4s; }
#hud-lives.gain { animation: gain .5s; }
@keyframes gain { 40% { transform: scale(1.25); } }
.sr-year { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.timeline-layer {
  flex: 0 0 auto;
  height: clamp(220px, 38vh, 330px);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#timeline {
  flex: 1;
  width: 100%;
  overflow: hidden; /* 카메라 밖으로 밀려난 막대는 가장자리에서 자름 (9.5) */
  border-top: 2px dashed rgba(34, 29, 25, .25);
  border-bottom: 2px dashed rgba(34, 29, 25, .25);
  touch-action: pan-y;
}
.tl-tick { stroke: rgba(34, 29, 25, .25); stroke-width: 1; }
.tl-tick-label { font-family: var(--f-body); font-size: 11px; fill: var(--ink-soft); }
.tl-bar { stroke: var(--ink); stroke-width: 2; }
.tl-name { font-family: var(--f-cute); font-size: 13px; fill: var(--ink); paint-order: stroke; stroke: var(--bg); stroke-width: 4px; }
.tl-baseline { stroke: var(--ink); stroke-width: 2; stroke-dasharray: 5 4; }
.tl-base-label { font-family: var(--f-cute); font-size: 12px; fill: var(--ink); paint-order: stroke; stroke: var(--bg); stroke-width: 4px; }
.tl-baton { fill: var(--hl); opacity: .85; }
.tl-q { fill: var(--paper); stroke: var(--ink); stroke-width: 2; stroke-dasharray: 4 3; }
.tl-q-text { font-family: var(--f-num); font-size: 15px; fill: var(--ink); }
.tl-callout { font-family: var(--f-cute); font-size: 14px; fill: var(--ink); paint-order: stroke; stroke: var(--paper); stroke-width: 5px; }
.tl-gap { stroke: var(--bad); stroke-width: 2; stroke-dasharray: 3 3; fill: none; }
.tl-chip-bg { fill: var(--paper); stroke: var(--ink); stroke-width: 2; }
.tl-chip-text { font-family: var(--f-cute); font-size: 12px; fill: var(--ink); }

.minimap {
  position: relative;
  height: 16px;
  border: 2px solid var(--ink);
  border-radius: 9px 7px 10px 8px;
  overflow: visible;
  background: var(--paper);
}
.mm-seg { position: absolute; top: 0; bottom: 0; opacity: .3; }
.mm-seg.done { opacity: 1; }
.mm-runner { position: absolute; top: -7px; font-size: 18px; transform: translateX(-50%) scaleX(-1); transition: left .9s cubic-bezier(.3, 1.3, .5, 1); }
.mm-flag { position: absolute; top: -14px; font-size: 13px; transform: translateX(-20%); }
.mm-label { position: absolute; top: 17px; font-size: 10px; color: var(--ink-soft); white-space: nowrap; }
.mm-label.l { left: 0; }
.mm-label.r { right: 0; }

.control-layer {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 12px;
  min-height: 0;
  padding-top: 18px;
}
.cand {
  padding: 22px 20px 16px;
  transition: transform .35s cubic-bezier(.3, 1.6, .5, 1);
}
.cand.flip { animation: flip .5s; }
@keyframes flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(80deg) scale(.98); }
  100% { transform: rotateX(0); }
}
.cand.enter { animation: pop .4s cubic-bezier(.3, 1.6, .5, 1); }
@keyframes pop { from { transform: translateY(16px) scale(.96); opacity: 0; } }
.cand-top { display: flex; gap: 14px; align-items: center; }
.portrait {
  flex: 0 0 auto;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 2px solid var(--ink);
  overflow: hidden;
  background: #e2e2df;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--f-title);
  font-size: 30px;
  color: var(--ink-soft);
}
.portrait img { width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; }
.cand-name { font-family: var(--f-title); font-size: 26px; line-height: 1.15; }
.cand-en { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.cand-desc { font-size: 15px; margin-top: 4px; }
.badge { display: inline-block; font-family: var(--f-cute); font-size: 12px; border: 1.5px solid var(--ink); border-radius: 8px; padding: 0 6px; margin-left: 6px; vertical-align: middle; background: var(--paper); }
.question { font-family: var(--f-cute); font-size: 19px; margin-top: 14px; text-align: center; line-height: 1.5; }
.reveal { margin-top: 12px; border-top: 2px dashed rgba(34, 29, 25, .2); padding-top: 10px; text-align: center; }
.reveal-dates { font-size: 15px; line-height: 1.6; }
.reveal-result { font-family: var(--f-cute); font-size: 21px; margin-top: 4px; }
.reveal-note { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.reveal-more { font-size: 12px; color: var(--ink-soft); margin-top: 6px; text-align: left; }
.reveal-more summary { cursor: pointer; text-align: center; }
.reveal-more div { margin-top: 6px; line-height: 1.5; word-break: break-all; }
.stamp {
  position: absolute;
  top: 10px;
  right: 14px;
  font-family: var(--f-title);
  font-size: 30px;
  width: 70px;
  height: 70px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 4px solid currentColor;
  border-radius: 50%;
  transform: rotate(-14deg);
  animation: stamp .35s cubic-bezier(.3, 1.8, .5, 1);
  background: rgba(255, 255, 255, .6);
}
.stamp.good { color: var(--good); }
.stamp.bad { color: var(--bad); }
@keyframes stamp { from { transform: rotate(-14deg) scale(2.2); opacity: 0; } }
.answer-row { display: flex; gap: 10px; }
.answer-row .btn { flex: 1; font-size: 20px; padding: 14px 8px; }
.answer.yes:hover { background: #e3eefc; }
.answer.no:hover { background: #fde8e4; }

.milestone {
  position: fixed;
  left: 50%;
  top: 30%;
  z-index: 10;
  transform: translate(-50%, -50%) rotate(-6deg);
  font-family: var(--f-title);
  font-size: clamp(28px, 8vw, 48px);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: var(--r);
  padding: 10px 26px;
  box-shadow: var(--shadow);
  animation: stamp .45s cubic-bezier(.3, 1.8, .5, 1);
  pointer-events: none;
}

/* ---------- 설정 ---------- */
.statusbar { position: relative; }
.opt { font-family: var(--f-cute); font-size: 15px; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.opt input { width: 18px; height: 18px; accent-color: var(--ink); cursor: pointer; }
.settings-pop { position: absolute; right: 0; top: 40px; z-index: 20; padding: 12px 14px; font-size: 15px; }

/* ---------- 첫 주자 뽑기 ---------- */
.draw-title { font-family: var(--f-title); font-size: 18px; text-align: center; margin-bottom: 12px; }
.draw .cand-name { transition: transform .08s; }
.draw.tick .portrait, .draw.tick .cand-name { animation: tick .14s; }
@keyframes tick { 0% { transform: translateY(-6px); opacity: .4; } 100% { transform: none; opacity: 1; } }
.draw.landed { animation: pop .45s cubic-bezier(.3, 1.8, .5, 1); }
.draw-born { font-family: var(--f-cute); font-size: 18px; text-align: center; margin-top: 14px; line-height: 1.5; }
.draw .stamp { font-size: 20px; }

/* ---------- 결과 ---------- */
#screen-result { max-width: none; padding-left: max(16px, 3vw); padding-right: max(16px, 3vw); }
.result-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; padding-top: 24px; text-align: center; }
.result-label { font-family: var(--f-cute); font-size: 20px; }
.result-year { font-family: var(--f-num); font-size: clamp(44px, 14vw, 88px); line-height: 1; }
.result-who { font-family: var(--f-title); font-size: 24px; }
.result-stats { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; font-family: var(--f-cute); font-size: 16px; }
.result-chain-card { width: 100%; padding: 18px 12px 12px; }
.result-chain-card h3 { font-family: var(--f-title); font-weight: 400; margin: 0 0 6px; font-size: 18px; }
.chain-scroll { overflow-x: auto; }
.result-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.toast { font-family: var(--f-cute); background: var(--ink); color: var(--paper); border-radius: 10px; padding: 6px 14px; }

@media (max-width: 520px) {
  .statusbar { font-size: 16px; gap: 6px 10px; grid-template-columns: 1fr auto; grid-template-areas: "left right" "back back"; }
  .cand { padding: 20px 14px 14px; }
  .cand-name { font-size: 22px; }
  .portrait { width: 64px; height: 64px; }
  .question { font-size: 17px; }
  .answer-row .btn { font-size: 18px; }
  kbd { display: none; }
}

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

/* ---------- 순위표 (7.3) ---------- */
.board-card { width: 100%; max-width: 560px; padding: 16px 14px 12px; text-align: left; }
.board-card h3, .board-dialog h3 { font-family: var(--f-title); font-weight: 400; margin: 0 0 10px; font-size: 20px; text-align: center; }
.board-mode { font-family: var(--f-body); font-size: 12px; color: var(--ink-soft); margin-left: 4px; }
.board-form { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
.board-form input {
  font-family: var(--f-cute); font-size: 17px; padding: 8px 12px; min-width: 0; flex: 1; max-width: 260px;
  border: 2.5px solid var(--ink); border-radius: var(--r2); background: var(--paper); color: var(--ink);
}
.board-form input:focus-visible { outline: 3px solid var(--era-early-modern); outline-offset: 1px; }
.board-msg { font-family: var(--f-cute); font-size: 15px; text-align: center; min-height: 1.2em; margin-bottom: 4px; }
.board-msg.err { color: var(--bad); }
.board-table table { width: 100%; border-collapse: collapse; font-size: 14px; }
.board-table th { font-family: var(--f-cute); font-weight: 400; font-size: 13px; color: var(--ink-soft); text-align: left; padding: 2px 6px 6px; border-bottom: 2px solid var(--ink); }
.board-table td { padding: 6px; border-bottom: 1px dashed rgba(34, 29, 25, .2); vertical-align: top; }
.board-table td.rk { font-family: var(--f-num); width: 2.6em; text-align: center; }
.board-table td.yr b { font-family: var(--f-cute); font-weight: 400; font-size: 15px; }
.board-table td.yr small { display: block; color: var(--ink-soft); font-size: 12px; }
.board-table td.num { text-align: right; white-space: nowrap; font-family: var(--f-cute); }
.board-table tr.me td { background: color-mix(in srgb, var(--hl) 45%, transparent); }
.board-table tr.gap td { text-align: center; color: var(--ink-soft); border-bottom: none; padding: 0; }
.board-empty { text-align: center; color: var(--ink-soft); font-family: var(--f-cute); padding: 10px 0; }
.board-dialog { position: fixed; inset: 0; margin: auto; height: fit-content; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); overflow: auto; padding: 20px 16px 14px; border: 0; color: var(--ink); }
.board-dialog::backdrop { background: rgba(34, 29, 25, .35); }
.board-dialog form { text-align: center; margin-top: 12px; }

/* 버전 표시 (9.2) — 기획서 문서 버전을 그대로 보여 준다 */
#screen-title { position: relative; }
.app-ver { position: absolute; right: 16px; bottom: 12px; font-size: 12px; color: var(--ink-soft); font-variant-numeric: tabular-nums; pointer-events: none; }
.app-ver:empty { display: none; }
.app-ver.in-pop { position: static; margin-top: 8px; text-align: right; }
