:root {
  --paper: #f2f1ea;
  --ink: #111310;
  --white: #fff;
  --lime: #d8ff3e;
  --violet: #5d5cff;
  --yellow: #ffd84a;
  --red: #ff503f;
  --line: #c9c8c0;
  font-family: Inter, Pretendard, "Noto Sans KR", Arial, sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-width: 320px; min-height: 100%; overflow-x: clip; background: var(--paper); }
a { color: inherit; }
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.history-shell { min-height: 100vh; overflow-x: clip; }
.history-wordmark { display: inline-flex; gap: .55rem; align-items: center; color: var(--ink); font-size: .78rem; font-weight: 950; text-decoration: none; }
.history-wordmark i { width: .72rem; height: .72rem; border: 1px solid var(--ink); border-radius: 50%; background: var(--lime); }

.history-intro { display: grid; grid-template-columns: minmax(18rem,.78fr) minmax(36rem,1.22fr); grid-template-rows: auto 1fr; gap: 3rem clamp(3rem,8vw,8rem); width: min(1440px,100%); min-height: 100vh; margin: auto; padding: 1.5rem clamp(1.25rem,4vw,4rem) 3rem; animation: history-intro-enter 560ms 150ms cubic-bezier(.2,.8,.2,1) both; }
.history-topbar { grid-column: 1/-1; display: flex; align-items: center; justify-content: space-between; min-height: 3.2rem; border-bottom: 1px solid var(--ink); }
.history-topbar > span { color: #6c6d67; font-size: .7rem; font-weight: 950; }
.history-intro-copy { align-self: center; position: relative; padding: 2rem 0; }
.history-intro-copy::before { position: absolute; top: -5rem; left: -12rem; width: 28rem; height: 28rem; border: 1px solid rgba(17,19,16,.15); border-radius: 50%; content: ""; }
.history-intro-copy p { position: relative; display: inline-block; margin: 0; padding: .5rem .72rem; border: 1px solid var(--ink); border-radius: 999px; background: var(--lime); font-size: .62rem; font-weight: 950; }
.history-intro-copy h1 { position: relative; display: grid; row-gap: .12em; justify-items: start; margin: 1.15rem 0 1.5rem; font-size: clamp(3.4rem,4.8vw,4.8rem); letter-spacing: -.075em; line-height: .98; }
.history-intro-copy h1 span,.history-intro-copy h1 em { display: block; white-space: nowrap; }
.history-intro-copy h1 em { color: transparent; font-style: normal; -webkit-text-stroke: 1.5px var(--ink); }
.history-intro-copy > span { position: relative; color: #70716b; font-size: 1rem; font-weight: 700; line-height: 1.75; }

.history-intro-card { align-self: center; position: relative; display: grid; gap: 1rem; padding: clamp(1.3rem,3vw,2.2rem); border: 1px solid var(--ink); background: var(--white); box-shadow: 10px 10px 0 var(--ink); }
.history-mode-back { justify-self: start; padding: .65rem .8rem; border: 1px solid var(--ink); background: var(--lime); box-shadow: 3px 3px 0 var(--ink); font-size: .72rem; font-weight: 950; text-decoration: none; }
.period-heading { display: flex; justify-content: space-between; padding-bottom: .7rem; border-bottom: 1px solid var(--ink); color: #656761; font-size: .62rem; font-weight: 950; }
.period-card { position: relative; overflow: hidden; min-height: 13rem; padding: 1.2rem; border: 1px solid var(--ink); background: var(--violet); color: var(--white); }
.period-card::after { position: absolute; right: -3rem; bottom: -6rem; width: 16rem; height: 16rem; border: 1px solid rgba(255,255,255,.45); border-radius: 50%; content: ""; }
.period-card small { color: var(--lime); font-size: .64rem; font-weight: 950; }
.period-card h2 { margin: 2.6rem 0 .4rem; font-size: clamp(2.3rem,4vw,4rem); letter-spacing: -.07em; line-height: .9; }
.period-card p { margin: 0; color: #e0e0ff; font-size: .75rem; font-weight: 700; }
.period-card > strong { position: absolute; right: .8rem; top: .5rem; color: transparent; font-size: clamp(4.5rem,8vw,7.5rem); letter-spacing: -.08em; line-height: 1; -webkit-text-stroke: 1px rgba(255,255,255,.45); }
.period-future { display: grid; grid-template-columns: repeat(3,1fr); gap: .45rem; }
.period-future span { min-height: 3.2rem; padding: .7rem; border: 1px dashed #9b9c95; color: #a4a59e; font-size: .72rem; font-weight: 950; }
.history-length-picker { display: grid; grid-template-columns: repeat(2,1fr); gap: .5rem; padding: 0; border: 0; }
.history-length-picker.is-three-up { grid-template-columns: repeat(3,1fr); }
.history-length-picker legend { grid-column: 1/-1; margin-bottom: .35rem; font-size: .6rem; font-weight: 950; }
.history-length-picker label { position: relative; cursor: pointer; }
.history-length-picker input { position: absolute; opacity: 0; }
.history-length-picker label > span { display: grid; gap: .25rem; min-height: 4rem; padding: .75rem; border: 1px solid var(--line); }
.history-length-picker label > span b { font-size: .82rem; }
.history-length-picker label > span small { color: #777971; font-size: .62rem; }
.history-length-picker input:checked + span { border-color: var(--ink); background: var(--lime); box-shadow: 3px 3px 0 var(--ink); }
#history-start { display: flex; min-height: 4.2rem; padding: 0 1rem; border: 1px solid var(--ink); align-items: center; justify-content: space-between; background: var(--ink); color: var(--white); cursor: pointer; font-weight: 950; }
#history-start:disabled { cursor: wait; opacity: .45; }
#history-start:not(:disabled):hover { background: var(--lime); color: var(--ink); }
#history-load-status { margin: 0; color: #6e7069; font-size: .62rem; font-weight: 750; }

.history-game { min-height: 100vh; padding: 0 clamp(.75rem,2vw,1.6rem) 1rem; background: #e9e9e2; }
.history-game-topbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 4.7rem; border-bottom: 1px solid var(--ink); }
.history-metrics { display: flex; align-items: stretch; border: 1px solid var(--ink); background: var(--white); }
.history-metrics > div { display: grid; min-width: 5.1rem; padding: .45rem .65rem; text-align: center; }
.history-metrics > div + div { border-left: 1px solid var(--ink); }
.history-metrics span { color: #6d6e68; font-size: .52rem; font-weight: 900; }
.history-metrics strong { margin-top: .15rem; font-size: .94rem; }
.history-exit { justify-self: end; display: inline-flex; gap: .45rem; min-height: 2.7rem; padding: 0 .85rem; border: 1px solid var(--ink); align-items: center; background: var(--lime); box-shadow: 3px 3px 0 var(--ink); cursor: pointer; font-size: .72rem; font-weight: 950; }
.history-actions { justify-self: end; display: flex; gap: .55rem; align-items: center; }
.history-sound { display: inline-flex; gap: .4rem; min-height: 2.7rem; padding: 0 .75rem; border: 1px solid var(--ink); align-items: center; background: var(--white); color: var(--ink); cursor: pointer; font-size: .68rem; font-weight: 950; }
.history-sound:hover,.history-sound:focus-visible { outline: 0; background: var(--yellow); }
.history-sound[aria-pressed="false"] { color: #696b65; background: #d9dad3; }
.history-progress { height: .35rem; border: 1px solid var(--ink); border-top: 0; background: var(--white); }
.history-progress span { display: block; width: 0; height: 100%; background: var(--violet); transition: width .3s ease; }

.history-arena { position: relative; overflow: hidden; height: calc(100vh - 6.4rem); min-height: 39rem; border: 1px solid var(--ink); border-top: 0; background: #111713; }
.history-arena::before { position: absolute; inset: 0; background: linear-gradient(90deg,rgba(93,92,255,.08) 1px,transparent 1px),linear-gradient(rgba(93,92,255,.08) 1px,transparent 1px); background-size: 44px 44px; content: ""; pointer-events: none; }
.history-globe-stage { position: absolute; z-index: 1; inset: 0; }
.history-globe-stage canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.history-globe-stage canvas:active { cursor: grabbing; }
.history-era-stamp { position: absolute; z-index: 4; top: 1rem; left: 1rem; display: grid; width: 11rem; padding: .8rem; border: 1px solid var(--white); background: var(--violet); color: var(--white); box-shadow: 5px 5px 0 var(--lime); }
.history-era-stamp span { color: var(--lime); font-size: .55rem; font-weight: 950; }
.history-era-stamp strong { font-size: 2.8rem; letter-spacing: -.07em; }
.history-era-stamp small { color: #dedfff; font-size: .6rem; }
.history-question { position: absolute; z-index: 4; top: 7.8rem; left: 1rem; width: 15rem; color: var(--white); }
.history-question span { color: var(--lime); font-size: .58rem; font-weight: 950; }
.history-question h1 { margin: .5rem 0 0; font-size: clamp(2rem,3.5vw,3.7rem); letter-spacing: -.065em; line-height: .93; }
.history-globe-hint { position: absolute; z-index: 3; bottom: .7rem; left: 50%; color: #a8b4ad; transform: translateX(-50%); font-size: .55rem; font-weight: 850; }

.history-choices { position: absolute; z-index: 5; inset: 0; pointer-events: none; }
.history-choice { position: absolute; display: grid; grid-template-columns: 3rem minmax(0,1fr); gap: .7rem; width: min(18rem,25%); min-height: 4.5rem; padding: .65rem; border: 1px solid var(--ink); align-items: center; background: rgba(255,255,255,.97); box-shadow: 5px 5px 0 var(--violet); cursor: pointer; pointer-events: auto; text-align: left; transition: transform .12s ease,background .12s ease,box-shadow .12s ease; }
.history-choice.up { top: 1rem; left: 50%; transform: translateX(-50%); }
.history-choice.down { bottom: 1rem; left: 50%; transform: translateX(-50%); }
.history-choice.left { top: 58%; left: 1rem; transform: translateY(-50%); }
.history-choice.right { top: 58%; right: 1rem; transform: translateY(-50%); }
.history-choice > b { display: grid; width: 3rem; height: 3rem; border: 1px solid var(--ink); place-items: center; background: var(--yellow); font-family: "Segoe UI Symbol",sans-serif; font-size: 1.3rem; }
.history-choice span { display: grid; gap: .22rem; }
.history-choice strong { font-size: clamp(.9rem,1.35vw,1.25rem); letter-spacing: -.03em; line-height: 1.05; }
.history-choice small { color: #74766f; font-size: .56rem; font-weight: 800; }
.history-choice:hover,.history-choice:focus-visible { outline: 0; background: var(--lime); box-shadow: 2px 2px 0 var(--white); }
.history-choice.is-correct { background: var(--lime); box-shadow: 0 0 0 6px rgba(216,255,62,.22); }
.history-choice.is-wrong { background: var(--red); color: var(--white); }
.history-choice.is-wrong small { color: #ffe3de; }

.history-feedback { position: absolute; z-index: 8; bottom: 1.2rem; left: 50%; display: none; width: min(36rem,calc(100% - 2rem)); padding: 1rem 1.1rem; border: 1px solid var(--ink); background: var(--white); box-shadow: 7px 7px 0 var(--lime); transform: translateX(-50%); }
.history-feedback.is-visible { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; animation: history-feedback-in .25s ease both; }
.history-feedback > b { grid-row: 1/3; display: grid; min-width: 4.1rem; place-items: center; background: var(--violet); color: var(--white); font-size: .67rem; }
.history-feedback strong { font-size: 1.35rem; }
.history-feedback span { color: #62645d; font-size: .72rem; font-weight: 700; line-height: 1.45; }
.history-feedback.is-challenge { width: min(25rem,calc(100% - 2rem)); grid-template-columns: 4.1rem 1fr; align-items: center; padding: .7rem; }
.history-feedback.is-challenge > b { grid-row: auto; min-height: 3.2rem; }
.history-feedback.is-challenge strong { font-size: 1.15rem; }
.history-countdown { position:absolute; z-index:9; inset:0; display:grid; place-items:center; overflow:hidden; background:rgba(10,15,12,.88); backdrop-filter:blur(3px); }
.history-countdown[hidden] { display:none; }
.history-countdown::before,.history-countdown::after { position:absolute; width:min(64vw,44rem); aspect-ratio:1; border:1px solid rgba(216,255,62,.28); border-radius:50%; content:""; animation:history-countdown-orbit 2.8s linear infinite; }
.history-countdown::after { width:min(44vw,29rem); border-color:rgba(93,92,255,.7); animation-direction:reverse; }
.history-countdown span { position:relative; z-index:1; color:var(--lime); font-size:clamp(8rem,24vw,18rem); font-weight:950; letter-spacing:-.1em; line-height:.8; text-shadow:8px 8px 0 var(--violet); }
.history-countdown span.is-popping { animation:history-countdown-pop .7s cubic-bezier(.2,.9,.2,1) both; }
.history-countdown span.is-start { font-size:clamp(4rem,13vw,9rem); letter-spacing:-.07em; }

.history-finish { position: absolute; z-index: 10; top: 50%; left: 50%; width: min(34rem,calc(100% - 2rem)); padding: 2rem; border: 1px solid var(--ink); background: var(--white); box-shadow: 10px 10px 0 var(--lime); transform: translate(-50%,-50%); text-align: center; }
.history-finish > span { color: var(--violet); font-size: .62rem; font-weight: 950; }
.history-finish h2 { margin: .8rem 0; font-size: clamp(2.5rem,5vw,4.5rem); letter-spacing: -.07em; line-height: .92; }
.history-finish > strong { display: block; font-size: 3rem; }
.history-finish p { color: #666861; font-size: .82rem; }
.history-finish-stats { display: grid; grid-template-columns: repeat(3,1fr); margin-top: 1rem; border: 1px solid var(--ink); }
.history-finish-stats > span { display: grid; gap: .25rem; min-width: 0; padding: .65rem .4rem; }
.history-finish-stats > span + span { border-left: 1px solid var(--ink); }
.history-finish-stats small { color: #666861; font-size: .5rem; font-weight: 950; }
.history-finish-stats b { overflow-wrap: anywhere; font-size: .9rem; }
.history-percentile-detail { display: block; color: #666861; font-size: .58rem; font-weight: 750; }
.history-finish-actions { display: grid; grid-template-columns: repeat(3,1fr); gap: .55rem; margin-top: 1.2rem; }
.history-finish button,.history-finish a { display: grid; min-height: 3.4rem; border: 1px solid var(--ink); place-items: center; background: var(--lime); color: var(--ink); cursor: pointer; font-weight: 950; text-decoration: none; }
.history-finish a { background: var(--ink); color: var(--white); }
#history-share { background: var(--yellow); }
.history-note { padding: .65rem .2rem 0; color: #666861; font-size: .58rem; font-weight: 700; }
.history-transition { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; overflow: hidden; pointer-events: none; background: var(--ink); color: var(--white); animation: history-entry-reveal 680ms cubic-bezier(.72,0,.28,1) both; }
.history-transition::after { position: absolute; top: 0; bottom: 0; left: 0; width: .8rem; background: var(--lime); content: ""; }
.history-transition span { font-size: clamp(.85rem,2vw,1.2rem); font-weight: 950; }
.history-transition.is-exiting { background: var(--violet); clip-path: inset(0 100% 0 0); transform: none; animation: history-transition-out .62s ease-in-out forwards; }
.history-transition.is-exiting::after { display: none; }
.history-transition.is-exiting span { font-size: clamp(2.6rem,9vw,8rem); letter-spacing: -.07em; }
body.is-history-exiting .history-intro { animation: history-page-out .28s ease-in both; }

@keyframes history-feedback-in { from { opacity: 0; transform: translate(-50%,.7rem); } }
@keyframes history-entry-reveal { 0%,31% { transform: translateX(0); } 100% { transform: translateX(105%); } }
@keyframes history-transition-out { 0% { clip-path: inset(0 100% 0 0); } 48%,62% { clip-path: inset(0); } 100% { clip-path: inset(0 0 0 100%); } }
@keyframes history-intro-enter { from { opacity: .35; transform: translateY(.75rem) scale(.995); } }
@keyframes history-page-out { to { opacity: 0; transform: scale(.985); } }
@keyframes history-countdown-pop { 0% { opacity:0; transform:scale(.55) rotate(-4deg); } 22%,72% { opacity:1; transform:scale(1); } 100% { opacity:.15; transform:scale(1.16); } }
@keyframes history-countdown-orbit { to { transform:rotate(360deg); } }

@media (max-width: 880px) {
  .history-intro { display: block; min-height: auto; padding: 0 1rem 2rem; }
  .history-topbar { margin-bottom: 2rem; }
  .history-intro-copy { padding: 1rem 0 2.5rem; }
  .history-intro-copy::before { left: auto; right: -13rem; }
  .history-intro-copy h1 { font-size: clamp(3.1rem,13.5vw,4rem); line-height: 1; }
  .history-intro-card { padding: 1rem; box-shadow: 6px 6px 0 var(--ink); }
  .history-length-picker.is-three-up { grid-template-columns: 1fr; }
  .period-card { min-height: 11rem; }
  .period-card > strong { font-size: 4.8rem; }
  .history-game { padding: 0 .5rem .5rem; }
  .history-game-topbar { grid-template-columns: 1fr auto; min-height: 4rem; }
  .history-metrics { grid-column: 1/-1; grid-row: 2; width: 100%; }
  .history-metrics > div { flex: 1; min-width: 0; }
  .history-actions { gap: .35rem; }
  .history-sound,.history-exit { padding: 0 .55rem; }
  .history-sound b { display: none; }
  .history-exit b { display: inline; font-size: .58rem; }
  .history-arena { height: calc(100dvh - 8.8rem); min-height: 36rem; }
  .history-globe-stage { inset: 0; }
  .history-era-stamp { top: .65rem; left: .65rem; width: 7.2rem; padding: .55rem; box-shadow: 3px 3px 0 var(--lime); }
  .history-era-stamp strong { font-size: 2rem; }
  .history-question { top: .9rem; left: 8.7rem; width: calc(100% - 9.4rem); }
  .history-question h1 { font-size: 1.45rem; }
  .history-choices { top: auto; right: .45rem; bottom: .45rem; left: .45rem; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: .45rem; }
  .history-choice,.history-choice.up,.history-choice.down,.history-choice.left,.history-choice.right { position: relative; top: auto; right: auto; bottom: auto; left: auto; width: auto; min-height: 4rem; padding: .42rem; transform: none; box-shadow: 3px 3px 0 var(--violet); }
  .history-choice { grid-template-columns: 2.4rem minmax(0,1fr); gap: .45rem; }
  .history-choice > b { width: 2.4rem; height: 2.4rem; font-size: 1rem; }
  .history-choice strong { font-size: .75rem; overflow-wrap: anywhere; }
  .history-choice small { display: none; }
  .history-globe-hint { top: 60%; bottom: auto; width: 100%; text-align: center; }
  .history-feedback { bottom: 9.2rem; padding: .75rem; }
  .history-feedback.is-visible { grid-template-columns: 3.6rem 1fr; }
  .history-feedback strong { font-size: 1rem; }
  .history-feedback span { font-size: .62rem; }
  .history-feedback.is-challenge { bottom: 9.2rem; grid-template-columns: 3.6rem 1fr; }
  .history-note { font-size: .52rem; }
}

@media (max-width: 390px) {
  .history-intro-copy h1 { font-size: 3.1rem; }
  .history-length-picker { grid-template-columns: 1fr; }
  .period-future { display: none; }
  .history-choice strong { font-size: .7rem; }
}

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