@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;700;900&display=swap');

@import url('https://cdn.jsdelivr.net/npm/galmuri@latest/dist/galmuri.css');

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background: #1a1a2e;
  font-family: 'Noto Sans KR', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  color: #fff;
}

#game-wrap {
  width: 100%;
  max-width: 420px;
  max-height: 100vh;
  max-height: 100dvh;
  aspect-ratio: 420 / 640;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 12px;
}

@media (max-aspect-ratio: 420/640) {
  #game-wrap {
    max-width: none;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    aspect-ratio: auto;
  }
}

/* ── HUD ── */
#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2;
  pointer-events: none;
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.5);
  padding: 6px 10px;
  font-family: 'Galmuri11', monospace;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  pointer-events: auto;
  color: #fff;
  font-size: 14px;
}

#score-display,
#level-display {
  font-weight: bold;
}

.hud-label {
  font-size: 10px;
  color: #aaa;
  letter-spacing: 1px;
}

#pause-btn {
  background: none;
  border: none;
  color: #888;
  font-family: 'Galmuri11', monospace;
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  display: flex;
  align-items: center;
}

#pause-btn:active {
  color: #fff;
}

/* ── Overlays ── */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 10;
  background: rgba(10, 10, 30, 0.78);
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow-y: auto;
  padding: 20px 0;
}

.overlay[hidden] {
  display: none !important;
}

.overlay h1 {
  font-size: 26px;
  font-weight: 900;
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}

.overlay p {
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
}

.overlay .sub {
  color: rgba(255, 255, 255, 0.45);
  font-size: 11px;
  margin-top: 4px;
}

.big-score {
  font-size: 52px;
  font-weight: 900;
  margin: 10px 0 2px;
  color: #f0c040;
}

.best-line {
  color: #f0c040;
  font-size: 13px;
  opacity: 0.8;
}

/* ── Title Screen ── */
#title-screen {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  justify-content: space-between;
  padding: 90px 0 60px;
}

.title-top {
  text-align: center;
}

.title-logo {
  font-family: 'Galmuri11', monospace;
  font-size: 72px;
  font-weight: 900;
  color: #fff;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.5);
  letter-spacing: -1px;
}

.title-sub {
  font-family: 'Galmuri11', monospace;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 4px;
  margin-top: 4px;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
}

.press-key {
  font-family: 'Galmuri11', monospace;
  font-size: 18px;
  color: #f0c040;
  font-weight: bold;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.6);
  animation: blink 2s ease-in-out infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Buttons ── */
.btn {
  margin-top: 16px;
  padding: 11px 36px;
  border: none;
  border-radius: 50px;
  background: #fff;
  color: #1a1a2e;
  font-size: 15px;
  font-weight: 700;
  font-family: 'Noto Sans KR', sans-serif;
  cursor: pointer;
  transition: transform 0.1s;
  width: 200px;
  text-align: center;
}

.btn:active {
  transform: scale(0.95);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  margin-top: 10px;
  padding: 11px 36px;
  font-size: 15px;
}

/* ── Name Input ── */
.name-input {
  margin-top: 14px;
  padding: 10px 16px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 50px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-size: 15px;
  font-family: 'Noto Sans KR', sans-serif;
  text-align: center;
  width: 200px;
  outline: none;
  transition: border-color 0.2s;
}

.name-input::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

.name-input:focus {
  border-color: #f0c040;
}

/* ── Character Select ── */
.char-section {
  margin-top: 14px;
  text-align: center;
}

.char-label {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
  margin-bottom: 8px;
}

.char-grid {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.char-card {
  width: 80px;
  height: 110px;
  border-radius: 12px;
  cursor: pointer;
  border: 3px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
  padding: 6px;
}

.char-card:hover {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.1);
}

.char-card.selected {
  border-color: #f0c040;
  background: rgba(240, 192, 64, 0.15);
  box-shadow: 0 0 16px rgba(240, 192, 64, 0.3);
}

.char-card img {
  width: 52px;
  height: 52px;
  object-fit: contain;
  image-rendering: pixelated;
}

.char-card .char-name {
  font-size: 11px;
  font-weight: 700;
  margin-top: 6px;
  color: rgba(255, 255, 255, 0.7);
}

.char-card.selected .char-name {
  color: #f0c040;
}

.char-card .check {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #f0c040;
  display: none;
  align-items: center;
  justify-content: center;
}

.char-card.selected .check {
  display: flex;
}

/* ── Leaderboard ── */
.lb-title {
  font-size: 14px;
  font-weight: 700;
  color: #f0c040;
  margin: 18px 0 8px;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.lb-list {
  width: 240px;
  max-height: 150px;
  overflow-y: auto;
}

.lb-row {
  display: flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  gap: 8px;
}

.lb-row:nth-child(odd) {
  background: rgba(255, 255, 255, 0.05);
}

.lb-rank {
  font-weight: 700;
  width: 22px;
  text-align: center;
  color: rgba(255, 255, 255, 0.5);
}

.lb-rank.gold { color: #f0c040; }
.lb-rank.silver { color: #c0c0c0; }
.lb-rank.bronze { color: #cd7f32; }

.lb-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-weight: 700;
  color: #f0c040;
}

.lb-me {
  background: rgba(240, 192, 64, 0.15) !important;
}


/* ── Help Screen ── */
#help-screen {
  padding: 24px 16px;
  gap: 0;
}

.help-section {
  width: 100%;
  max-width: 300px;
  margin-top: 14px;
}

.help-section-title {
  font-size: 14px;
  font-weight: 700;
  color: #f0c040;
  margin-bottom: 8px;
  letter-spacing: 1px;
}

.help-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.help-control-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.8);
}

.help-key {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  min-width: 60px;
  text-align: center;
}

.help-item-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
}

.help-item-row .img-wrap {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.help-item-row img {
  image-rendering: pixelated;
  object-fit: contain;
  display: block;
}
.help-item-row img[alt="빵조각"]  { width: 26px; height: 26px; }
.help-item-row img[alt="하트"]    { width: 28px; height: 28px; }
.help-item-row img[alt="호루라기"] { width: 26px; height: 26px; }
.help-item-row img[alt="운동화"]  { width: 30px; height: 30px; }
.help-item-row img[alt="페인트"]  { width: 26px; height: 26px; }
.help-item-row img[alt="알람시계"] { width: 32px; height: 32px; }

.help-item-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.help-item-name {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.help-item-desc {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
}

.help-warn-tag {
  font-size: 10px;
  color: #E24B4A;
  font-weight: 700;
}

.help-item-row.help-warn {
  background: rgba(226, 75, 74, 0.08);
}

/* ── Mobile D-Pad ── */
#dpad {
  display: none;
  position: absolute;
  bottom: 18px;
  left: 12px;
  right: 12px;
  z-index: 5;
  justify-content: space-between;
  pointer-events: none;
}

#dpad.visible {
  display: flex;
}

.dpad-btn {
  pointer-events: auto;
  width: 56px;
  height: 56px;
  border: none;
  background: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.6;
}

.dpad-btn img {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.dpad-btn.pressed {
  opacity: 1;
  transform: scale(0.9);
}

/* ── Responsive ── */
@media (max-height: 660px) {
  .overlay h1 { font-size: 20px; }
  .big-score { font-size: 40px; }
  .lb-list { max-height: 100px; }
  .char-card { width: 70px; height: 95px; }
  .char-card img { width: 44px; height: 44px; }
}
