/* 아이가 보는 화면이다. 글씨는 크게, 모서리는 둥글게, 색은 따뜻하게. */
:root {
  --bg: #fff7ec;
  --bg2: #ffe9cf;
  --ink: #3b2a1d;
  --ink-soft: #8a6f57;
  --card: #ffffff;
  --line: #f0dcc4;
  --me: #ff9f45;
  --me-ink: #4a2600;
  --ai: #ffffff;
  --good: #33a06f;
  --bad: #e0525b;
  --shadow: 0 6px 0 rgba(0,0,0,.06), 0 12px 24px rgba(140,90,40,.10);
  --radius: 20px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%) fixed;
  color: var(--ink);
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
#app { max-width: 560px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }
.screen { padding: 18px 16px 28px; flex: 1; display: flex; flex-direction: column; }
.hidden { display: none !important; }
button { font: inherit; font-weight: 700; cursor: pointer; border: 0; }

/* 시작 화면 */
.hero { text-align: center; padding: 18px 0 6px; }
.hero h1 { font-size: 2.4rem; margin: 0; letter-spacing: -1px; }
.hero-emoji { display: inline-block; margin-right: 8px; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-7px) rotate(4deg); } }
.hero-sub { color: var(--ink-soft); margin: 6px 0 0; }
.section-title { font-size: 1.05rem; margin: 20px 4px 10px; color: var(--ink-soft); }

