:root {
  color-scheme: dark;

  --bg-top: #0b0d14;
  --bg-mid: #11141d;
  --bg-bottom: #1a1f2e;
  --paper: #f3f1ec;
  --paper-soft: rgba(243, 241, 236, 0.62);
  --accent: #5fdc7a;
  --good: #5fdc7a;
  --pill-bg: rgba(22, 24, 32, 0.58);
  --pill-border: rgba(255, 255, 255, 0.1);
  --font-display: 'Inter', 'Outfit', system-ui, sans-serif;
  --font-ui-weight: 700;
  --font-body-weight: 700;
  --font-timer-weight: 900;

  --tab-bar-h: 80px;
  --ad-bar-h: var(--tab-bar-h);
  --bottom-gap: 8px;
  --bottom-margin: 6px;
}

* { box-sizing: border-box; }

html, body, #app {
  margin: 0;
  width: 100%;
  height: 100%;
  min-height: 100%;
}

html, body {
  overflow: hidden;
  font-family: var(--font-display);
  font-weight: var(--font-ui-weight);
  color: var(--paper);
  background: #05070d;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  position: fixed;
  width: 100%;
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg-top);
  height: 100%;
  height: 100dvh;
}

button { font: inherit; cursor: pointer; }
button:focus { outline: none; }
button:focus-visible {
  outline: 2px solid rgba(95, 220, 122, .5);
  outline-offset: 2px;
}
button, canvas {
  user-select: none;
  -webkit-user-select: none;
}

/* 페이지 공통 */
.page {
  position: absolute;
  inset: 0;
  display: none;
  background: linear-gradient(165deg, var(--bg-top), var(--bg-mid) 55%, var(--bg-bottom));
}

.page.active { display: block; }

.page-scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding:
    calc(env(safe-area-inset-top, 0px) + 56px)
    18px
    calc(var(--tab-bar-h) + var(--ad-bar-h) + var(--bottom-gap) + var(--bottom-margin) + 36px + env(safe-area-inset-bottom, 0px));
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.page-scroll::-webkit-scrollbar {
  display: none;
}

.page-title {
  margin: 0 0 16px;
  font-size: 13px;
  font-weight: var(--font-ui-weight);
  letter-spacing: 0.12em;
  color: var(--paper-soft);
}

.empty {
  font-size: 14px;
  font-weight: var(--font-ui-weight);
  color: var(--paper-soft);
  padding: 10px 0;
  margin: 0;
}

/* PROFILE */
.profile-card {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid var(--pill-border);
  background: var(--pill-bg);
}

.profile-avatar {
  font-size: 32px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.06);
  border-radius: 14px;
  flex-shrink: 0;
}

.profile-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
}

.profile-info b {
  font-size: 16px;
  font-weight: var(--font-ui-weight);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.profile-info span {
  font-size: 13px;
  font-weight: var(--font-ui-weight);
  color: var(--paper-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.home-best-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 28px 0;
  margin-bottom: 20px;
  border-radius: 20px;
  background: var(--pill-bg);
}

.home-best-card span {
  font-size: 11px;
  font-weight: var(--font-ui-weight);
  letter-spacing: 0.08em;
  color: var(--paper-soft);
}

.home-best-card b {
  font-size: 52px;
  font-weight: var(--font-timer-weight);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  letter-spacing: -0.02em;
  font-family: 'Inter', system-ui, sans-serif;
}

.home-section { margin-bottom: 20px; }

.home-section-title {
  font-size: 11px;
  font-weight: var(--font-ui-weight);
  letter-spacing: 0.1em;
  color: var(--paper-soft);
  margin-bottom: 8px;
}

.home-notice-card {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--pill-border);
  background: var(--pill-bg);
}

.home-notice-card strong {
  display: block;
  font-size: 14px;
  font-weight: var(--font-ui-weight);
  margin-bottom: 4px;
  color: var(--accent);
}

.home-notice-card p {
  margin: 0;
  font-size: 13px;
  font-weight: var(--font-body-weight);
  color: var(--paper-soft);
  line-height: 1.5;
}

.play-cta {
  width: 100%;
  height: 52px;
  border: 0;
  border-radius: 16px;
  background: var(--accent);
  color: #0a2011;
  font-size: 15px;
  font-weight: var(--font-ui-weight);
  letter-spacing: 0.04em;
  transition: transform .15s ease, opacity .15s ease;
}

.play-cta:active { transform: scale(.97); }

/* NUMBERS */
.numbers-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.stat-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 12px;
  border-radius: 16px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  text-align: center;
}

