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

:root {
  --night: #0e1a31;
  --night-2: #172844;
  --night-3: #22355e;
  --ink: #f7ecd8;
  --ink-dim: #aebbd6;
  --ember: #ff9a3c;
  --ember-hi: #ffcf6a;
  --ember-lo: #c4513b;
  --edge: #070d1a;
  --panel: rgba(12, 21, 40, 0.92);
  --px: 3px;
  --font: 'Galmuri11', 'Apple SD Gothic Neo', 'Malgun Gothic', 'Noto Sans KR', sans-serif;
  /* notched pixel border, NES-style */
  --pixel-border:
    0 calc(var(--px) * -1) 0 0 var(--edge),
    0 var(--px) 0 0 var(--edge),
    calc(var(--px) * -1) 0 0 0 var(--edge),
    var(--px) 0 0 0 var(--edge);
  color-scheme: dark;
}

[hidden] { display: none !important; }

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--night);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

body {
  position: fixed;
  inset: 0;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

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

h1, h2, p { margin: 0; }
b { font-weight: normal; }

.dim { color: var(--ink-dim); }

.kicker {
  color: var(--ember-hi);
  font-size: 12px;
  letter-spacing: 0.12em;
}

/* ---------- surfaces & controls ---------- */

.panel {
  background: var(--panel);
  box-shadow: var(--pixel-border), inset 0 var(--px) 0 0 rgba(255, 255, 255, 0.06);
  margin: var(--px);
}

.btn {
  font: inherit;
  font-size: 15px;
  line-height: 1.2;
  color: var(--ink);
  background: #2a3f6b;
  border: 0;
  border-radius: 0;
  padding: 13px 16px 15px;
  min-height: 48px;
  margin: var(--px);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-shadow: var(--pixel-border),
    inset 0 -4px 0 0 rgba(0, 0, 0, 0.28),
    inset 0 3px 0 0 rgba(255, 255, 255, 0.12);
  touch-action: manipulation;
  transition: transform 80ms ease-out, filter 120ms ease-out;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(2px); box-shadow: var(--pixel-border), inset 0 -2px 0 0 rgba(0, 0, 0, 0.28); }
.btn:disabled { filter: saturate(0.4) brightness(0.85); cursor: progress; }
.btn-primary {
  background: var(--ember);
  color: #2b1306;
}
.btn-big {
  font-size: 18px;
  min-width: 220px;
  min-height: 56px;
}
.btn:focus-visible, .link:focus-visible, .icon-btn:focus-visible {
  outline: 3px solid var(--ember-hi);
  outline-offset: 5px;
}

.link {
  font: inherit;
  font-size: 13px;
  color: var(--ink-dim);
  background: none;
  border: 0;
  padding: 10px 6px;
  min-height: 40px;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 2px;
  text-decoration-color: rgba(174, 187, 214, 0.4);
}
.link:hover { color: var(--ink); }

.row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
}
.row .btn { flex: 1 1 0; min-width: 0; }

.icon-btn {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  z-index: 30;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  margin: var(--px);
  border: 0;
  color: var(--ink);
  background: rgba(10, 18, 34, 0.6);
  box-shadow: var(--pixel-border);
  cursor: pointer;
}
.icon-btn[aria-pressed="false"] { color: var(--ink-dim); }
.icon-btn[aria-pressed="false"] .on,
.icon-btn[aria-pressed="true"] .off { display: none; }

/* ---------- screens ---------- */

.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
           max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.screen-title {
  justify-content: space-between;
  gap: 16px;
  background: linear-gradient(to bottom, rgba(14, 26, 49, 0.62), rgba(14, 26, 49, 0) 42%,
              rgba(14, 26, 49, 0) 58%, rgba(9, 16, 31, 0.7));
}

