/* 콘셉트: 그림책 속 숲길 표지판. 하얀 종이 판 위에 갈색 글씨, 눈에 띄는 것은 초록 출발 버튼 하나 */
:root {
  --ink: #3b2a1d;        /* 도토리 갈색 글씨 */
  --muted: #7d6a5a;
  --paper: #ffffff;
  --line: #e7dccf;
  --sky: #2f80c8;        /* 고르기 표시 */
  --leaf: #3e9b4f;       /* 출발 버튼 */
  --leaf-dark: #2c7a3b;
  --berry: #e0483e;      /* 하트, 오답 */
  --sun: #f4b63c;        /* 힘 게이지 */
  --display: "Jua", "Gowun Dodum", system-ui, sans-serif;
  --body: "Gowun Dodum", system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: #1d2a36; color: var(--ink); font-family: var(--body); overflow: hidden; }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }
h1, h2 { font-family: var(--display); font-weight: 400; margin: 0; line-height: 1.2; }

#app { position: fixed; inset: 0; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- 달리는 중 정보 ---------- */
#hud {
  position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  pointer-events: none; font-family: var(--display);
}
.hud-left, .hud-right { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hud-right { justify-content: flex-end; }
.hearts { display: flex; gap: 2px; }
.hearts img { width: 34px; height: 34px; object-fit: contain; filter: drop-shadow(0 2px 0 rgba(0,0,0,.15)); transition: transform .2s; }
.hearts img.lost { filter: grayscale(1) opacity(.35); transform: scale(.8); }
.energy { display: flex; align-items: center; gap: 6px; background: rgba(255,255,255,.88); border-radius: 999px; padding: 4px 10px 4px 12px; }
.energy-label { font-family: var(--display); font-size: 17px; }
.cells { display: flex; gap: 4px; }
.cells i { position: relative; width: 58px; height: 16px; border-radius: 8px; background: #eadfce; overflow: hidden; }
.cells i::after { content: ""; position: absolute; inset: 0; width: calc(var(--f, 0) * 100%); background: var(--sun); border-radius: 8px; transition: width .25s ease-out; }
.energy.low .cells i::after { background: var(--berry); }
.pill { background: rgba(255,255,255,.88); border-radius: 999px; padding: 4px 14px; font-size: 20px; display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.pill img { width: 24px; height: 24px; object-fit: contain; }
.round { pointer-events: auto; border: 0; background: rgba(255,255,255,.88); border-radius: 999px; padding: 6px 14px; font-family: var(--display); font-size: 16px; }

/* 점프·숙이기 버튼 (태블릿) */
#pad { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; pointer-events: none;
  padding: 0 max(18px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); }
#pad button {
  pointer-events: auto; touch-action: none; width: 118px; height: 118px; border-radius: 50%; border: 4px solid rgba(255,255,255,.95);
  background: rgba(47,128,200,.55); color: #fff; font-family: var(--display); font-size: 24px; text-shadow: 0 2px 0 rgba(0,0,0,.25);
  -webkit-user-select: none; user-select: none;
}
#pad #slidePad { background: rgba(224,120,40,.6); }
#pad button.on { transform: scale(.94); background: rgba(224,120,40,.85); }
@media (max-height: 520px) { #pad button { width: 88px; height: 88px; font-size: 19px; } }
#gate {
  position: absolute; top: max(62px, calc(env(safe-area-inset-top) + 52px)); left: 50%; transform: translateX(-50%);
  background: var(--paper); border: 3px solid var(--sky); border-radius: 16px; padding: 8px 18px; display: flex; align-items: center; gap: 12px;
  font-family: var(--display); font-size: 30px; box-shadow: 0 6px 18px rgba(0,0,0,.18); pointer-events: none; white-space: nowrap;
}
.gate-tag { font-size: 15px; background: var(--sky); color: #fff; border-radius: 8px; padding: 2px 8px; }
#toast {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); font-family: var(--display); font-size: 34px; color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,.35); pointer-events: none; opacity: 0; transition: opacity .2s; text-align: center; white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ---------- 공통 화면 ---------- */
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
.screen.dim { background: rgba(20, 30, 40, .45); }
.card { background: var(--paper); border-radius: 22px; padding: 26px 30px; display: grid; gap: 14px; text-align: center; min-width: min(360px, 100%); box-shadow: 0 14px 40px rgba(0,0,0,.25); }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.btn { border: 0; border-radius: 16px; padding: 14px 26px; font-family: var(--display); font-size: 22px; }
.btn.small { padding: 10px 20px; font-size: 19px; }
.btn.go { background: var(--leaf); color: #fff; box-shadow: 0 5px 0 var(--leaf-dark); }
.btn.go:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--leaf-dark); }
.btn.go:disabled { background: #b9c4ba; box-shadow: 0 5px 0 #9aa59b; cursor: default; }
.btn.ghost { background: #f3ece3; color: var(--ink); box-shadow: 0 5px 0 #dccfbf; }
.btn.ghost:active { transform: translateY(3px); box-shadow: 0 2px 0 #dccfbf; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 14px; padding: 4px; }
.fullbtn { margin-left: auto; border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 14px; font-family: var(--display); font-size: 16px; }
.fullbtn.install { background: var(--leaf); border-color: var(--leaf); color: #fff; }
.fullbtn.install + .fullbtn { margin-left: 0; }
.tip { margin: -4px 0 0; background: #eef5fc; border-radius: 12px; padding: 8px 12px; font-size: 14px; display: flex; gap: 8px; align-items: center; justify-content: space-between; }
#inapp .card { max-width: 440px; }
#inapp a.btn { text-decoration: none; }
.link.studio { color: var(--ink); font-weight: 700; text-underline-offset: 3px; }

/* ---------- 시작 화면 ---------- */
#menu { background: linear-gradient(rgba(20,30,40,.25), rgba(20,30,40,.25)); }
.sheet {
  background: rgba(255,255,255,.96); border-radius: 26px; width: min(1080px, 100%); max-height: 100%; overflow: auto; overscroll-behavior: contain;
  padding: 22px 26px 16px; display: grid; gap: 14px; box-shadow: 0 18px 50px rgba(0,0,0,.3); -webkit-user-select: none;
}
.brand { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
.brand h1 { font-size: 46px; color: var(--leaf-dark); letter-spacing: .01em; }
.brand p { margin: 0; color: var(--muted); flex-basis: 100%; order: 3; }
.brand .tagline { font-family: var(--display); font-size: 20px; color: var(--ink); }
.cols { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 22px; }
.col { display: grid; gap: 10px; align-content: start; min-width: 0; }
.col h2 { font-size: 21px; }
.col-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.petbtn { display: inline-flex; align-items: center; gap: 6px; border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 2px 12px 2px 4px; font-family: var(--display); font-size: 16px; }
.petbtn img { width: 34px; height: 34px; object-fit: contain; }
dialog.wide { width: min(680px, 94vw); max-width: none; max-height: 92vh; }
.petgrid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; margin-bottom: 14px; }
.trailgrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.petgrid .pick img { max-width: 70px; }
.trailgrid .pick img { width: 40px; height: 40px; object-fit: contain; }
.pick .none { width: 100%; max-width: 70px; aspect-ratio: 1; border: 2px dashed var(--line); border-radius: 50%; }
.petgrid .pick small { font-size: 12px; text-align: center; }
.trailgrid .pick .none { width: 40px; height: 40px; }
@media (max-width: 560px) { .petgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); } .trailgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
dialog .note { color: var(--muted); font-size: 14px; margin: 10px 0; }
.chars { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.pick { background: #faf6f0; border: 3px solid transparent; border-radius: 18px; padding: 8px 6px 10px; display: grid; justify-items: center; gap: 2px; }
.pick[aria-checked="true"] { border-color: var(--sky); background: #eef5fc; }
.pick img { width: 100%; max-width: 120px; aspect-ratio: 1; object-fit: contain; }
.pick b { font-family: var(--display); font-weight: 400; font-size: 19px; }
.pick small { color: var(--muted); font-size: 13px; }
.maps { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.map { border: 3px solid transparent; border-radius: 16px; padding: 0; overflow: hidden; position: relative; background: #ddd; aspect-ratio: 16 / 7; }
.map img { width: 100%; height: 100%; object-fit: cover; display: block; }
.map span { position: absolute; left: 8px; bottom: 6px; background: rgba(255,255,255,.92); border-radius: 10px; padding: 1px 10px; font-family: var(--display); font-size: 16px; }
.map[aria-checked="true"] { border-color: var(--sky); }
.grades { display: flex; gap: 6px; flex-wrap: wrap; }
.grades button { border: 0; background: #f3ece3; border-radius: 12px; padding: 7px 14px; font-family: var(--display); font-size: 18px; }
.grades button[aria-selected="true"] { background: var(--sky); color: #fff; }
.units { display: grid; gap: 6px; max-height: 300px; overflow: auto; padding-right: 4px; }
.unit { text-align: left; border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 9px 12px; display: grid; gap: 1px; }
.unit[aria-checked="true"] { border-color: var(--sky); background: #eef5fc; }
.unit b { font-weight: 700; font-size: 16px; }
.unit small { color: var(--muted); font-size: 13px; }
.locked { background: #eef5fc; border-radius: 14px; padding: 12px 14px; }
.go-row { display: flex; gap: 12px; justify-content: flex-end; flex-wrap: wrap; }
.go-row .go { min-width: 200px; font-size: 26px; }
.foot { display: flex; gap: 14px; align-items: center; justify-content: flex-end; flex-wrap: wrap; color: var(--muted); font-size: 14px; }
.foot #bestLine { margin-right: auto; }

/* ---------- 문제 풀기 ---------- */
.screen.quiz { align-items: flex-end; justify-content: flex-end; pointer-events: none; }
.quiz-card {
  pointer-events: auto; background: var(--paper); border-radius: 24px; width: min(560px, 100%); padding: 18px 22px 12px; display: grid; gap: 10px;
  box-shadow: 0 14px 40px rgba(0,0,0,.28); margin-bottom: 2vh;
}
.quiz-title { margin: 0; font-family: var(--display); font-size: 19px; color: var(--muted); }
.quiz-q { font-family: var(--display); font-size: 40px; text-align: center; min-height: 60px; display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px; line-height: 1.25; }
.quiz-choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.quiz-choices button {
  border: 3px solid var(--line); background: #fff; border-radius: 16px; padding: 10px 6px; min-height: 66px; font-family: var(--display); font-size: 30px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 0 var(--line);
}
.quiz-choices button:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--line); }
.quiz-choices button.wrong { border-color: var(--berry); color: #bbb; box-shadow: none; }
.quiz-choices button.right { border-color: var(--leaf); background: #e8f6ea; }
.quiz-feedback { margin: 0; min-height: 24px; text-align: center; font-family: var(--display); font-size: 19px; }
.quiz-bottom { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.energy.big { background: #f6f0e7; }
.energy.big .cells i { width: 64px; height: 18px; }
.streak { display: flex; gap: 5px; margin-right: auto; }
.streak i { width: 16px; height: 16px; border-radius: 50%; background: #eadfce; }
.streak i.on { background: var(--sky); }
.streak.full i { background: var(--sun); }
.quiz-code { margin: 0; font-size: 12px; color: var(--muted); text-align: right; }

/* 분수 */
.frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; font-size: .72em; line-height: 1.05; margin: 0 .08em; }
.frac > span:first-child { border-bottom: .09em solid currentColor; padding: 0 .12em; }
.mixed { display: inline-flex; align-items: center; gap: .06em; }

/* ---------- 결과 ---------- */
.result h2 { font-size: 34px; }
.score-line { margin: 0; font-family: var(--display); font-size: 22px; }
.score-line b { font-size: 56px; font-weight: 400; color: var(--leaf-dark); font-variant-numeric: tabular-nums; }
#resultText { margin: 0; max-width: 40ch; }
.new-best { margin: 0; color: var(--berry); font-family: var(--display); font-size: 20px; }
.records { margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; font-size: 15px; color: var(--muted); }
.records li { display: flex; justify-content: space-between; gap: 18px; font-variant-numeric: tabular-nums; }

dialog { border: 0; border-radius: 20px; padding: 22px 26px; max-width: min(520px, 92vw); color: var(--ink); font-family: var(--body); }
dialog::backdrop { background: rgba(20,30,40,.5); }
dialog h2 { margin-bottom: 8px; }
dialog ul { padding-left: 1.2em; display: grid; gap: 6px; }
.url { word-break: break-all; background: #f3ece3; border-radius: 10px; padding: 8px 12px; font-size: 15px; -webkit-user-select: all; user-select: all; }

@media (max-width: 760px), (max-height: 520px) {
  .cols { grid-template-columns: 1fr 1fr; gap: 14px; }
  .brand h1 { font-size: 34px; }
  .brand p { font-size: 14px; }
  .pick img { max-width: 80px; }
  .units { max-height: 210px; }
  .sheet { padding: 14px 16px 10px; gap: 10px; }
  .go-row .go { min-width: 150px; font-size: 22px; }
  .quiz-card { padding: 12px 16px 8px; gap: 6px; }
  .quiz-q { font-size: 32px; min-height: 46px; }
  .quiz-choices button { min-height: 52px; font-size: 26px; }
  #gate { font-size: 24px; }
  .cells i { width: 44px; }
}
@media (max-height: 520px) {
  .brand p { display: none; }
  .chars .pick { padding: 4px; }
  .chars .pick img { max-width: 54px; }
  .chars .pick b { font-size: 16px; }
  .chars .pick small { display: none; }
  .chars { gap: 6px; }
  .maps { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .map { aspect-ratio: 16 / 6; }
  .map span { font-size: 13px; }
  .units { max-height: 170px; }
  .unit { padding: 6px 10px; }
  .col h2 { font-size: 17px; }
  .go-row { position: sticky; bottom: -10px; background: rgba(255,255,255,.97); padding: 6px 0 4px; margin: 0 -4px; }
  .go-row .btn { padding: 9px 18px; }
}
@media (max-width: 560px) { .cols { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
