@font-face {
  font-family: Galmuri11;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/Galmuri11.woff2') format('woff2');
}
@font-face {
  font-family: Galmuri11;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/Galmuri11-Bold.woff2') format('woff2');
}

:root {
  --ink: #1b1420;
  --paper: #fff8ec;
  --paper-2: #ffe9c7;
  --yellow: #ffd23f;
  --sky: #3fa7ff;
  --red: #ff5a4e;
  --green: #3ecf6a;
  --purple: #8e5cff;
  --pink: #ff6fa8;
  --muted: #7a6a74;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #5ec8ff;
  font-family: Galmuri11, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  image-rendering: pixelated;
}

.hidden { display: none !important; }

kbd {
  font-family: inherit;
  font-size: 0.8em;
  padding: 1px 5px;
  border: 2px solid currentColor;
  border-radius: 3px;
  opacity: 0.85;
}

/* ---------- 공통 버튼 ---------- */
button { font-family: inherit; color: inherit; cursor: pointer; }

.btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  font-size: 17px;
  font-weight: 700;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 6px;
  box-shadow: inset -3px -4px 0 rgba(0, 0, 0, 0.12), 0 4px 0 var(--ink);
  transition: transform 0.05s;
}
.btn:active, .btn.pressed { transform: translateY(3px); box-shadow: inset -3px -4px 0 rgba(0, 0, 0, 0.12), 0 1px 0 var(--ink); }
.btn:focus-visible, .icon-btn:focus-visible, .mode-card:focus-visible, .tab:focus-visible, .shop-card button:focus-visible,
.chip:focus-visible, .swatch:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 2px;
}
.btn-primary { background: var(--red); color: #fff; text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.25); }
.btn-yellow { background: var(--yellow); }
.btn-danger { background: #ffd9d6; color: #b3261e; }
.btn-big { font-size: 22px; padding: 16px; }
.btn-small { font-size: 14px; padding: 8px 12px; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  font-size: 18px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 6px;
  box-shadow: 0 3px 0 var(--ink);
}
.icon-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.pause-ico { width: 14px; height: 16px; border-left: 5px solid var(--ink); border-right: 5px solid var(--ink); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px 6px 8px;
  background: rgba(27, 20, 32, 0.75);
  color: #fff;
  border-radius: 999px;
  font-weight: 700;
  font-size: 16px;
}
.ico-coin {
  display: inline-block;
  width: 16px;
  height: 16px;
  background: var(--yellow);
  border: 2px solid #5a3a00;
  border-radius: 50%;
  box-shadow: inset -3px -2px 0 #e09a00, inset 2px 2px 0 #fff2b0;
  flex: none;
}

/* ---------- 화면 공통 ---------- */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  z-index: 10;
}
.modal {
  align-items: center;
  justify-content: center;
  background: rgba(27, 20, 32, 0.55);
  z-index: 20;
}
.panel {
  width: min(360px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--paper);
  border: 4px solid var(--ink);
  border-radius: 10px;
  box-shadow: 0 6px 0 var(--ink);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: pop 0.22s cubic-bezier(.2, 1.4, .5, 1);
  touch-action: pan-y;
}
.panel h2 { margin: 0 0 4px; text-align: center; font-size: 24px; }

@keyframes pop {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* ---------- 타이틀 ---------- */
#screen-title { justify-content: space-between; align-items: center; }
.title-top { width: 100%; display: flex; justify-content: flex-end; }
.logo-wrap { text-align: center; margin-top: -4vh; }
.logo {
  margin: 0;
  font-size: clamp(44px, 14vw, 88px);
  white-space: nowrap;
  line-height: 1;
  font-weight: 700;
  color: #fff;
  letter-spacing: 2px;
  text-shadow:
    4px 0 0 var(--ink), -4px 0 0 var(--ink), 0 4px 0 var(--ink), 0 -4px 0 var(--ink),
    4px 4px 0 var(--ink), -4px 4px 0 var(--ink), 4px -4px 0 var(--ink), -4px -4px 0 var(--ink),
    0 10px 0 var(--ink), 4px 10px 0 var(--ink), -4px 10px 0 var(--ink);
  animation: float 2.4s ease-in-out infinite;
}
.logo span { display: inline-block; }
.logo span:first-child { color: var(--yellow); }
.logo-sub {
  margin: 14px 0 0;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 8px;
  color: #fff;
  text-shadow: 2px 2px 0 var(--ink);
}
@keyframes float { 50% { transform: translateY(-8px); } }

.title-bottom {
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.title-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.title-row .btn { font-size: 14px; padding: 10px 2px; }
.btn-pink { background: var(--pink); color: #fff; text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.25); }
.key-hint {
  margin: 2px 0 0;
  text-align: center;
  font-size: 12px;
  color: #fff;
  text-shadow: 1px 1px 0 var(--ink);
}
@media (pointer: coarse) { .key-hint, .ctrl kbd { display: none; } }

.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode-card {
  position: relative;
  padding: 10px 4px 8px;
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 8px;
  box-shadow: 0 3px 0 var(--ink);
  text-align: center;
  font-weight: 700;
}
.mode-card .m-name { display: block; font-size: 15px; }
.mode-card .m-best { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); font-weight: 400; }
.mode-card.selected { background: var(--yellow); transform: translateY(-3px); box-shadow: 0 6px 0 var(--ink); }
.mode-card.locked { background: #d8d0d4; color: #7a6a74; }
.mode-card.locked .m-best { color: #7a6a74; }

/* ---------- HUD ---------- */
#hud {
  position: fixed;
  left: 0;
  right: 0;
  top: 0;
  padding: calc(10px + var(--safe-top)) 12px 0;
  z-index: 5;
  pointer-events: none;
}
#hud button { pointer-events: auto; }
.hud-top { display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; }
.hud-top .coin-pill { justify-self: start; }
.hud-top .icon-btn { justify-self: end; }
.score-wrap { text-align: center; }
#hud-score {
  font-size: clamp(44px, 12vw, 64px);
  font-weight: 700;
  line-height: 1;
  color: #fff;
  text-shadow:
    3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 3px 0 var(--ink), 0 -3px 0 var(--ink),
    3px 3px 0 var(--ink), -3px 3px 0 var(--ink), 3px -3px 0 var(--ink), -3px -3px 0 var(--ink), 0 6px 0 var(--ink);
}
.hud-sub { margin-top: 8px; font-size: 13px; font-weight: 700; color: #fff; text-shadow: 2px 2px 0 var(--ink); }

.gauge {
  position: relative;
  width: min(300px, 76vw);
  height: 22px;
  margin: 12px auto 0;
  background: rgba(27, 20, 32, 0.65);
  border: 3px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
}
#gauge-fill {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  background: linear-gradient(180deg, #8cf59e 0 35%, var(--green) 35%);
}
.gauge.mid #gauge-fill { background: linear-gradient(180deg, #ffe58a 0 35%, #ffbf1f 35%); }
.gauge.low #gauge-fill { background: linear-gradient(180deg, #ff9e95 0 35%, var(--red) 35%); }
.gauge.low { animation: warn 0.4s steps(2) infinite; }
.gauge.fever #gauge-fill { background: linear-gradient(90deg, #ff6fa8, #ffd23f, #3ecf6a, #3fa7ff, #8e5cff); background-size: 200% 100%; animation: rainbow 0.6s linear infinite; }
@keyframes warn { 50% { border-color: var(--red); } }
@keyframes rainbow { to { background-position: 200% 0; } }
#gauge-label {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  text-shadow: 1px 1px 0 var(--ink);
}

#fever-badge {
  width: max-content;
  margin: 10px auto 0;
  padding: 4px 12px;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(90deg, var(--pink), var(--purple));
  border: 3px solid var(--ink);
  border-radius: 6px;
  animation: float 0.5s ease-in-out infinite;
}
#combo {
  margin: 8px auto 0;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--yellow);
  text-shadow: 2px 2px 0 var(--ink);
}

