:root {
  --paper: #fbf4e4;
  --paper-2: #f3e8cf;
  --card: #fffdf7;
  --ink: #23304a;
  --ink-soft: #5b6478;
  --line: #e3d5b4;
  --accent: #e2722f;
  --accent-ink: #fff;
  --blue: #2f6fb1;
  --good: #2e8b57;
  --good-bg: #e6f4ea;
  --bad: #c0392b;
  --bad-bg: #fbe9e6;
  --warn-bg: #fff3d6;
  --radius: 16px;
  --shadow: 0 2px 0 var(--line), 0 6px 18px rgba(60, 40, 0, 0.08);
  --head: 'Jua', 'Apple SD Gothic Neo', sans-serif;
  --body: 'Gowun Dodum', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background:
    repeating-linear-gradient(to bottom, transparent 0 31px, rgba(47, 111, 177, 0.07) 31px 32px),
    var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.6;
  min-height: 100vh;
}
body.sheet-open { overflow: hidden; }
button, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
h1, h2, b, .btn, .topbar-title { font-family: var(--head); font-weight: 400; }
small { font-size: 0.8em; color: var(--ink-soft); }

#app { max-width: 720px; margin: 0 auto; padding: 0 16px calc(32px + env(safe-area-inset-bottom)); }

/* 위 막대 */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 0; background: var(--paper);
}
.topbar-title { flex: 1; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.icon-btn, .note-btn {
  border: 2px solid var(--ink); background: var(--card); border-radius: 12px;
  min-width: 44px; height: 44px; padding: 0 10px; font-size: 18px;
}
.note-btn b { font-size: 18px; color: var(--accent); }

.steps { list-style: none; display: flex; gap: 4px; margin: 0 0 16px; padding: 0; }
.steps li { flex: 1; text-align: center; font-size: 12px; color: var(--ink-soft); }
.steps li::before { content: ''; display: block; height: 6px; border-radius: 3px; background: var(--line); margin-bottom: 3px; }
.steps li.done::before { background: var(--blue); }
.steps li.now::before { background: var(--accent); }
.steps li.now { color: var(--ink); font-weight: 700; }

.stage { animation: rise 0.25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 52px; padding: 0 22px; border-radius: 14px;
  border: 2px solid var(--ink); background: var(--card); font-size: 19px;
  box-shadow: 0 3px 0 var(--ink); transition: transform 0.05s;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.small { min-height: 40px; font-size: 16px; padding: 0 14px; margin: 4px 6px 4px 0; }
.btn:disabled { opacity: 0.4; box-shadow: none; transform: none; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 20px 0 8px; }
.actions .hint { width: 100%; text-align: center; margin: 0; }
.actions.sticky {
  position: sticky; bottom: 0; margin: 20px -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper) 70%, transparent);
}
.hint { color: var(--ink-soft); font-size: 15px; }
.section-title { font-size: 20px; margin: 24px 0 10px; }
.section-title small { font-family: var(--body); margin-left: 6px; }

/* 처음 화면 */
.home-hero { text-align: center; padding: 40px 0 8px; }
.badge-big { font-size: 72px; line-height: 1; filter: drop-shadow(0 4px 0 var(--line)); }
.home-hero h1 { font-size: 40px; margin: 8px 0 4px; letter-spacing: 1px; }
.home-hero p { margin: 0 auto; max-width: 30em; color: var(--ink-soft); }
.cases { display: grid; gap: 12px; }
.case-card {
  display: flex; align-items: center; gap: 14px; text-align: left; width: 100%;
  padding: 16px; border: 2px solid var(--ink); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow);
}
.case-cover { font-size: 44px; width: 64px; height: 64px; display: grid; place-items: center; background: var(--paper-2); border-radius: 12px; flex: none; }
.case-body { display: flex; flex-direction: column; }
.case-body b { font-size: 21px; }
.case-topic { font-size: 13px; color: var(--accent); font-weight: 700; }
.case-meta { font-size: 14px; color: var(--ink-soft); }

/* 대화 */
.case-file {
  background: var(--ink); color: var(--paper); border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px;
  display: flex; flex-direction: column;
}
.case-file span { font-size: 13px; opacity: 0.7; }
.case-file b { font-size: 24px; }
.case-file small { color: var(--paper-2); }
.dialogue > * { animation: rise 0.3s ease-out; }
.narration { font-size: 18px; margin: 12px 4px; }
.bubble {
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px 12px; margin: 12px 0;
}
.bubble.owl { border-color: var(--blue); background: #eef4fb; }
.bubble .who { font-size: 14px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }
.bubble .face { font-size: 24px; }
.bubble p { margin: 4px 0 0; font-size: 18px; }

/* 현장 조사 */
.places { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; margin-top: 12px; }
.place {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 18px 8px 14px; border: 2px dashed var(--ink); border-radius: var(--radius); background: var(--card);
}
.place.person { border-style: solid; border-color: var(--blue); }
.place.seen { background: var(--paper-2); }
.place-emoji { font-size: 44px; line-height: 1.1; }
.place-name { font-family: var(--head); font-size: 18px; }
.place .check {
  position: absolute; top: 6px; right: 8px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--good); color: #fff; font-size: 15px; display: grid; place-items: center;
}

