:root {
  --bg: #101828;
  --panel: #18233a;
  --text: #f2f5fa;
  --muted: #9aa7bd;
  --accent: #2dd4bf;
  --hud-h: 52px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#hud {
  width: min(100vw, calc((100dvh - var(--hud-h)) * 360 / 640));
  height: var(--hud-h);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 0 10px;
}

.hud-item { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.hud-item .label { font-size: 11px; color: var(--muted); }
.hud-item b { font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#hud-lives { color: var(--accent); letter-spacing: 0; }

#mute {
  background: none;
  border: 0;
  font-size: 20px;
  padding: 6px;
  cursor: pointer;
}

#stage {
  position: relative;
  width: min(100vw, calc((100dvh - var(--hud-h)) * 360 / 640));
  aspect-ratio: 360 / 640;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  border-radius: 10px;
}

#practice-tag {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: var(--muted);
  background: rgba(16, 24, 40, 0.8);
  padding: 3px 10px;
  border-radius: 999px;
  pointer-events: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px 24px;
  text-align: center;
  background: rgba(16, 24, 40, 0.93);
  border-radius: 10px;
}

.overlay[hidden], #practice-tag[hidden] { display: none; }

h1 { font-size: 34px; margin: 0; letter-spacing: -0.5px; }
h2 { font-size: 22px; margin: 0; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }

.rules {
  list-style: none;
  margin: 8px 0 10px;
  padding: 14px 16px;
  background: var(--panel);
  border-radius: 12px;
  text-align: left;
  font-size: 14px;
  line-height: 1.5;
  display: grid;
  gap: 6px;
}
.rules b { color: var(--accent); }