/* ---------- 조작 버튼 ---------- */
#controls {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 12px calc(14px + var(--safe-bottom));
  z-index: 6;
}
.ctrl {
  height: clamp(84px, 15vh, 120px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-weight: 700;
  color: #fff;
  border: 4px solid var(--ink);
  border-radius: 14px;
  box-shadow: inset -4px -6px 0 rgba(0, 0, 0, 0.18), 0 6px 0 var(--ink);
  touch-action: none;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.3);
}
.ctrl-turn { background: var(--purple); }
.ctrl-climb { background: var(--sky); }
.ctrl.pressed { transform: translateY(4px); box-shadow: inset -4px -6px 0 rgba(0, 0, 0, 0.18), 0 2px 0 var(--ink); filter: brightness(1.12); }
.ctrl-ico { font-size: 30px; line-height: 1; }
.ctrl-txt { font-size: 17px; }
.ctrl kbd { margin-top: 2px; font-size: 11px; }
@media (min-width: 720px) {
  #controls { left: 50%; right: auto; width: 520px; transform: translateX(-50%); }
}

/* ---------- 배너 & 토스트 ---------- */
#banner {
  position: fixed;
  left: 50%;
  top: 34%;
  transform: translate(-50%, -50%);
  padding: 10px 22px;
  font-size: clamp(22px, 7vw, 32px);
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  background: rgba(27, 20, 32, 0.8);
  border: 3px solid #fff;
  border-radius: 8px;
  z-index: 7;
  pointer-events: none;
  animation: banner 1.6s forwards;
}
#banner small { display: block; text-align: center; font-size: 0.5em; color: var(--yellow); }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  20% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -70%); }
}
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(30px + var(--safe-bottom));
  transform: translateX(-50%);
  padding: 10px 18px;
  background: var(--ink);
  color: #fff;
  border-radius: 8px;
  font-weight: 700;
  z-index: 50;
  white-space: nowrap;
  animation: pop 0.2s;
}