.title-card {
  width: 100%;
  max-width: 420px;
  text-align: center;
  padding-top: clamp(8px, 5vh, 56px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.logo {
  font-size: 48px;
  line-height: 1.05;
  font-weight: normal;
  color: #fff1d6;
  letter-spacing: 0.02em;
  text-shadow:
    3px 0 0 var(--edge), -3px 0 0 var(--edge), 0 3px 0 var(--edge), 0 -3px 0 var(--edge),
    3px 3px 0 var(--edge), -3px 3px 0 var(--edge), 3px -3px 0 var(--edge), -3px -3px 0 var(--edge),
    0 7px 0 #7b2c1f, 3px 7px 0 #7b2c1f, -3px 7px 0 #7b2c1f;
}
.logo-small {
  display: block;
  font-size: 24px;
  color: var(--ember-hi);
  margin-bottom: 6px;
}

.howto {
  font-size: 14px;
  color: var(--ink);
  background: rgba(10, 18, 34, 0.55);
  padding: 7px 12px;
  text-wrap: balance;
}

.me-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 2px 8px;
  font-size: 13px;
  color: var(--ink-dim);
  text-shadow: 0 2px 0 var(--edge);
}
.me-line:empty { display: none; }

.board {
  width: 100%;
  max-width: 420px;
  padding: 14px 16px 10px;
}
.board h2 {
  font-size: 15px;
  font-weight: normal;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.board h2 .dim { font-size: 12px; }

.rank-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}
.rank-list li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 4px;
  border-top: 2px dashed rgba(174, 187, 214, 0.14);
}
.rank-list li:first-child { border-top: 0; }
.rank-list .rk { text-align: center; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.rank-list li:nth-child(1) .rk { color: #ffcf5a; }
.rank-list li:nth-child(2) .rk { color: #d5dff0; }
.rank-list li:nth-child(3) .rk { color: #e4a272; }
.rank-list .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-list .sc { color: var(--ember-hi); font-variant-numeric: tabular-nums; }
.rank-list li.me { background: rgba(255, 154, 60, 0.14); }
.rank-list li.me .nm::after { content: ' (나)'; color: var(--ember-hi); }
.rank-list li.empty {
  display: block;
  text-align: center;
  color: var(--ink-dim);
  padding: 14px 4px 12px;
  border: 0;
}

/* ---------- HUD ---------- */

.hud {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: 64px;
  right: 64px;
  z-index: 5;
  text-align: center;
  pointer-events: none;
}
.hud-floor {
  font-size: 48px;
  line-height: 1;
  color: #fff6e6;
  text-shadow:
    3px 0 0 var(--edge), -3px 0 0 var(--edge), 0 3px 0 var(--edge), 0 -3px 0 var(--edge),
    3px 3px 0 var(--edge), -3px 3px 0 var(--edge), 3px -3px 0 var(--edge), -3px -3px 0 var(--edge);
  font-variant-numeric: tabular-nums;
}
.hud-floor small { font-size: 18px; margin-left: 4px; }
.hud-floor.pop { animation: pop 200ms ease-out; }
.hud-sub {
  margin-top: 8px;
  min-height: 1.4em;
  font-size: 13px;
  color: var(--ink-dim);
  text-shadow: 0 2px 0 var(--edge);
}
.hud-sub.combo { color: var(--ember-hi); }

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ---------- result ---------- */

.screen-result {
  justify-content: flex-end;
  background: linear-gradient(to bottom, rgba(9, 16, 31, 0) 40%, rgba(9, 16, 31, 0.55));
}

.sheet {
  width: 100%;
  max-width: 440px;
  padding: 18px 16px 8px;
  text-align: center;
  animation: sheet-in 380ms cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}
@keyframes sheet-in {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

.res-floors {
  font-size: 72px;
  font-weight: normal;
  line-height: 1;
  margin-top: 6px;
  color: #fff1d6;
  font-variant-numeric: tabular-nums;
  text-shadow:
    3px 0 0 var(--edge), -3px 0 0 var(--edge), 0 3px 0 var(--edge), 0 -3px 0 var(--edge),
    3px 3px 0 var(--edge), -3px 3px 0 var(--edge), 3px -3px 0 var(--edge), -3px -3px 0 var(--edge);
}
.res-floors small { font-size: 24px; margin-left: 6px; color: var(--ember-hi); }

.res-best {
  min-height: 1.4em;
  margin-top: 8px;
  font-size: 13px;
  color: var(--ink-dim);
}
.res-best .new { color: var(--ember-hi); }

.stats {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding: 0;
  margin: 12px 0 0;
}
.stats li {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 9px 4px 8px;
  background: rgba(255, 255, 255, 0.05);
}
.stats span { font-size: 12px; color: var(--ink-dim); }
.stats b { font-size: 18px; font-variant-numeric: tabular-nums; }

.res-rank {
  min-height: 48px;
  margin-top: 10px;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 4px 10px;
  font-size: 14px;
  background: rgba(255, 154, 60, 0.08);
}
.res-rank .big { color: var(--ember-hi); font-size: 18px; }
.res-rank .err { color: #ffb4a0; }
.res-rank .btn { min-height: 40px; padding: 9px 12px 11px; font-size: 13px; }

.sheet .row { flex-wrap: nowrap; }
#btn-again { flex: 0 0 30%; }
#btn-share { flex: 1 1 auto; font-size: 14px; padding-left: 10px; padding-right: 10px; white-space: nowrap; }

/* ---------- pause, modal, toast ---------- */

.pause {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(7, 13, 26, 0.6);
  text-align: center;
  font-size: 24px;
}
.pause small {
  display: block;
  margin-top: 10px;
  font-size: 14px;
  color: var(--ink-dim);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(5, 9, 18, 0.74);
  overflow-y: auto;
}
.modal-card {
  width: 100%;
  max-width: 380px;
  padding: 20px 16px 14px;
  text-align: center;
}
.modal-card h2 { font-size: 18px; font-weight: normal; }
.modal-card .dim { font-size: 13px; margin-top: 8px; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 14px;
  text-align: left;
  font-size: 12px;
  color: var(--ink-dim);
}
.field input {
  font: inherit;
  font-size: 18px;
  color: var(--ink);
  background: #0a1324;
  border: 0;
  border-radius: 0;
  padding: 12px;
  margin: var(--px);
  box-shadow: var(--pixel-border), inset 0 3px 0 0 rgba(0, 0, 0, 0.35);
  -webkit-user-select: text;
  user-select: text;
}
.field input:focus { outline: 3px solid var(--ember-hi); outline-offset: 4px; }
.error { min-height: 1.4em; margin-top: 8px; font-size: 13px; color: #ffb4a0; }

.share-card { max-width: 420px; }
.share-card img {
  display: block;
  width: 100%;
  max-height: 56vh;
  object-fit: contain;
  margin: 12px 0 6px;
  background: #070d1a;
  -webkit-user-select: auto;
  user-select: auto;
  -webkit-touch-callout: default;
}
.hint { font-size: 12px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 50;
  max-width: calc(100vw - 32px);
  transform: translate(-50%, 12px);
  padding: 10px 14px;
  background: rgba(10, 18, 34, 0.94);
  box-shadow: var(--pixel-border);
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease-out, transform 180ms ease-out;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .title-card { padding-top: clamp(16px, 7vh, 72px); }
}

@media (max-width: 359px) {
  .logo { font-size: 40px; }
  #btn-share { font-size: 12px; white-space: normal; }
  .stats b { font-size: 15px; }
}

@media (max-height: 640px) {
  .logo { font-size: 36px; }
  .logo-small { font-size: 18px; }
  .title-card { gap: 10px; padding-top: 4px; }
  .res-floors { font-size: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  .sheet, .hud-floor.pop { animation: none; }
  .btn, .toast { transition: none; }
}
