@import url('https://fonts.googleapis.com/css2?family=Jua&display=swap');

:root {
  --bg: #0b1030;
  --bg2: #151c4d;
  --panel: rgba(24, 32, 84, 0.82);
  --panel-line: rgba(140, 170, 255, 0.28);
  --text: #f2f5ff;
  --muted: #a9b4e6;
  --cyan: #4fe3ff;
  --cyan-deep: #1aa9d6;
  --yellow: #ffd84a;
  --pink: #ff6fae;
  --green: #4dff9a;
  --red: #ff5b6b;
  --violet: #9b7bff;
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;
  --font-fun: 'Jua', var(--font);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 50% 0%, var(--bg2), var(--bg) 70%);
  background-color: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.hidden { display: none !important; }

#stars { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; }

#app {
  position: relative; z-index: 1;
  height: 100dvh; max-width: 480px; margin: 0 auto;
  padding: calc(var(--safe-top) + 10px) 16px calc(var(--safe-bottom) + 12px);
}
.screen { display: none; height: 100%; flex-direction: column; }
.screen.active { display: flex; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- 공통 버튼 ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; padding: 10px 16px; border-radius: 16px;
  font-family: var(--font-fun); font-size: 19px; letter-spacing: .5px;
  background: var(--panel); border: 2px solid var(--panel-line);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .35);
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .35); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn-big { min-height: 62px; font-size: 22px; width: 100%; }
.btn-primary { background: linear-gradient(180deg, #5ef0ff, #1aa9d6); border-color: #9ff6ff; color: #04203a; }
.btn-daily { background: linear-gradient(180deg, #ffe27a, #f2a922); border-color: #fff0b3; color: #3a2400; justify-content: space-between; }
.btn-danger { background: linear-gradient(180deg, #a68bff, #5a33d6); border-color: #cdbfff; justify-content: space-between; }
.btn-ghost { background: rgba(255, 255, 255, .07); }
.badge {
  font-family: var(--font); font-size: 14px; font-weight: 700;
  background: rgba(0, 0, 0, .25); padding: 4px 10px; border-radius: 999px;
}
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; font-size: 26px; line-height: 1;
  display: grid; place-items: center; background: rgba(255, 255, 255, .08);
}
.icon-btn.off { opacity: .35; }
.link-btn { color: var(--muted); font-size: 14px; text-decoration: underline; padding: 8px; margin: 2px auto 0; }

/* ---------- 홈 ---------- */
.home-top { display: flex; justify-content: flex-end; gap: 8px; }
.home-hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; position: relative; min-height: 0; }
.robot-wrap { width: 128px; animation: float 3s ease-in-out infinite; cursor: pointer; }
.robot-wrap.small { width: 92px; }
.robot-wrap.tiny { width: 54px; animation: none; flex: none; }
@keyframes float { 50% { transform: translateY(-10px); } }
.logo {
  font-family: var(--font-fun); font-weight: 400; font-size: clamp(40px, 12vw, 54px); margin: 6px 0 4px;
  background: linear-gradient(180deg, #fff 10%, var(--cyan) 60%, var(--violet));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 0 14px rgba(79, 227, 255, .45));
}
.tagline { text-align: center; color: var(--muted); margin: 0; line-height: 1.5; font-size: 15px; }
.tagline b { color: var(--cyan); }
.menu { display: flex; flex-direction: column; gap: 12px; padding-bottom: 6px; }
.menu-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.speech {
  position: absolute; top: 4%; background: #fff; color: #1b1f4a; padding: 8px 14px; border-radius: 14px;
  font-family: var(--font-fun); font-size: 17px; animation: pop .3s ease;
}
.speech::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -8px; border: 8px solid transparent; border-top-color: #fff; border-bottom: 0; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

/* ---------- 로봇 SVG ---------- */
.robot .head { fill: #dfe7ff; stroke: #8fa3e8; stroke-width: 3; }
.robot .face { fill: #18204f; }
.robot .eye { fill: var(--cyan); }
.robot .eye-line, .robot .mouth { fill: none; stroke: var(--cyan); stroke-width: 4; stroke-linecap: round; }
.robot .mouth-fill { fill: var(--cyan); }
.robot .cheek { fill: var(--pink); opacity: .7; }
.robot .ear { fill: #9fb2f0; }
.robot .antenna { stroke: #9fb2f0; stroke-width: 3; }
.robot .antenna-ball { fill: var(--yellow); filter: drop-shadow(0 0 4px var(--yellow)); }
.robot .body { fill: #c8d3ff; stroke: #8fa3e8; stroke-width: 3; }
.robot .core { fill: var(--yellow); }
.robot .arm { fill: #9fb2f0; }
.robot .flame { fill: rgba(255, 170, 60, .75); animation: flame .25s infinite alternate; transform-origin: 60px 138px; }
@keyframes flame { to { transform: scaleX(.75); opacity: .5; } }
.robot-happy .arm-l { transform: rotate(35deg); transform-origin: 23px 92px; }
.robot-happy .arm-r { transform: rotate(-35deg); transform-origin: 97px 92px; }
.robot-sad .eye-line, .robot-sad .mouth { stroke: #7aa2ff; }
.robot-sad .antenna-ball { fill: #7aa2ff; filter: none; }

/* ---------- 행성 ---------- */
.planet { width: 64px; height: 64px; border-radius: 50%; flex: none; position: relative; box-shadow: inset -10px -10px 18px rgba(0, 0, 0, .45), 0 0 22px rgba(255, 255, 255, .12); }
.planet.big { width: 120px; height: 120px; }
.planet-moon { background: radial-gradient(circle at 35% 30%, #f4f4f8, #a9adc4 60%, #6c7090); }
.planet-moon::after { content: ''; position: absolute; width: 22%; height: 22%; left: 52%; top: 50%; border-radius: 50%; background: rgba(0, 0, 0, .15); box-shadow: -160% -120% 0 -2px rgba(0, 0, 0, .12); }
.planet-mars { background: radial-gradient(circle at 35% 30%, #ffb38a, #e0562c 60%, #8c2a14); }
.planet-saturn { background: radial-gradient(circle at 35% 30%, #fff1b8, #e6b84f 60%, #9a6a1c); }
.planet-saturn::before { content: ''; position: absolute; left: -24%; right: -24%; top: 42%; height: 16%; border-radius: 50%; border: 3px solid rgba(255, 230, 160, .85); transform: rotate(-16deg); }
.planet-blackhole { background: radial-gradient(circle, #000 38%, #5a33d6 52%, #ff6fae 62%, transparent 72%); box-shadow: 0 0 30px rgba(155, 123, 255, .6); animation: spin 6s linear infinite; }
.planet-earth { background: radial-gradient(circle at 35% 30%, #9be7ff, #2f7fe0 55%, #164a8a); }
.planet-earth::after { content: ''; position: absolute; inset: 22% 30% 40% 18%; background: #47c46b; border-radius: 40% 60% 50% 40%; opacity: .9; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 상단바 ---------- */
.topbar { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px; min-height: 48px; }
.topbar h2 { margin: 0; text-align: center; font-family: var(--font-fun); font-weight: 400; font-size: 21px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar > span { width: 44px; }
.score { font-family: var(--font-fun); font-size: 17px; color: var(--yellow); min-width: 44px; text-align: right; white-space: nowrap; }

/* ---------- 행성 선택 ---------- */
.level-list { display: flex; flex-direction: column; gap: 14px; padding-top: 12px; overflow-y: auto; }
.level-card {
  display: flex; align-items: center; gap: 16px; text-align: left; width: 100%;
  padding: 16px; border-radius: var(--radius); background: var(--panel); border: 2px solid var(--panel-line);
  box-shadow: 0 4px 0 rgba(0, 0, 0, .35);
}
.level-card:active { transform: translateY(3px); }
.level-card .info { flex: 1; min-width: 0; }
.level-card .name { font-family: var(--font-fun); font-size: 23px; }
.level-card .grade { font-size: 13px; color: var(--cyan); font-weight: 700; margin-left: 6px; }
.level-card .desc { color: var(--muted); font-size: 14px; margin-top: 2px; }
.level-card .best { color: var(--yellow); font-size: 14px; margin-top: 6px; }

/* ---------- 게임 ---------- */
.track { display: flex; align-items: center; gap: 4px; margin: 6px 0 4px; height: 28px; }
.track .dot { flex: 1; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, .12); position: relative; }
.track .dot.done { background: linear-gradient(90deg, var(--cyan), var(--green)); box-shadow: 0 0 8px var(--cyan); }
.track .dot.miss { background: rgba(255, 91, 107, .5); }
.track .dot.now { background: rgba(79, 227, 255, .35); animation: blink 1s infinite alternate; }
.track .planet { width: 26px; height: 26px; }
@keyframes blink { to { opacity: .4; } }
.hearts { letter-spacing: 2px; }

.timer { position: relative; height: 22px; border-radius: 11px; background: rgba(255, 255, 255, .1); overflow: hidden; margin: 6px 0; }
.timer-fill { position: absolute; inset: 0; transform-origin: left; background: linear-gradient(90deg, var(--green), var(--cyan)); transition: transform .25s linear; }
.timer.low .timer-fill { background: linear-gradient(90deg, var(--red), #ff9a4d); }
.timer span { position: relative; display: block; text-align: center; font-size: 13px; font-weight: 700; line-height: 22px; }

.target-panel { text-align: center; margin: 4px auto 0; padding: 6px 26px 8px; border-radius: 22px; background: rgba(0, 0, 0, .3); border: 2px solid rgba(79, 227, 255, .45); box-shadow: 0 0 24px rgba(79, 227, 255, .2), inset 0 0 18px rgba(79, 227, 255, .15); }
.target-label { font-size: 13px; color: var(--muted); }
.target { font-family: var(--font-fun); font-size: clamp(46px, 15vw, 64px); line-height: 1.05; color: var(--yellow); text-shadow: 0 0 18px rgba(255, 216, 74, .55); }

.bridge-area { position: relative; flex: 1; display: flex; align-items: center; justify-content: center; min-height: 110px; }
.bridge { position: relative; z-index: 2; display: flex; align-items: center; justify-content: center; gap: 4px; width: 100%; }
.num, .slot {
  flex: 1 1 0; min-width: 0; max-width: 64px; height: 66px; border-radius: 16px;
  display: grid; place-items: center; font-family: var(--font-fun); line-height: 1;
}
.num {
  font-size: clamp(28px, 8.5vw, 38px); background: linear-gradient(180deg, #2b3a8f, #1b2463);
  border: 2px solid #6f86ff; box-shadow: 0 4px 0 #0c1240;
}
.num.can-square { border-style: dashed; }
.num { position: relative; }
.num sup { position: absolute; top: 5px; right: 4px; font-size: .5em; line-height: 1; color: var(--pink); }
.bridge.many { gap: 3px; }
.bridge.many .num { font-size: clamp(24px, 7.5vw, 36px); border-radius: 13px; }
.bridge.many .slot { flex-grow: .8; border-radius: 13px; font-size: clamp(22px, 7vw, 32px); }
.num.squared { border-color: var(--pink); border-style: solid; background: linear-gradient(180deg, #5a2a7d, #33184f); }
.slot {
  max-width: 54px; height: 54px; font-size: clamp(26px, 8vw, 34px);
  border: 3px dashed rgba(79, 227, 255, .55); background: rgba(79, 227, 255, .06); color: var(--cyan);
}
.slot.filled { border-style: solid; background: rgba(79, 227, 255, .18); color: #fff; }
.slot.selected { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 216, 74, .35), 0 0 16px rgba(255, 216, 74, .5); animation: pulse 1s infinite alternate; }
.slot.locked { border-color: var(--green); color: var(--green); background: rgba(77, 255, 154, .12); }
.slot.locked::after { content: '🔒'; position: absolute; font-size: 11px; transform: translate(14px, -18px); }
.num.locked { box-shadow: 0 0 0 3px var(--green); }
@keyframes pulse { to { transform: scale(1.07); } }
.bridge.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

.beam { position: absolute; z-index: 1; left: 0; right: 0; top: 50%; height: 10px; margin-top: -5px; border-radius: 5px; transform: scaleX(0); transform-origin: left; background: linear-gradient(90deg, var(--cyan), #fff, var(--green)); box-shadow: 0 0 18px var(--cyan); }
.beam.built { animation: beam .7s ease-out forwards; }
@keyframes beam { to { transform: scaleX(1); } }
.mini-robot { position: absolute; z-index: 3; width: 44px; left: -10px; top: 50%; margin-top: -62px; opacity: 0; pointer-events: none; }
.mini-robot.go { animation: zoom 1.1s ease-in-out .35s forwards; }
@keyframes zoom { 0% { opacity: 1; transform: translateX(0) rotate(0); } 85% { opacity: 1; } 100% { opacity: 0; transform: translateX(calc(min(100vw, 480px) - 40px)) rotate(10deg); } }

.tip-row { display: flex; align-items: center; gap: 10px; min-height: 56px; margin: 4px 0 8px; }
.tip-robot { width: 40px; flex: none; }
.tip { margin: 0; flex: 1; background: rgba(255, 255, 255, .92); color: #1b1f4a; padding: 8px 12px; border-radius: 14px; font-size: 14.5px; line-height: 1.4; position: relative; }
.tip::before { content: ''; position: absolute; left: -7px; top: 50%; margin-top: -7px; border: 7px solid transparent; border-right-color: rgba(255, 255, 255, .92); border-left: 0; }
.tip.hint { background: #fff4c2; }
.tip.hint::before { border-right-color: #fff4c2; }

.palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 10px; }
.palette.three { grid-template-columns: repeat(3, 1fr); }
.op-btn {
  height: 66px; border-radius: 18px; font-family: var(--font-fun); font-size: 38px; line-height: 1;
  background: linear-gradient(180deg, #ffffff, #d7defa); color: #22307a; box-shadow: 0 5px 0 #7c8bd1;
}
.op-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 #7c8bd1; }
.actions { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 8px; }
.actions .btn { font-size: 17px; padding: 8px 4px; white-space: nowrap; gap: 4px; }
@media (max-width: 350px) { .actions .btn { font-size: 15px; } .op-btn { font-size: 32px; } }

/* ---------- 시트 / 모달 ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 20; background: rgba(4, 7, 25, .6); display: flex; align-items: flex-end; justify-content: center; animation: fadeIn .2s; }
.sheet {
  width: 100%; max-width: 480px; max-height: 88dvh; overflow-y: auto;
  background: linear-gradient(180deg, #1f2a6e, #141a4a); border: 2px solid var(--panel-line); border-bottom: 0;
  border-radius: 26px 26px 0 0; padding: 18px 18px calc(var(--safe-bottom) + 18px);
  animation: up .28s cubic-bezier(.2, .9, .3, 1.2);
}
@keyframes up { from { transform: translateY(100%); } }
.sheet.modal { border-radius: 24px; margin: auto 16px; border-bottom: 2px solid var(--panel-line); }
#modal-back { align-items: center; }
.sheet h3 { margin: 0; font-family: var(--font-fun); font-weight: 400; font-size: 26px; }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.sheet.good h3 { color: var(--green); }
.sheet.bad h3 { color: #ffb0b8; }
.stars { font-size: 26px; letter-spacing: 2px; min-height: 4px; }
.stars .off { filter: grayscale(1); opacity: .3; }
.sheet-body { font-size: 16px; line-height: 1.55; }
.sheet-body p { margin: 6px 0; }
.expr { font-family: var(--font-fun); font-size: 24px; text-align: center; padding: 8px; border-radius: 12px; background: rgba(0, 0, 0, .25); margin: 6px 0; word-break: keep-all; }
.steps { list-style: none; padding: 0; margin: 8px 0; counter-reset: s; }
.steps li { counter-increment: s; display: flex; gap: 10px; align-items: center; padding: 6px 4px; font-size: 17px; border-bottom: 1px dashed rgba(255, 255, 255, .12); }
.steps li::before { content: counter(s); width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--cyan); color: #04203a; font-weight: 800; font-size: 13px; flex: none; }
.steps li.err { color: #ffb0b8; }
.steps li.err::before { background: var(--red); color: #fff; }
.diff { font-weight: 700; color: var(--yellow); }
.points { font-family: var(--font-fun); font-size: 22px; color: var(--yellow); text-align: center; margin-top: 6px; }
.sheet-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.input-big { width: 100%; height: 56px; border-radius: 14px; border: 2px solid var(--panel-line); background: rgba(0, 0, 0, .3); color: #fff; font-size: 26px; text-align: center; font-family: var(--font-fun); margin-top: 10px; }

/* ---------- 결과 ---------- */
.result { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 4px; }
.result .robot-wrap { margin-top: -46px; }
.result h2 { font-family: var(--font-fun); font-weight: 400; font-size: 34px; margin: 6px 0 0; color: var(--yellow); }
.result p { color: var(--muted); margin: 0 0 8px; }
.result-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; width: 100%; margin: 8px 0 18px; }
.stat { background: var(--panel); border: 2px solid var(--panel-line); border-radius: 16px; padding: 10px 4px; }
.stat b { display: block; font-family: var(--font-fun); font-weight: 400; font-size: 24px; color: var(--cyan); }
.stat span { font-size: 12.5px; color: var(--muted); }
.result .menu { width: 100%; }
.new-record { color: var(--pink); font-family: var(--font-fun); font-size: 20px; animation: pulse .6s infinite alternate; }

/* ---------- 도움말 / 보호자 ---------- */
.scroll { overflow-y: auto; flex: 1; padding: 8px 0 20px; -webkit-overflow-scrolling: touch; }
.card { background: var(--panel); border: 2px solid var(--panel-line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; line-height: 1.55; font-size: 15px; }
.card h3 { margin: 0 0 6px; font-family: var(--font-fun); font-weight: 400; font-size: 20px; color: var(--cyan); }
.card p { margin: 6px 0; }
.card ol { margin: 4px 0; padding-left: 22px; }
.example { font-family: var(--font-fun); font-size: 22px; text-align: center; background: rgba(0, 0, 0, .25); border-radius: 12px; padding: 8px; margin: 8px 0; }
.example i { font-style: normal; color: var(--cyan); }
.example b { color: var(--yellow); font-weight: 400; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.kpi { background: var(--panel); border: 2px solid var(--panel-line); border-radius: 16px; padding: 12px; }
.kpi b { display: block; font-size: 26px; font-family: var(--font-fun); font-weight: 400; color: var(--text); }
.kpi span { font-size: 13px; color: var(--muted); }
.bar-row { display: grid; grid-template-columns: 92px 1fr 64px; align-items: center; gap: 8px; margin: 9px 0; font-size: 14px; }
.bar { height: 14px; border-radius: 7px; background: rgba(255, 255, 255, .1); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 7px; background: var(--cyan); }
.bar i.warn { background: #ff9a4d; }
.bar-row .v { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.days { display: flex; align-items: flex-end; gap: 4px; height: 90px; padding-top: 6px; }
.days .d { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 10px; color: var(--muted); gap: 3px; }
.days .d i { width: 100%; border-radius: 4px 4px 0 0; background: var(--cyan); min-height: 2px; }
.days .d.today i { background: var(--yellow); }
.advice { background: rgba(255, 216, 74, .12); border-color: rgba(255, 216, 74, .4); }
.muted { color: var(--muted); font-size: 13px; }

/* ---------- 폭죽 ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (min-height: 760px) {
  .num { height: 74px; }
  .op-btn { height: 74px; }
}
@media (max-height: 640px) {
  .robot-wrap { width: 96px; }
  .tip-row { min-height: 44px; }
  .tip { font-size: 13px; padding: 6px 10px; }
  .btn-big { min-height: 54px; }
  .num { height: 56px; }
  .op-btn { height: 56px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