.levels { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.level-card {
  background: var(--card); border-radius: var(--radius); padding: 12px 12px 10px;
  box-shadow: var(--shadow); border: 3px solid transparent; text-align: left; width: 100%;
  display: flex; gap: 10px; align-items: center; transition: transform .12s ease, border-color .12s ease;
}
.level-card:active { transform: scale(.97); }
.level-card[aria-pressed="true"] { border-color: var(--me); }
.level-card .lv-emoji { font-size: 1.9rem; }
.level-card .lv-no { font-size: .72rem; color: var(--ink-soft); font-weight: 700; }
.level-card .lv-name { font-size: 1.02rem; }
.level-card .lv-blurb { font-size: .72rem; color: var(--ink-soft); font-weight: 500; }
.level-card .lv-best { font-size: .68rem; color: var(--good); font-weight: 700; }

.options { display: grid; gap: 8px; margin: 18px 2px 0; }
.opt { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 14px; padding: 10px 12px; box-shadow: 0 2px 0 rgba(0,0,0,.04); }
.opt input { width: 22px; height: 22px; accent-color: var(--me); }
.opt span { font-weight: 700; font-size: .92rem; }
.opt em { display: block; font-style: normal; font-weight: 500; font-size: .74rem; color: var(--ink-soft); }

.opt-num { justify-content: space-between; }
.numbox { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.numbox input { width: 68px; font: inherit; font-weight: 800; font-size: 1.05rem; text-align: center;
  padding: 8px 6px; border-radius: 12px; border: 3px solid var(--line); background: #fffdf9; color: var(--ink); }
.numbox input:focus { outline: none; border-color: var(--me); }
.numbox b { font-size: .82rem; color: var(--ink-soft); }

.home-actions { display: flex; gap: 10px; margin-top: 18px; }
.big-btn { flex: 1; background: var(--me); color: var(--me-ink); border-radius: 18px; padding: 16px; font-size: 1.15rem; box-shadow: 0 5px 0 #d9822b; }
.big-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #d9822b; }
.ghost-btn { background: #fff; color: var(--ink); border-radius: 18px; padding: 16px; box-shadow: 0 3px 0 var(--line); }
.tiny { font-size: .72rem; color: var(--ink-soft); text-align: center; margin-top: 14px; }

/* 게임 화면 */
.bar { display: flex; align-items: center; gap: 10px; }
.icon-btn { background: #fff; width: 40px; height: 40px; border-radius: 50%; font-size: 1.2rem; box-shadow: 0 3px 0 var(--line); }
.bar-level { flex: 1; font-weight: 800; display: flex; gap: 6px; align-items: center; }
.bar-score { background: #fff; border-radius: 999px; padding: 6px 14px; box-shadow: 0 3px 0 var(--line); font-weight: 800; font-size: .9rem; }
.bar-score b { font-size: 1.1rem; color: var(--me); }

.timer { position: relative; height: 12px; background: #fff; border-radius: 999px; margin: 12px 0 4px; overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,.06); }
#timerBar { height: 100%; width: 100%; background: linear-gradient(90deg, #7bd389, #ffd166); transition: width .25s linear; }
.timer.warn #timerBar { background: linear-gradient(90deg, #ff8f6b, #e0525b); }
#timerText { position: absolute; right: 8px; top: -2px; font-size: .62rem; font-weight: 800; color: var(--ink-soft); }

.log { flex: 1; overflow-y: auto; padding: 10px 2px 6px; display: flex; flex-direction: column; gap: 10px; min-height: 180px; }
.bubble { max-width: 84%; border-radius: 18px; padding: 10px 14px; box-shadow: var(--shadow); animation: pop .18s ease-out; }
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.bubble .word { font-size: 1.45rem; font-weight: 800; letter-spacing: -.5px; }
.bubble .mean { font-size: .86rem; color: var(--ink-soft); margin-top: 2px; }
.bubble.ai { align-self: flex-start; background: var(--ai); border-bottom-left-radius: 6px; }
.bubble.me { align-self: flex-end; background: var(--me); color: var(--me-ink); border-bottom-right-radius: 6px; }
.bubble.me .mean { color: #7a4a11; }
.bubble .who { font-size: .68rem; font-weight: 800; color: var(--ink-soft); margin-bottom: 2px; }
.bubble.me .who { color: #8a4b00; text-align: right; }
.bubble .tagchip { display: inline-block; font-size: .62rem; font-weight: 800; background: #fff2e0; color: #b9702a; border-radius: 999px; padding: 2px 8px; margin-top: 6px; }
.bubble.system { align-self: center; background: #fffbf4; color: var(--ink-soft); font-size: .82rem; font-weight: 600; text-align: center; box-shadow: none; border: 2px dashed var(--line); }
.bubble.bomb { border: 3px solid var(--bad); }
.bubble.hint { align-self: stretch; max-width: 100%; background: #fff6e0; border: 3px dashed #f0c476; box-shadow: none; }
.bubble.hint .hint-head { font-size: 1.05rem; font-weight: 700; }
.bubble.hint .hint-head b { font-size: 1.3rem; letter-spacing: 2px; color: #c4681c; }
.bubble.hint .hint-mean { font-size: .86rem; color: var(--ink-soft); margin-top: 4px; }

.turnbox { background: var(--card); border-radius: 22px; padding: 14px; box-shadow: var(--shadow); }
.need { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.need-label { font-size: .72rem; color: var(--ink-soft); font-weight: 700; }
.need-char { font-size: 1.8rem; font-weight: 800; background: #fff2e0; border-radius: 14px; padding: 2px 14px; color: #c4681c; }
.need-alt { font-size: .78rem; color: var(--ink-soft); font-weight: 700; }
.composer { display: flex; gap: 8px; }
#wordInput { flex: 1; font: inherit; font-size: 1.25rem; font-weight: 700; padding: 12px 14px; border-radius: 16px; border: 3px solid var(--line); background: #fffdf9; color: var(--ink); min-width: 0; }
#wordInput:focus { outline: none; border-color: var(--me); }
.send-btn { background: var(--me); color: var(--me-ink); border-radius: 16px; padding: 0 18px; box-shadow: 0 4px 0 #d9822b; }
.send-btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #d9822b; }
.send-btn:disabled { opacity: .5; box-shadow: none; }
.tools { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.tool-btn { background: #fff6ea; border-radius: 999px; padding: 8px 12px; font-size: .82rem; box-shadow: 0 2px 0 var(--line); }
.tool-btn:disabled { opacity: .45; }
.chips { margin-left: auto; display: flex; gap: 4px; flex-wrap: wrap; }
.chip { font-size: .62rem; font-weight: 800; background: #f4ece1; color: var(--ink-soft); border-radius: 999px; padding: 3px 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #4a2f1a; color: #fff;
  padding: 12px 18px; border-radius: 16px; font-weight: 700; font-size: .92rem; max-width: 90vw; text-align: center;
  box-shadow: 0 10px 24px rgba(0,0,0,.25); z-index: 20; animation: pop .16s ease-out; }
.toast.good { background: var(--good); }
.toast.bad { background: var(--bad); }

/* 결과 */
.result-card { background: var(--card); border-radius: 26px; padding: 22px 18px; box-shadow: var(--shadow); text-align: center; }
.stage { position: relative; height: 96px; display: flex; align-items: center; justify-content: center; }
.result-emoji { font-size: 3.4rem; animation: bob 2s ease-in-out infinite; }

/* 컴퓨터가 졌을 때 — 휘청이다 빙글 돌며 쓰러진다 */
.result-emoji.knockout { animation: knockout 1.5s cubic-bezier(.3,.8,.4,1) forwards; }
@keyframes knockout {
  0%   { transform: translateX(0) rotate(0) scale(1); }
  8%   { transform: translateX(-10px) rotate(-12deg) scale(1.25); }
  16%  { transform: translateX(10px) rotate(12deg) scale(1.25); }
  24%  { transform: translateX(-8px) rotate(-10deg) scale(1.2); }
  32%  { transform: translateX(8px) rotate(10deg) scale(1.2); }
  44%  { transform: translateY(-26px) rotate(180deg) scale(1.1); }
  70%  { transform: translateY(10px) rotate(420deg) scale(.95); }
  100% { transform: translateY(26px) rotate(455deg) scale(.9); opacity: .55; }
}
/* 아이가 졌을 때 — 상대가 으스대며 콩콩 뛴다 */
.result-emoji.gloat { animation: gloat 1.1s ease-in-out 3; }
@keyframes gloat {
  0%, 100% { transform: translateY(0) rotate(0); }
  25% { transform: translateY(-14px) rotate(-8deg) scale(1.1); }
  60% { transform: translateY(0) rotate(8deg); }
}
.boom { position: absolute; font-size: 4.6rem; opacity: 0; pointer-events: none; }
.boom.go { animation: boom .7s ease-out forwards; }
@keyframes boom {
  0%   { opacity: 1; transform: scale(.3) rotate(-20deg); }
  60%  { opacity: .9; transform: scale(1.6) rotate(10deg); }
  100% { opacity: 0; transform: scale(2.2) rotate(20deg); }
}
.shake { animation: shake .5s ease-in-out 1; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-6px, 3px); }
  40% { transform: translate(6px, -3px); }
  60% { transform: translate(-4px, -2px); }
  80% { transform: translate(4px, 2px); }
}

/* 패배 대사 */
.taunt { min-height: 2.6em; margin: 6px 4px 10px; padding: 12px 14px; border-radius: 18px;
  background: #fff6e0; border: 3px dashed #f0c476; font-weight: 700; font-size: 1.02rem;
  line-height: 1.45; color: #6b4a22; }
.taunt::after { content: '▌'; opacity: .45; animation: caret .7s steps(1) infinite; }
.taunt.done::after { content: ''; }
@keyframes caret { 50% { opacity: 0; } }

/* 꽃가루 */
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 30; }
.confetti i { position: absolute; top: -24px; width: 10px; height: 16px; border-radius: 2px;
  animation: fall linear forwards; }
@keyframes fall {
  0%   { transform: translateY(-10vh) rotate(0); opacity: 1; }
  100% { transform: translateY(105vh) rotate(720deg); opacity: .9; }
}
.result-card h2 { margin: 6px 0 4px; font-size: 1.7rem; }
.result-why { color: var(--ink-soft); margin: 0 0 14px; font-size: .92rem; }
.result-nums { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
.result-nums div { flex: 1; background: #fff7ec; border-radius: 16px; padding: 10px 4px; }
.result-nums b { display: block; font-size: 1.35rem; color: var(--me); }
.result-nums span { font-size: .68rem; color: var(--ink-soft); font-weight: 700; }
.learned { list-style: none; padding: 0; margin: 0 0 16px; text-align: left; max-height: 220px; overflow-y: auto; }
.learned li { border-bottom: 1px dashed var(--line); padding: 8px 4px; }
.learned b { font-size: 1rem; }
.learned span { display: block; font-size: .8rem; color: var(--ink-soft); }
.learned .from { font-size: .62rem; font-weight: 800; color: #b9702a; }
.result-actions { display: flex; flex-direction: column; gap: 8px; }

dialog { border: 0; border-radius: 22px; padding: 22px; max-width: 460px; width: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0,0,0,.3); background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgba(60,35,15,.45); }
.rules { padding-left: 20px; margin: 0 0 8px; }
.rules li { margin-bottom: 10px; font-size: .92rem; }
.rules i { font-style: normal; color: #b9702a; font-weight: 700; }

@media (min-width: 520px) { body { font-size: 18px; } }
/* 움직임을 줄여 달라고 한 사람에게는 흔들지 않는다. 대신 결과는 그대로 보여 준다 —
   컴퓨터는 쓰러진 채로, 아이는 꽃가루 없이. */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
  .result-emoji.knockout { transform: rotate(95deg) translateY(18px); opacity: .6; }
  .boom.go { opacity: .9; transform: scale(1.4); }
  .confetti { display: none; }
  .taunt::after { content: ''; }
}