.stat-block span {
  font-size: 10px;
  font-weight: var(--font-ui-weight);
  letter-spacing: 0.08em;
  color: var(--paper-soft);
}

.stat-block b {
  font-size: 32px;
  font-weight: var(--font-timer-weight);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  letter-spacing: -0.02em;
  color: var(--paper);
  font-family: 'Inter', system-ui, sans-serif;
}

.stat-block em {
  font-style: normal;
  font-size: 11px;
  font-weight: var(--font-ui-weight);
  color: var(--paper-soft);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.history-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 13px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
}

.history-row .h-rank {
  font-size: 14px;
  font-weight: var(--font-ui-weight);
  color: var(--paper-soft);
  min-width: 20px;
  text-align: center;
  font-family: 'Inter', system-ui, sans-serif;
}

.history-row .h-date {
  font-size: 12px;
  font-weight: var(--font-ui-weight);
  color: var(--paper-soft);
}

.history-row .h-score {
  font-size: 16px;
  font-weight: var(--font-ui-weight);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-family: 'Inter', system-ui, sans-serif;
}

/* RANKING */
.rank-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.rank-tab {
  flex: 1;
  height: 38px;
  border: 0;
  border-radius: 12px;
  background: rgba(255,255,255,.08);
  color: var(--paper-soft);
  font-size: 13px;
  font-weight: var(--font-ui-weight);
}

.rank-tab.active {
  background: var(--accent);
  color: #0a2011;
}

.rank-list, .notices-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.rank-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 13px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
}

.rank-row strong {
  font-size: 14px;
  font-weight: var(--font-ui-weight);
  font-family: 'Inter', system-ui, sans-serif;
}

.rank-row span {
  min-width: 0;
  font-size: 13px;
  font-weight: var(--font-ui-weight);
  color: var(--paper-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rank-row b {
  font-size: 15px;
  font-weight: var(--font-ui-weight);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-family: 'Inter', system-ui, sans-serif;
}

/* EVENTS */
.notice-card {
  padding: 18px;
  border-radius: 18px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
}

.notice-card strong {
  display: block;
  font-size: 18px;
  font-weight: var(--font-ui-weight);
  line-height: 1.25;
  margin-bottom: 8px;
  color: var(--paper);
}

.notice-card p {
  margin: 0;
  font-size: 15px;
  /* Stories 본문/미리보기만 한 단계 낮은 두께로 (다른 곳의 --font-body-weight는 그대로 700 유지) */
  font-weight: 600;
  line-height: 1.55;
  color: var(--paper);
  white-space: pre-wrap;
  word-break: keep-all;
}

.notice-card time {
  display: block;
  margin-top: 10px;
  font-size: 12px;
  color: var(--paper-soft);
  opacity: .8;
}

/* PLAY
   다른 페이지 기본값과 같은 그라데이션을 사용합니다.
   #page-play와 #bg가 같은 배경을 사용해서 화면 전환 시 배경 차이가 보이지 않게 합니다. */
#page-play {
  background: linear-gradient(165deg, var(--bg-top), var(--bg-mid) 55%, var(--bg-bottom));
  overflow: hidden;
}

#bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--game-bg, linear-gradient(165deg, var(--bg-top), var(--bg-mid) 55%, var(--bg-bottom)));
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

#game {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* HUD */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: max(72px, calc(env(safe-area-inset-top, 0px) + 64px)) 0 0;
  pointer-events: none;
}

.time b {
  display: block;
  font-size: 124px;
  font-weight: var(--font-timer-weight);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  letter-spacing: -0.02em;
  text-align: center;
  font-family: 'Inter', system-ui, sans-serif;
}

.best-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.72);
  font-size: 14px;
  color: var(--paper);
}

.best-pill-icon { font-size: 14px; }

.best-pill b {
  font-size: 15px;
  font-weight: var(--font-ui-weight);
  font-variant-numeric: tabular-nums;
  font-family: 'Inter', system-ui, sans-serif;
}

/* 가이드 */
.guide {
  margin-top: 16px;
  text-align: center;
  pointer-events: none;
  transition: opacity .2s ease, visibility .2s ease;
  white-space: nowrap;
}

.guide.hidden { opacity: 0; visibility: hidden; }

.guide span {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: .06em;
  color: var(--accent);
}