/* 단서 카드 */
.clue-list { display: grid; gap: 10px; }
.clue {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 2px solid var(--line); border-left: 6px solid var(--accent);
  border-radius: 12px; padding: 10px 14px;
}
.clue.new { animation: pop 0.4s ease-out; }
@keyframes pop { 0% { transform: scale(0.9); opacity: 0; } 70% { transform: scale(1.02); } }
.clue-head { display: flex; align-items: center; gap: 8px; }
.clue-emoji { font-size: 22px; }
.clue-head b { font-size: 18px; }
.clue p { margin: 4px 0 0; }
.clue .concept { background: #eef4fb; border-radius: 8px; padding: 6px 10px; font-size: 15px; margin-top: 8px; }
.tag { margin-left: auto; background: var(--accent); color: #fff; font-size: 12px; border-radius: 99px; padding: 2px 8px; }
.clue-list.pick .clue { border-left-color: var(--line); }
.clue.selected { border-color: var(--blue); border-left-color: var(--blue); background: #eef4fb; box-shadow: 0 0 0 2px var(--blue); }
.clue.selected .clue-head::after { content: '근거 ✔'; margin-left: auto; font-size: 13px; color: var(--blue); font-weight: 700; }

/* 선택지 */
.options { display: grid; gap: 10px; }
.option {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px; text-align: left; width: 100%;
  min-height: 56px; padding: 10px 14px; border: 2px solid var(--ink); border-radius: 14px; background: var(--card);
}
.option.selected { background: var(--ink); color: var(--paper); }
.option.right { border-color: var(--good); background: var(--good-bg); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.option:disabled { cursor: default; }
.option .why { width: 100%; color: var(--bad); }
.opt-emoji { font-size: 26px; flex: none; }
.option > span:not(.opt-emoji) { flex: 1; min-width: 0; }

/* 피드백 */
.fb-list { list-style: none; padding: 0; margin: 12px 0; display: grid; gap: 8px; }
.fb { display: flex; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--card); border: 2px solid var(--line); }
.fb > span { font-size: 22px; }
.fb p { margin: 2px 0 0; font-size: 15px; }
.fb.support { background: var(--good-bg); border-color: #b9dfc6; }
.fb.conflict { background: var(--bad-bg); border-color: #efc2bb; }
.fb.decoy { background: var(--warn-bg); border-color: #f0d68d; }

/* 실험실 */
.lab-q { background: var(--card); border: 2px solid var(--ink); border-radius: 14px; padding: 12px 14px; font-size: 18px; }
.vars { display: grid; gap: 10px; }
.var-row {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  background: var(--card); border: 2px solid var(--line); border-radius: 14px; padding: 10px 12px;
}
.var-row.changing { border-color: var(--accent); background: #fff1e6; }
.var-name { font-family: var(--head); font-size: 18px; }
.var-val { grid-column: 1 / -1; }
.var-val select { width: 100%; min-height: 44px; border: 2px solid var(--line); border-radius: 10px; background: #fff; padding: 0 10px; }
.vals { font-size: 15px; color: var(--accent); font-weight: 700; }
.seg { display: inline-flex; border: 2px solid var(--ink); border-radius: 12px; overflow: hidden; }
.seg button { border: 0; background: var(--card); min-height: 40px; padding: 0 14px; font-family: var(--head); font-size: 16px; }
.seg button.on { background: var(--ink); color: var(--paper); }
.seg button[data-mode="change"].on { background: var(--accent); }

.lab-table { margin-top: 20px; background: var(--card); border: 2px solid var(--ink); border-radius: var(--radius); padding: 12px; }
.lab-cap { font-size: 15px; margin-bottom: 8px; }
.trial { display: grid; grid-template-columns: 150px 1fr; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px dashed var(--line); }
.bench {
  position: relative; height: 48px; background: var(--paper-2); border-radius: 10px; overflow: hidden;
}
.bench .magnet { position: absolute; left: 6px; top: 50%; transform: translateY(-50%); font-size: 28px; }
.bench .obj { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 26px; }
.trial.stick .obj { animation: pull 0.6s cubic-bezier(.5, 0, .9, .4) forwards; animation-delay: var(--d); }
.trial.stay .obj { animation: wobble 0.5s ease-in-out; animation-delay: var(--d); }
@keyframes pull { to { right: calc(100% - 72px); } }
@keyframes wobble { 30% { transform: translate(-6px, -50%); } 60% { transform: translate(2px, -50%); } }
.trial-label { display: flex; flex-direction: column; }
.trial-label b { font-size: 17px; }
.trial.stick .trial-label span { color: var(--good); font-weight: 700; }
.trial.stay .trial-label span { color: var(--ink-soft); }
.lab-fb.warn .bubble { border-color: #e0b84a; background: var(--warn-bg); }
.lab-fb.good .bubble { border-color: var(--good); background: var(--good-bg); }

/* 추리 */
textarea {
  width: 100%; border: 2px solid var(--ink); border-radius: 14px; padding: 12px; background: #fff;
  font-size: 18px; line-height: 1.6; resize: vertical;
}
blockquote { margin: 0; padding: 12px 16px; border-radius: 14px; font-size: 17px; }
blockquote.mine { background: var(--card); border: 2px solid var(--ink); }
blockquote.model { background: #eef4fb; border: 2px solid var(--blue); }
.ideas { list-style: none; padding: 0; display: grid; gap: 6px; }
.ideas li { padding: 8px 12px; border-radius: 10px; background: var(--card); border: 2px solid var(--line); }
.ideas li.hit { background: var(--good-bg); border-color: #b9dfc6; }

/* 결말 */
.ending-title { text-align: center; font-family: var(--head); font-size: 18px; color: var(--ink-soft); }
.ending-title b { display: block; font-size: 30px; color: var(--ink); }
.ending-title.solved b { color: var(--accent); }
.result {
  text-align: center; margin: 24px 0; padding: 20px 16px; border: 3px double var(--ink); border-radius: 20px; background: var(--card);
  animation: pop 0.5s ease-out;
}
.medal { font-size: 64px; line-height: 1; }
.grade-name { font-family: var(--head); font-size: 30px; }
.score { font-family: var(--head); font-size: 44px; color: var(--accent); line-height: 1.1; }
.parts { list-style: none; padding: 0; margin: 12px auto 0; max-width: 320px; text-align: left; }
.parts li { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.further { background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); padding: 4px 16px 16px; }

/* 아래에서 올라오는 시트 */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20, 25, 40, 0.45); z-index: 40; animation: fade 0.2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88vh; overflow-y: auto;
  max-width: 720px; margin: 0 auto; padding: 20px 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--paper); border-radius: 22px 22px 0 0; animation: up 0.25s ease-out;
}
.sheet h2 { margin: 0 40px 8px 0; font-size: 24px; }
.sheet-lead { font-size: 18px; }
.sheet-close { position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--ink); background: var(--card); font-size: 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

@media (min-width: 600px) {
  .var-row { grid-template-columns: 140px auto 1fr; }
  .var-val { grid-column: auto; }
  .trial { grid-template-columns: 220px 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0s !important; }
}

/* 실험 그림: 녹는 얼음 (lab.display = "melt") */
.bench.melt .cond { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: 26px; }
.bench.melt .ice { position: absolute; left: 58%; top: 50%; transform: translate(-50%, -50%); font-size: 30px; transition: none; }
.bench.melt .drop { position: absolute; left: 58%; bottom: 2px; transform: translateX(-50%) scale(0); font-size: 22px; opacity: 0; }
.trial.little .ice { animation: melt-little 1.2s ease-out forwards var(--d); }
.trial.half .ice { animation: melt-half 1.2s ease-out forwards var(--d); }
.trial.melted .ice { animation: melt-all 1.2s ease-in forwards var(--d); }
.trial.little .drop { animation: drop-s 1.2s ease-out forwards var(--d); }
.trial.half .drop { animation: drop-m 1.2s ease-out forwards var(--d); }
.trial.melted .drop { animation: drop-l 1.2s ease-out forwards var(--d); }
.trial.frozen .ice { animation: shiver 0.6s ease-in-out var(--d); }
@keyframes melt-little { to { transform: translate(-50%, -38%) scale(0.8); } }
@keyframes melt-half { to { transform: translate(-50%, -25%) scale(0.5); } }
@keyframes melt-all { to { transform: translate(-50%, 0) scale(0.1); opacity: 0; } }
@keyframes drop-s { to { transform: translateX(80%) scale(0.6); opacity: 1; } }
@keyframes drop-m { to { transform: translateX(60%) scale(0.9); opacity: 1; } }
@keyframes drop-l { to { transform: translateX(-50%) scale(1.3); opacity: 1; } }
@keyframes shiver { 25% { transform: translate(-54%, -50%); } 75% { transform: translate(-46%, -50%); } }
.trial.frozen .trial-label span { color: var(--blue); font-weight: 700; }
.trial.little .trial-label span { color: var(--ink-soft); }
.trial.half .trial-label span { color: var(--accent); font-weight: 700; }
.trial.melted .trial-label span { color: var(--bad); font-weight: 700; }