/* ---------- 튜토리얼 ---------- */
#tutorial {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  padding-bottom: calc(150px + var(--safe-bottom));
  z-index: 4;
  pointer-events: none;
}
.tut-card {
  width: min(340px, 100%);
  padding: 16px;
  background: rgba(255, 248, 236, 0.95);
  border: 4px solid var(--ink);
  border-radius: 10px;
  box-shadow: 0 5px 0 var(--ink);
}
.tut-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.tut-row p { margin: 0; font-size: 14px; line-height: 1.4; }
.tut-btn {
  flex: none;
  width: 76px;
  height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  border: 3px solid var(--ink);
  border-radius: 8px;
}
.tut-btn small { font-size: 11px; }
.tut-btn.turn { background: var(--purple); }
.tut-btn.climb { background: var(--sky); }
.tut-note { margin: 4px 0 8px; font-size: 13px; line-height: 1.5; text-align: center; }
.tut-go { margin: 0; text-align: center; font-weight: 700; color: var(--red); }
.blink { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0.2; } }

/* ---------- 게임 오버 ---------- */
.over-title { font-size: 34px !important; color: var(--red); text-shadow: 3px 3px 0 var(--ink); }
.over-reason { margin: -8px 0 0; text-align: center; color: var(--muted); font-size: 14px; }
.over-score { display: flex; flex-direction: column; align-items: center; }
.over-score .label { font-size: 14px; color: var(--muted); }
.big-num { font-size: 60px; font-weight: 700; line-height: 1.1; }
.record {
  margin: -6px auto 0;
  padding: 4px 12px;
  font-weight: 700;
  color: #fff;
  background: var(--red);
  border: 3px solid var(--ink);
  border-radius: 6px;
  animation: float 0.6s ease-in-out infinite;
}
.over-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.over-stats div {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px;
  background: var(--paper-2);
  border: 2px solid var(--ink);
  border-radius: 6px;
}
.over-stats span { font-size: 12px; color: var(--muted); }
.over-stats b { font-size: 18px; }
.over-reward {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 22px;
  font-weight: 700;
}
.over-btns { display: grid; gap: 10px; }
.over-btns .btn:disabled { opacity: 0.6; }