/* 날씨 */
.weather-badge {
  position: absolute;
  left: 50%;
  bottom: calc(
    var(--tab-bar-h) +
    var(--ad-bar-h) +
    var(--bottom-gap) +
    var(--bottom-margin) +
    env(safe-area-inset-bottom, 0px) +
    20px
  );
  transform: translateX(-50%);
  z-index: 5;
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(10, 12, 18, 0.72);
  color: var(--paper-soft);
  font-size: 12px;
  font-weight: var(--font-ui-weight);
  white-space: nowrap;
  pointer-events: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.weather-badge[hidden] { display: none; }

.weather-status-good { color: var(--good); font-weight: var(--font-ui-weight); }
.weather-status-warn { color: #ffc94d; font-weight: var(--font-ui-weight); }
.weather-status-bad { color: #ff6b6b; font-weight: var(--font-ui-weight); }

/* 하단 고정 묶음 */
.bottom-stack {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(var(--bottom-margin) + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: var(--bottom-gap);
}

/* 광고 */
.ad-bar {
  position: relative;
  width: 100%;
  height: var(--ad-bar-h);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 20, 29, 0.96);
  border-radius: 22px;
  overflow: hidden;
}

/* 탭 바 */
.tab-bar {
  position: relative;
  width: 100%;
  height: var(--tab-bar-h);
  padding: 8px 10px;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  background: rgba(10, 11, 17, 0.96);
  border-radius: 22px;
  align-items: center;
}

.tab-btn {
  min-width: 0;
  border: 0;
  border-radius: 15px;
  background: transparent;
  color: rgba(255, 255, 255, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 100%;
  transition: color .15s ease, transform .15s ease;
}

.tab-btn:active { transform: scale(.93); }

.tab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
}

.tab-icon svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
}

.tab-label {
  font-size: 9px;
  font-weight: var(--font-ui-weight);
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  color: currentColor;
}

.tab-btn:not(.active) { color: rgba(255, 255, 255, 0.35); }

.tab-btn.active {
  color: var(--good);
  background: transparent;
}

/* 플레이 탭 */
.tab-btn-play {
  position: relative;
  transform: none;
  justify-content: center;
}

.tab-btn-play:active { transform: scale(.93); }

.tab-icon-play-wrap {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  background: rgba(20, 22, 32, 0.96);
  overflow: hidden;
  transition: border-color .15s ease;
  flex-shrink: 0;
}

.tab-btn-play.active .tab-icon-play-wrap {
  border-color: var(--good);
}

#tabPlayObjImg {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -69%);
  width: 35px;
  height: 35px;
  object-fit: contain;
  transition: opacity .2s ease;
}

.tab-btn-play .tab-label {
  position: absolute;
  bottom: 13px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 9px;
  font-weight: var(--font-ui-weight);
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.35);
  line-height: 1;
  white-space: nowrap;
}

.tab-btn-play.active .tab-label {
  color: var(--good);
}

/* 모달 공통 */
.gameover,
.pause-overlay,
.login-modal {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(8, 9, 14, .72);
  touch-action: none;
}

.pause-card,
.login-card {
  width: min(84vw, 320px);
  padding: 28px 24px 24px;
  border-radius: 28px;
  border: 1px solid var(--pill-border);
  background: #13161f;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.7);
}

.gameover-card {
  width: min(84vw, 320px);
  max-height: calc(100dvh - 36px);
  overflow-y: auto;
  padding: 28px 24px 24px;
  border-radius: 28px;
  border: 1px solid var(--pill-border);
  background: #13161f;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.7);
}

.go-label {
  font-size: 11px;
  font-weight: var(--font-ui-weight);
  letter-spacing: .12em;
  color: var(--paper-soft);
  margin: 0 0 8px;
}

.go-score {
  margin: 0;
  font-size: 56px;
  font-weight: var(--font-timer-weight);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  letter-spacing: -0.02em;
  font-family: 'Inter', system-ui, sans-serif;
}

.go-divider {
  display: none;
}

.go-grade-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 6px;
  padding: 22px 18px;
  border-radius: 20px;
  background: var(--accent);
  margin: 16px 0 8px;
}

.go-grade-icon {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: rgba(9,33,18,.12);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  overflow: hidden;
}

.go-fade {
  opacity: 0;
  transition: opacity .25s ease;
}

.go-fade-in {
  opacity: 1;
}

.go-grade-name {
  margin: 0;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .06em;
  color: #092112;
}

.go-grade-comment {
  margin: 0;
  font-size: 15px;
  font-style: italic;
  font-weight: 700;
  color: #0a2011;
  line-height: 1.35;
  max-width: 230px;
}