button.primary, button.ghost {
  width: 100%;
  max-width: 280px;
  min-height: 50px;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
button.primary { background: var(--accent); color: #06231f; border: 0; }
button.ghost { background: none; color: var(--muted); border: 1px solid #33415a; font-size: 14px; font-weight: 500; min-height: 44px; }
button:active { transform: translateY(1px); }

.hint { margin: 0; min-height: 18px; font-size: 13px; color: var(--muted); }
.score { margin: 0; }
.score b { font-size: 52px; font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.score span { font-size: 18px; color: var(--muted); margin-left: 4px; }
.rows { margin: 0; font-size: 24px; letter-spacing: 2px; }
.meta { margin: 0 0 6px; font-size: 14px; color: var(--muted); line-height: 1.6; }
.next { margin: 8px 0 0; font-size: 14px; color: var(--muted); }
.next b { color: var(--text); font-variant-numeric: tabular-nums; }

button.link {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 13px;
  font-family: inherit;
  text-decoration: underline;
  padding: 10px;
  cursor: pointer;
}
.meta b { color: #fbbf24; font-weight: 700; }

/* ---- 오늘의 사다리: 화면은 위쪽 캔버스 + 아래쪽 조작 버튼 ---- */
#stage { display: flex; flex-direction: column; }
#game { height: auto; aspect-ratio: 360 / 460; flex: none; }

#pad {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 8px;
  padding: 0 14px 0 0;
  touch-action: none;
}

/* 조이스틱: 왼쪽 영역 어디를 눌러도 되고, 손가락은 밖으로 끌고 나가도 계속 따라온다 */
#stick {
  flex: 0 0 62%;
  min-height: 0;
  position: relative;
  touch-action: none;
  cursor: pointer;
}
#stick-svg { position: absolute; left: 12.5%; top: 12.5%; width: 75%; height: 75%; overflow: visible; pointer-events: none; }
#stick .seg { fill: #2a3955; stroke: var(--bg); stroke-width: 3; }
#stick .seg.on { fill: #3f5580; }
#stick .arrow { fill: #eef2f8; stroke: #eef2f8; stroke-width: 4; stroke-linejoin: round; }
#stick .hole { fill: #0a101d; }
#stick .neck { fill: #26334d; }
#stick .knob { fill: #a9b4c6; stroke: #0a101d; stroke-width: 3; }
#stick.held .knob { fill: #c8d1e0; }

#pad #k-jump {
  align-self: center;
  height: min(70%, 118px);
  aspect-ratio: 1;
  flex: none;
  margin-right: 6px;
  padding: 0;
  border: 4px solid #0f766e;
  border-radius: 50%;
  background: var(--accent);
  color: #06231f;
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 0.5px;
  touch-action: none;
  cursor: pointer;
}
#pad #k-jump.on { background: #5eead4; transform: scale(0.95); }
.rules { font-size: 13px; }

/* ---- 설치 창, 안내 말풍선 ---- */
.overlay { overflow-y: auto; justify-content: safe center; }
.install-btn[hidden], #install[hidden], #toast[hidden] { display: none; }
#install { position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 24px; background: rgba(5, 9, 18, 0.82); }
#install .box { width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 22px 20px 12px; background: var(--panel); border-radius: 18px; text-align: center; }
#install img { border-radius: 16px; }
#install p { margin: 0 0 4px; font-size: 14px; line-height: 1.7; color: var(--muted); white-space: pre-line; }
#toast { position: fixed; z-index: 20; left: 50%; bottom: 24px; transform: translateX(-50%); white-space: nowrap; padding: 10px 16px; border-radius: 999px; background: #f2f5fa; color: #101828; font-size: 14px; pointer-events: none; }

/* ---- 넓은 화면(갤럭시 Z Fold 펼침, 태블릿, 가로 모드, PC): 게임판을 크게, 조작은 양옆 ----
   접거나 펴면 화면 비율이 바뀌어 자동으로 전환된다. */
@media (min-aspect-ratio: 3/4) {
  :root {
    /* 게임판 너비: 위아래를 꽉 채우되, 양옆에 조작 자리(각 120px 이상)를 남긴다 */
    --board: min(calc(100vw - 240px), calc((100dvh - var(--hud-h) - 8px) * 360 / 460));
    --side: calc((100vw - var(--board)) / 2);
    /* 조이스틱·점프 중심의 높이(화면 아래에서). 값이 작을수록 아래로 내려간다 */
    --ctl-y: max(80px, 14dvh);
    --stick-size: min(calc(var(--side) * 0.92), 150px);
  }
  #hud { width: max(var(--board), min(100vw, 340px)); }
  #stage { display: block; width: 100vw; height: calc(100dvh - var(--hud-h)); aspect-ratio: auto; }
  #game { width: var(--board); margin: 0 auto; }
  #pad { position: absolute; inset: 0; padding: 0; pointer-events: none; }
  #stick { position: absolute; left: 0; bottom: 0; width: var(--side); height: 66%; pointer-events: auto; }
  #stick-svg { left: 4%; width: 92%; top: auto; height: var(--stick-size); bottom: max(14px, calc(var(--ctl-y) - var(--stick-size) / 2)); }
  #pad #k-jump {
    position: absolute;
    --size: min(calc(var(--side) * 0.82), 150px);
    width: var(--size);
    height: var(--size);
    right: calc((var(--side) - var(--size)) / 2);
    bottom: max(14px, calc(var(--ctl-y) - var(--size) / 2));
    margin: 0;
    pointer-events: auto;
  }
  .overlay > * { flex-shrink: 0; }
  .rules { max-width: 440px; }
}

/* v1.0-③ 오늘의 별 */
.goals { white-space: pre-line; margin: 0; font-size: 13px; color: #cbd5e1; text-align: center; line-height: 1.6; }

/* language switch: visible pill in the top-right corner of the start screen */
#start { position: absolute; }
#lang {
  position: absolute; top: 10px; right: 10px;
  text-decoration: none; font-weight: 700; color: #e2e8f0;
  border: 1px solid #475569; border-radius: 999px; padding: 6px 12px; background: rgba(30, 41, 59, 0.9);
}
