@font-face {
  font-family: 'Galmuri11';
  src: url('../assets/fonts/Galmuri11.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Galmuri11';
  src: url('../assets/fonts/Galmuri11-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #060406;
  --ink: #d9cdb4;
  --ink-dim: #8a8a90;
  --me: #f2ead6;
  --owner: #d8452e;
  --owner-dark: #741619;
  --gold: #e0b864;
  --panel: #2a140c;
  --panel-deep: #170c08;
  --btn: #0f0a08;
  --line: #bfb39a;
  --fs: clamp(12px, min(4.1cqw, 2.3cqh), 16px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Galmuri11', 'Dotum', '돋움', sans-serif;
  -webkit-font-smoothing: none;
  font-smooth: never;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body { overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.ghost { visibility: hidden; }
.nowrap { white-space: nowrap; }

/* 모바일 전용: PC에서는 휴대폰 크기 프레임으로 띄운다 */
.stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  container-type: size;
  background: var(--bg);
  font-size: var(--fs);
  line-height: 1.5;
}
@media (min-width: 560px) {
  body {
    background:
      radial-gradient(ellipse at center, #1c1014 0%, #060406 70%);
  }
  .stage {
    inset: auto;
    left: 50%;
    top: 50%;
    width: 400px;
    height: min(860px, calc(100dvh - 40px));
    transform: translate(-50%, -50%);
    box-shadow: 0 0 0 10px #0e090b, 0 0 0 12px #2c1b1c, 0 30px 80px rgba(0, 0, 0, 0.8);
    border-radius: 4px;
  }
}

.app {
  position: absolute;
  inset: 0;
  animation: flicker 6s infinite steps(1);
}
@keyframes flicker {
  0%, 100% { opacity: 1; }
  41% { opacity: 0.94; }
  42% { opacity: 1; }
  77% { opacity: 0.9; }
  77.6% { opacity: 1; }
  78.2% { opacity: 0.95; }
  79% { opacity: 1; }
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

canvas.art, .art-wrap canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.art-full {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* ── CRT 효과 ───────────────────────────── */
.fx { position: absolute; inset: 0; pointer-events: none; z-index: 20; }
/* 옅은 주사선은 도트 그림 위에만 얹는다 (글자·버튼 위에는 없음) */
.zoom::after, .scene::after, .art-full::after {
  content: '';
  position: absolute; inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(to bottom, rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 3px);
}
.result-art { position: relative; }
.fx-vignette {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.8);
}

.glitch {
  position: absolute; inset: 0; z-index: 30; pointer-events: none;
  opacity: 0;
}
.glitch canvas { width: 100%; height: 100%; image-rendering: pixelated; }
.glitch.on { animation: glitch 0.42s steps(1) forwards; }
@keyframes glitch {
  0% { opacity: 0.95; clip-path: inset(0 0 0 0); }
  15% { opacity: 0.2; clip-path: inset(30% 0 40% 0); }
  30% { opacity: 0.9; clip-path: inset(0 0 55% 0); }
  45% { opacity: 0.6; clip-path: inset(60% 0 5% 0); }
  60% { opacity: 1; clip-path: inset(0 0 0 0); }
  80% { opacity: 0.35; clip-path: inset(20% 0 70% 0); }
  100% { opacity: 0; }
}

.rgb { text-shadow: 1px 0 rgba(201, 58, 42, 0.55), -1px 0 rgba(63, 99, 154, 0.55); }
.jitter { animation: jitter 2.4s infinite steps(1); }
@keyframes jitter {
  0%, 100% { transform: translate(0, 0); }
  12% { transform: translate(1px, 0); }
  13% { transform: translate(0, 0); }
  58% { transform: translate(-1px, 1px); }
  59% { transform: translate(0, 0); }
}

/* ── 공통 글자 · 버튼 ───────────────────── */
.owner-say {
  white-space: pre-line;
  color: var(--owner);
  font-weight: 700;
  text-shadow: 0 0 6px rgba(158, 36, 32, 0.6), 1px 0 rgba(63, 99, 154, 0.35);
  letter-spacing: 0.02em;
  min-height: 1.5em;
  margin: 0;
}
.me-say {
  position: relative;
  display: inline-block;
  color: #170f11;
  background: var(--me);
  padding: 0.55em 0.9em;
  margin: 0;
  box-shadow: 0 -3px 0 0 var(--me), 0 3px 0 0 var(--me), -3px 0 0 0 var(--me), 3px 0 0 0 var(--me), 0 0 0 3px transparent;
}
.me-say::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -12px;
  width: 9px; height: 9px;
  background:
    linear-gradient(var(--me), var(--me)) 0 0 / 9px 3px no-repeat,
    linear-gradient(var(--me), var(--me)) 3px 3px / 6px 3px no-repeat,
    linear-gradient(var(--me), var(--me)) 6px 6px / 3px 3px no-repeat;
}
.narr { color: var(--ink); margin: 0; }
.cursor::after { content: '▮'; animation: blink 0.8s steps(1) infinite; margin-left: 2px; color: currentColor; }
@keyframes blink { 50% { opacity: 0; } }

.px-btn {
  --b: var(--line);
  display: block;
  width: calc(100% - 6px);
  margin: 3px;
  padding: 0.75em 1em;
  background: var(--btn);
  border: 0;
  color: var(--ink);
  text-align: center;
  text-decoration: none;
  box-shadow: 0 -3px 0 0 var(--b), 0 3px 0 0 var(--b), -3px 0 0 0 var(--b), 3px 0 0 0 var(--b);
  transition: none;
  touch-action: manipulation;
}
.px-btn:active, .px-btn.picked { background: var(--owner-dark); color: var(--me); --b: var(--owner); }
@media (hover: hover) { .px-btn:hover { background: #2e080b; --b: var(--owner); } }
.px-btn:focus-visible { outline: 2px dashed var(--gold); outline-offset: 5px; }
.px-btn.primary { background: var(--owner-dark); color: var(--me); --b: var(--owner); font-weight: 700; }
.px-btn.gold { background: #3b2418; --b: var(--gold); color: var(--gold); }
.px-btn.dim { --b: #5e5e66; color: var(--ink-dim); }
.px-btn[disabled] { opacity: 0.4; pointer-events: none; }

.hint { color: var(--ink-dim); font-size: 0.8em; margin: 0; }
.tap-next { color: var(--owner); animation: blink 0.9s steps(1) infinite; text-align: right; margin: 0; }

/* ── 시작 화면 ───────────────────────────── */
.scr-start .zoom {
  position: absolute; inset: 0;
  transform-origin: 50% 46%;
  animation: approach 9s cubic-bezier(.4, 0, .4, 1) forwards;
}
@keyframes approach { from { transform: scale(1); } to { transform: scale(1.12); } }
.start-ui {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 0 22px calc(22px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  z-index: 4;
  text-align: center;
}
.start-ui .me-say { margin-bottom: 10px; }
.start-ui .px-btn { max-width: 300px; }
.fade-in { animation: fadein 0.6s steps(4) both; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ── 주의사항 ─────────────────────────── */
.warn {
  position: absolute; inset: 0; z-index: 10;
  background: #060406;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  animation: fadein 0.3s steps(3) both;
}
.warn-body { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 1.1em; color: #f2ead6; text-align: center; }
.warn-body p { margin: 0; white-space: pre-line; word-break: keep-all; text-wrap: balance; line-height: 1.7; font-size: 0.86em; letter-spacing: -0.02em; }
.warn-body .warn-title { font-size: 1.1em; color: #f2ead6; margin-bottom: 0.3em; }
.warn-body .px-btn { margin-top: 1em; }

/* ── 도입 화면: 테스트 화면과 같은 구성 ─── */
.intro-text { display: flex; flex-direction: column; gap: 10px; padding-top: 22px; }
.tap-layer { position: absolute; inset: 0; z-index: 5; background: transparent; border: 0; }

/* ── 테스트 화면 ─────────────────────────── */
.scr-quiz { background: var(--panel); }
.scr-quiz .scene, .scr-name .scene { position: relative; flex: 0 0 34%; min-height: 0; overflow: hidden; }
.quiz-panel, .name-panel {
  background:
    repeating-linear-gradient(90deg, transparent 0 59px, rgba(0, 0, 0, 0.22) 59px 61px),
    linear-gradient(var(--panel), var(--panel-deep));
}
.scr-quiz .scene canvas { position: absolute; left: 0; bottom: 0; width: 100%; }
.quiz-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
}
.quiz-num { color: var(--gold); margin: 0 0 4px; letter-spacing: 0.1em; font-size: 0.85em; }
.quiz-q { margin: 0 0 12px; color: var(--me); min-height: 3em; }
.quiz-opts { display: flex; flex-direction: column; gap: 7px; }
.quiz-opts .px-btn { text-align: left; padding: 0.55em 0.85em; line-height: 1.4; font-size: 0.93em; }
.quiz-opts .px-btn b { color: var(--gold); margin-right: 0.4em; font-weight: 400; }
.quiz-opts.locked { pointer-events: none; }
.quiz-opts .px-btn.faded { opacity: 0.35; }
.quiz-opts .px-btn.vanish { animation: vanish 0.42s steps(1) forwards; pointer-events: none; }
@keyframes vanish {
  0% { opacity: 1; transform: translate(0, 0); }
  18% { opacity: 0.3; transform: translate(4px, 0); clip-path: inset(0 0 50% 0); }
  36% { opacity: 0.9; transform: translate(-3px, 0); clip-path: inset(40% 0 0 0); }
  54% { opacity: 0.2; transform: translate(2px, 0); clip-path: inset(20% 0 30% 0); }
  72% { opacity: 0.6; transform: translate(-1px, 0); clip-path: inset(60% 0 10% 0); }
  100% { opacity: 0; visibility: hidden; }
}
.quiz-back {
  display: block;
  margin: 12px auto 0;
  padding: 6px 10px;
  background: transparent;
  border: 0;
  color: var(--ink-dim);
  font-size: 0.82em;
}
.quiz-back:active { color: var(--owner); }

/* ── 이름 입력 ───────────────────────────── */
.scr-name { background: var(--panel); }
.scr-name .scene canvas { position: absolute; left: 0; bottom: 0; width: 100%; }
.name-panel {
  flex: 1 1 auto;
  padding: 22px 22px calc(26px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px;
}
.name-input {
  --b: var(--owner);
  width: calc(100% - 6px);
  margin: 3px;
  padding: 0.7em 0.9em;
  background: #060406;
  border: 0;
  color: var(--me);
  outline: none;
  box-shadow: 0 -3px 0 0 var(--b), 0 3px 0 0 var(--b), -3px 0 0 0 var(--b), 3px 0 0 0 var(--b);
  font-size: 16px; /* iOS 확대 방지 */
  border-radius: 0;
  -webkit-appearance: none;
}
.name-input::placeholder { color: #5e5e66; }

/* ── 결과 화면 ───────────────────────────── */
.scr-result { overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; display: block; background: #060406; scrollbar-width: none; }
.scr-result::-webkit-scrollbar { display: none; }
.result-head { padding: calc(46px + env(safe-area-inset-top)) 22px 0; text-align: center; min-height: 3.5em; }
.result-say {
  position: absolute;
  top: 10px;
  right: 10px;
  margin: 0;
  text-align: right;
  font-size: 0.92em;
  line-height: 1.65;
  white-space: pre; /* 닉네임, 문장1, 문장2를 한 줄씩 */
  text-shadow: 0 0 4px rgba(6, 4, 6, 1), 0 0 8px rgba(116, 22, 25, 0.8);
  z-index: 2;
}
.result-art { position: relative; margin: calc(48px + env(safe-area-inset-top)) 22px 0; }
.result-head + .result-art { margin-top: 12px; }
.art-stack { position: relative; overflow: hidden; animation: hold 3.2s infinite steps(1); }
.art-stack canvas { display: block; }
.art-stack .layer-front { position: absolute; left: 0; top: 0; }
.book-cover { position: absolute; transform-origin: 50% 50%; display: block; object-fit: fill; }
@keyframes hold { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(1.5px); } }
.result-body { padding: 28px 22px calc(30px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.fear-tag { margin: 0; text-align: center; color: var(--ink-dim); font-size: 0.85em; }
.fear-tag strong { display: block; color: var(--owner); font-size: 1.35em; margin-top: 4px; }
.book-title { margin: 0; text-align: center; color: var(--me); font-size: 1.55em; font-weight: 700; line-height: 1.35; word-break: keep-all; text-shadow: 0 0 10px rgba(201, 58, 42, 0.45); }
.book-author { margin: -8px 0 0; text-align: center; color: var(--gold); font-size: 0.85em; }
.box {
  --b: #3a3a40;
  margin: 3px;
  padding: 14px 16px;
  background: #0e090b;
  box-shadow: 0 -3px 0 0 var(--b), 0 3px 0 0 var(--b), -3px 0 0 0 var(--b), 3px 0 0 0 var(--b);
}
.box p { margin: 0; font-size: 0.92em; line-height: 1.65; }
.box p + p { margin-top: 10px; }
.box .label { color: var(--gold); font-size: 0.8em; margin-bottom: 6px; letter-spacing: 0.06em; }
.extra { display: flex; gap: 14px; align-items: flex-start; color: inherit; text-decoration: none; -webkit-tap-highlight-color: transparent; }
.extra:active { opacity: 0.75; }
.extra .ex-cover { flex: 0 0 auto; width: 84px; height: auto; display: block; box-shadow: 3px 3px 0 #060406; }
.extra .ex-body { flex: 1 1 auto; display: flex; flex-direction: column; gap: 6px; }
.extra .ex-title { color: var(--me); font-weight: 700; margin: 0; font-size: 1.12em; line-height: 1.4; word-break: keep-all; }
.extra .ex-author { color: var(--gold); font-size: 0.82em; margin: 0; }
.extra .ex-fear { color: var(--ink-dim); font-size: 0.82em; margin: 0; }
.extra .px-btn { padding: 0.5em 0.6em; font-size: 0.88em; margin-top: 4px; }
.btn-row { display: flex; gap: 10px; }
.btn-row .px-btn { flex: 1 1 0; }
.promo {
  --b: #170f11;
  display: flex; align-items: center; gap: 12px;
  margin: 3px;
  padding: 10px 10px;
  background: #e0782c;
  color: #170f11;
  text-decoration: none;
  box-shadow: 0 -3px 0 0 var(--b), 0 3px 0 0 var(--b), -3px 0 0 0 var(--b), 3px 0 0 0 var(--b), 0 0 0 6px rgba(224, 120, 44, 0.35);
  animation: promo 2.4s infinite steps(1);
}
.promo:active { background: #f0a040; }
button.promo { width: calc(100% - 6px); border: 0; text-align: left; font: inherit; cursor: pointer; }
.promo.webtoon { background: #00dc64; --b: #00602b; animation-name: promo-w; }
.promo.webtoon:active { background: #3ef08c; }
.promo.webtoon .promo-kicker { color: #00431e; }
.promo.webtoon .promo-title { color: #00210f; }
.promo.webtoon .promo-arrow { color: #00431e; }
.promo.webtoon .promo-title { white-space: normal; line-height: 1.45; }
@keyframes promo-w {
  0%, 100% { box-shadow: 0 -3px 0 0 var(--b), 0 3px 0 0 var(--b), -3px 0 0 0 var(--b), 3px 0 0 0 var(--b), 0 0 0 6px rgba(0, 220, 100, 0.35); }
  50% { box-shadow: 0 -3px 0 0 var(--b), 0 3px 0 0 var(--b), -3px 0 0 0 var(--b), 3px 0 0 0 var(--b), 0 0 0 6px rgba(0, 220, 100, 0.1); }
}
.promo .promo-poster { flex: 0 0 auto; width: 48px; height: auto; display: block; box-shadow: 2px 2px 0 rgba(6, 4, 6, 0.6); }
.promo-body { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 4px; word-break: keep-all; }
.promo-kicker { font-size: 0.75em; color: #3b2418; }
.promo-title { font-size: 1em; font-weight: 700; color: #0e090b; white-space: nowrap; }
.promo-arrow { flex: 0 0 auto; font-size: 1.1em; color: #4d0d12; animation: blink 0.9s steps(1) infinite; }
@keyframes promo {
  0%, 100% { box-shadow: 0 -3px 0 0 var(--b), 0 3px 0 0 var(--b), -3px 0 0 0 var(--b), 3px 0 0 0 var(--b), 0 0 0 6px rgba(224, 120, 44, 0.35); }
  50% { box-shadow: 0 -3px 0 0 var(--b), 0 3px 0 0 var(--b), -3px 0 0 0 var(--b), 3px 0 0 0 var(--b), 0 0 0 6px rgba(224, 120, 44, 0.1); }
}
.divider { height: 3px; margin: 6px 0; background: repeating-linear-gradient(90deg, #3a3a40 0 6px, transparent 6px 12px); }
.shared-cta { text-align: center; color: var(--me); margin: 8px 0 0; }

/* ── Coming Soon ─────────────────────────── */
.soon {
  position: absolute; inset: 0; z-index: 40;
  background: #060406;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.soon canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; opacity: 0.08; }
.soon-body { position: relative; width: 100%; text-align: center; }
.soon-text { position: relative; display: inline-block; }
.soon-dots { position: absolute; left: 100%; top: 0; }
.soon-text, .soon-timer {
  margin: 0;
  font-size: var(--fs);
  color: var(--owner);
  letter-spacing: 0.04em;
}
.soon-timer { margin-top: 8px; font-variant-numeric: tabular-nums; }
.soon-close {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 12px;
  width: 44px; height: 44px;
  background: transparent; border: 0;
  color: var(--ink-dim); font-size: 28px; line-height: 1;
}

/* ── 기타 ───────────────────────────────── */
.sound {
  position: absolute; z-index: 25;
  top: calc(10px + env(safe-area-inset-top)); right: 10px;
  padding: 6px 8px;
  background: rgba(6, 4, 6, 0.6);
  border: 0;
  color: var(--ink-dim);
  font-size: 11px;
  letter-spacing: 0.08em;
}
.sound[aria-pressed='true'] { color: var(--gold); }

.toast {
  position: absolute; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom)); z-index: 45;
  transform: translateX(-50%);
  padding: 10px 14px;
  background: #0e090b;
  color: var(--me);
  box-shadow: 0 -3px 0 0 var(--owner), 0 3px 0 0 var(--owner), -3px 0 0 0 var(--owner), 3px 0 0 0 var(--owner);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  font-size: 0.9em;
}
.toast.on { animation: fadein 0.2s steps(2) both; opacity: 1; }

.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .app, .jitter, .art-stack { animation: none !important; }
  .scr-start .zoom { animation-duration: 0.01s; }
}