.go-rank-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
  gap: 8px;
  margin: 0 0 8px;
}

.go-rank-box {
  padding: 12px 8px;
  border-radius: 14px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--pill-border);
  text-align: center;
}

.go-rank-box span {
  display: block;
  font-size: 10px;
  line-height: 1.4;
  font-weight: 800;
  letter-spacing: .05em;
  color: var(--paper-soft);
  white-space: nowrap;
}

.go-rank-box b {
  display: block;
  font-size: 20px;
  font-weight: 900;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
  font-family: 'Inter', system-ui, sans-serif;
}

.go-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.go-btn-primary {
  width: 100%;
  height: 42px;
  border: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #0a2011;
  font-size: 14px;
  font-weight: var(--font-ui-weight);
  letter-spacing: .04em;
}

.go-btn-secondary {
  width: 100%;
  height: 42px;
  border: 1px solid var(--pill-border);
  border-radius: 14px;
  background: rgba(255,255,255,.06);
  color: var(--paper);
  font-size: 14px;
  font-weight: var(--font-ui-weight);
}

.pause-card h2 { margin: 0 0 8px; letter-spacing: .12em; }
.pause-card p { margin: 0; color: var(--paper-soft); font-size: 14px; font-weight: var(--font-ui-weight); }

.login-card h2 { margin: 0 0 16px; letter-spacing: .12em; }

.login-card input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border-radius: 14px;
  border: 1px solid var(--pill-border);
  background: rgba(255,255,255,.06);
  color: var(--paper);
  font-size: 15px;
  font-weight: var(--font-ui-weight);
  font-family: var(--font-display);
}

.login-error {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: var(--font-ui-weight);
  color: #ff8a8a;
  text-align: left;
}

.login-error[hidden] { display: none; }

.login-save, .login-cancel {
  width: 100%;
  height: 44px;
  margin-top: 8px;
  border: 0;
  border-radius: 14px;
  font-weight: var(--font-ui-weight);
  font-size: 14px;
  font-family: var(--font-display);
}

.login-save { background: var(--accent); color: #0a2011; }
.login-save:disabled { opacity: .6; }
.login-cancel { background: rgba(255,255,255,.08); color: var(--paper); }

.mini-btn {
  flex: 0 0 auto;
  border: 1px solid rgba(95, 220, 122, 0.45);
  border-radius: 999px;
  padding: 7px 12px;
  background: rgba(95, 220, 122, 0.12);
  color: var(--accent);
  font-size: 11px;
  font-weight: var(--font-ui-weight);
  letter-spacing: 0.04em;
}

/* 배지 토스트 */
.badge-toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: 16px;
  background: rgba(10, 12, 18, 0.92);
  border: 1px solid rgba(95, 220, 122, 0.4);
  opacity: 0;
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
}

.badge-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.badge-toast-icon { font-size: 28px; }

.badge-toast-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.badge-toast-text strong {
  font-size: 11px;
  font-weight: var(--font-ui-weight);
  letter-spacing: .06em;
  color: var(--good);
}

.badge-toast-text span {
  font-size: 14px;
  font-weight: var(--font-ui-weight);
  color: var(--paper);
}

/* 배지 목록 (Profile) */
.badges-grid {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(2, 1fr);
  grid-auto-columns: 76px;
  gap: 10px;
  margin-bottom: 20px;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  padding-bottom: 2px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.badges-grid::-webkit-scrollbar {
  display: none;
}

.badge-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 8px;
  border-radius: 14px;
  background: var(--pill-bg);
  border: 1px solid var(--pill-border);
  text-align: center;
}

.badge-item-icon { font-size: 28px; }

.badge-item-name {
  font-size: 10px;
  font-weight: var(--font-ui-weight);
  color: var(--paper-soft);
  line-height: 1.3;
}

.badge-item.locked {
  opacity: 0.3;
}

@media (min-width: 768px) {
  #app {
    max-width: 520px;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
  }
  .time b { font-size: 112px; font-weight: var(--font-timer-weight); }
}

@media (max-height: 720px) {
  .hud {
    padding-top: max(36px, calc(env(safe-area-inset-top, 0px) + 28px));
    gap: 8px;
  }
  .time b { font-size: 88px; font-weight: var(--font-timer-weight); }
}

@media (max-width: 380px) {
  .time b { font-size: 96px; font-weight: var(--font-timer-weight); }
  .gameover-card, .pause-card, .login-card {
    width: min(90vw, 300px);
    padding: 24px 20px 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