/* ---------- 상점 ---------- */
#screen-shop { background: var(--paper); gap: 12px; }
.shop-head { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; }
.shop-head h2 { margin: 0; font-size: 22px; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tab {
  padding: 10px;
  font-size: 16px;
  font-weight: 700;
  background: #efe3d0;
  border: 3px solid var(--ink);
  border-radius: 8px;
}
.tab.active { background: var(--yellow); }
.shop-grid {
  flex: 1;
  overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  align-content: start;
  padding: 4px 2px 12px;
  touch-action: pan-y;
}
.shop-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 10px;
  box-shadow: 0 4px 0 var(--ink);
}
.shop-card.equipped { background: #e9fbe9; }
.shop-card .preview {
  width: 100%;
  height: 96px;
  display: grid;
  place-items: center;
  background: linear-gradient(#bfe6ff, #e8f7ff);
  border: 2px solid var(--ink);
  border-radius: 6px;
}
.shop-card .preview canvas { image-rendering: pixelated; }
.shop-card .name { font-weight: 700; font-size: 15px; text-align: center; }
.shop-card .desc { font-size: 11px; color: var(--muted); text-align: center; min-height: 2.6em; line-height: 1.3; }
.shop-card button {
  width: 100%;
  padding: 7px;
  font-weight: 700;
  font-size: 14px;
  border: 3px solid var(--ink);
  border-radius: 6px;
  background: var(--yellow);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.shop-card button.use { background: var(--sky); color: #fff; }
.shop-card button.on { background: var(--green); color: #fff; cursor: default; }
.shop-card button.cant { background: #e3dade; color: #8a7a84; }
.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.shop-card .btn-pair { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.shop-card button.edit { background: var(--pink); color: #fff; }
.shop-card.custom-card { border-color: var(--pink); }

/* ---------- 이름표 ---------- */
.nametag {
  display: inline-block;
  max-width: 100%;
  padding: 2px 8px;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: rgba(27, 20, 32, 0.8);
  border-radius: 4px;
}
.over-name { margin: -10px 0 0; text-align: center; font-weight: 700; color: var(--ink); }

/* ---------- 캐릭터 꾸미기 ---------- */
#screen-custom { background: var(--paper); gap: 10px; }
.custom-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 2px 2px 8px;
  touch-action: pan-y;
}
.custom-preview {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 0 10px;
  background: linear-gradient(#7fd0ff, #d6f3ff 70%, #7ed957 70%, #5bbf4a);
  border: 3px solid var(--ink);
  border-radius: 10px;
}
.custom-preview canvas { image-rendering: pixelated; width: 108px; height: 144px; }
.name-field {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  font-weight: 700;
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 8px;
}
.name-field input {
  min-width: 0;
  padding: 6px 4px;
  font: inherit;
  font-size: 17px;
  color: var(--ink);
  border: none;
  border-bottom: 2px dashed #c9bcc4;
  outline: none;
  background: transparent;
  -webkit-user-select: text;
  user-select: text;
  touch-action: manipulation;
}
.name-field input:focus { border-bottom-color: var(--sky); }
.name-field small { font-size: 12px; color: var(--muted); font-weight: 400; }
.custom-options { display: flex; flex-direction: column; gap: 10px; }
.opt-row { display: flex; flex-direction: column; gap: 6px; }
.opt-row h3 { margin: 0; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 10px;
  font-size: 13px;
  font-weight: 700;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 6px;
}
.chip[aria-pressed='true'] { background: var(--yellow); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.15); }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 30px;
  height: 30px;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 6px;
}
.swatch[aria-pressed='true'] { outline: 3px solid var(--ink); outline-offset: 2px; transform: scale(1.08); }

/* ---------- 설정 ---------- */
.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-weight: 700;
  background: var(--paper-2);
  border: 3px solid var(--ink);
  border-radius: 8px;
  cursor: pointer;
}
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i {
  position: relative;
  width: 52px;
  height: 28px;
  background: #c9bcc4;
  border: 3px solid var(--ink);
  border-radius: 6px;
}
.toggle i::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 3px;
  transition: left 0.12s;
}
.toggle input:checked + i { background: var(--green); }
.toggle input:checked + i::after { left: 26px; }
.toggle input:focus-visible + i { outline: 3px solid var(--sky); }
.stats { font-size: 13px; color: var(--muted); line-height: 1.7; text-align: center; }

.help-list { margin: 0; padding-left: 18px; font-size: 14px; line-height: 1.6; }
.help-list li { margin-bottom: 4px; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; background: #fff; }

@media (prefers-reduced-motion: reduce) {
  .logo, #fever-badge, .record, .blink, .gauge.low { animation: none; }
}
@media (max-height: 600px) {
  .logo { font-size: 48px; }
  .logo-wrap { margin-top: 0; }
  .btn-big { padding: 10px; font-size: 18px; }
  .ctrl { height: 72px; }
}
