/* 눈을 굴려라 - 픽셀 아트 스타일, 화면 전체 사용 */

:root {
  --ink: #15386b;
  --ink-soft: #2868ac;
  --panel: #69c6f2;
  --panel-deep: #245890;
  --panel-light: #adf0ff;
  --sky: #c3f2ff;
  --accent: #ffdb56;
  --accent-deep: #cfa000;
  --good: #63e6a6;
  --bad: #ff9090;
  --text: #ffffff;
  --muted: #e2f2ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--panel-deep);
  color: var(--text);
  font-family: Gulim, "굴림", "Malgun Gothic", system-ui, sans-serif;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.5;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  padding: 10px clamp(12px,3vw,40px);
  padding-top: max(10px,env(safe-area-inset-top));
  background: linear-gradient(#bdefff,#79c9f0);
  border-bottom: 4px solid var(--ink);
  box-shadow: inset 0 -3px #4e9cce;
}

.title {
  margin: 0;
  font-size: clamp(16px,2.6vw,25px);
  letter-spacing: -.05em;
  font-weight: 900;
  color: var(--ink);
  text-shadow: 1px 2px white;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stat {
  display: flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 8px;
  border: 2px solid var(--ink);
  background: #ebfaff;
  box-shadow: 0 2px #518bb4;
}

.stat-label {
  font-size: 11px;
  color: #36567c;
}

.stat-value {
  font-size: 15px;
  color: #183970;
  font-variant-numeric: tabular-nums;
  min-width: 1.2em;
  text-align: right;
}

/* ---------- Stage ---------- */
.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--sky);
  border-bottom: 4px solid var(--ink);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

/* ---------- Overlay ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: safe center;
  justify-content: center;
  padding: 14px;
  background: linear-gradient(180deg,rgba(42,114,161,.05),rgba(56,110,156,.18));
  overflow-y: auto;
  transition: opacity .15s ease;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  position: relative;
  width: min(100%,435px);
  margin-block: auto;
  padding: clamp(16px,2.5vw,28px);
  text-align: center;
  border: 3px solid #172f60;
  border-radius: 5px;
  background: radial-gradient(circle at 1px 1px,rgba(153,223,255,.09) 1px, transparent 1.4px) 0 0 / 6px 6px, linear-gradient(145deg,#275a98,#173962 82%);
  box-shadow: inset 0 3px #679dd1, inset 0 -4px #102951,0 0 0 3px #c2f2ff, 0 0 0 6px #347da4, 7px 9px 0 #315e88;
}

.overlay-kicker {
  margin: 0 0 4px;
  color: #aeeeff;
  font-size: 12px;
  letter-spacing: .18em;
}

.overlay-card.is-result .overlay-kicker {
  display: none;
}

.overlay-title {
  margin: 0 0 10px;
  font-size: clamp(31px,5.4vw,46px);
  font-weight: 900;
  letter-spacing: -.07em;
  line-height: 1.28;
  color: #f5fcff;
  text-shadow: 0 3px #62b9e7, 2px 5px #0c2857;
}

.overlay-card.is-result .overlay-title {
  font-size: clamp(34px, 12vw, 60px);
  line-height: 1.2;
  color: #ffffff;
  text-shadow: 4px 4px 0 var(--ink);
}

.overlay-text {
  margin: 0 auto 16px;
  max-width: 32ch;
  font-size: 14px;
  line-height: 1.65;
  color: #d4eeff;
  word-break: keep-all;
}

.overlay-card.is-result .overlay-text {
  font-size: 16px;
  color: #ffffff;
}

/* ---------- 난이도 선택 ---------- */
.modes {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 14px;
}

.mode-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  padding: 7px 4px;
  border: 2px solid #132c55;
  border-radius: 4px;
  background: #35699c;
  color: white;
  font: inherit;
  cursor: pointer;
  box-shadow: inset 0 2px #6997c5,0 3px #102444;
}

.mode-button:hover {
  background: #3978af;
}

.mode-button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.mode-name {
  font-size: 16px;
  font-weight: 700;
}

.mode-desc {
  font-size: 11px;
  color: #eaf6ff;
}

.mode-button.is-selected {
  background: #b8edff;
  color: #123765;
  box-shadow: inset 0 2px white,0 3px #5ca4cc;
}

.mode-button.is-selected .mode-desc {
  color: #30567a;
}

.primary-button {
  width: 100%;
  padding: 11px 16px;
  min-height: 46px;
  border: 2px solid #302f51;
  border-radius: 4px;
  background: linear-gradient(#ffe987,#ffd851);
  color: #283356;
  font: inherit;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: inset 0 3px #fff4ba,0 4px #be8934;
  transition: transform .06s ease, filter .12s ease;
}

.primary-button:hover {
  filter: brightness(1.05);
}

.primary-button:active {
  transform: translateY(4px);
  box-shadow: 0 1px 0 var(--accent-deep);
}

/* ---------- Controls ---------- */
.controls {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 12px;
  align-items: stretch;
  padding: 10px clamp(12px,3vw,40px);
  padding-bottom: max(10px,env(safe-area-inset-bottom));
  background: repeating-linear-gradient(135deg,#95dcfa 0 8px,#89d5f6 8px 16px);
  border-top: 2px solid #d1f6ff;
}

.prompt-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  padding: 10px 16px;
  border: 2px solid #28567d;
  border-radius: 5px;
  background: linear-gradient(105deg,#21466d,#2d6591);
  box-shadow: inset 0 2px #629fc3, 0 3px #5ba6c9;
}

.prompt-label {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.prompt {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}

.prompt-arrow {
  font-size: 34px;
  line-height: 1;
  color: #ffffff;
  text-shadow: 3px 3px 0 var(--ink);
  transition: color 0.1s ease, transform 0.1s ease;
}

.prompt-name {
  font-size: 16px;
  color: #ffffff;
}

.prompt.is-hit .prompt-arrow {
  color: var(--good);
  transform: scale(1.12);
}

.prompt.is-miss .prompt-arrow {
  color: var(--bad);
  transform: translateY(2px);
}

.timing {
  height: 10px;
  border: 2px solid #102c52;
  border-radius: 3px;
  background: #163756;
  overflow: hidden;
}

.timing-fill {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform-origin: left center;
  transform: scaleX(1);
}

.timing-text {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.2em;
}

/* ---------- D-pad ---------- */
.dpad {
  display: grid;
  grid-template-columns: repeat(3,44px);
  grid-template-rows: repeat(3,44px);
  gap: 4px;
  padding: 5px 8px;
  border: 2px solid #34658b;
  border-radius: 8px;
  background: #75b7d7;
  box-shadow: inset 0 2px #b8e9ff,0 3px #518fb4;
  touch-action: manipulation;
}

.pad {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #214468;
  border-radius: 6px;
  background: linear-gradient(#f4fcff,#c8eaff);
  color: #1b4c79;
  font: inherit;
  font-size: 23px;
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: inset 0 2px white,0 3px #43769a;
  transition: transform .06s ease, background .1s ease;
}

.pad:hover {
  background: var(--panel-light);
}

.pad:active,
.pad.is-active {
  background: var(--accent);
  color: #232f4c;
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.pad-up {
  grid-column: 2;
  grid-row: 1;
}

.pad-left {
  grid-column: 1;
  grid-row: 2;
}

.pad-down {
  grid-column: 2;
  grid-row: 3;
}

.pad-right {
  grid-column: 3;
  grid-row: 2;
}

.pad-center {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #eaf6ff;
}

.pad-finger {
  display: none;
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  opacity: 0.95;
}

body.fingers-on .pad-finger {
  display: block;
}

/* ---------- 반응형 ---------- */
@media (max-width: 560px) {
  .hud {
    gap: 4px 8px;
    padding: 6px 8px;
    padding-top: max(6px, env(safe-area-inset-top));
  }

  .title {
    font-size: 15px;
  }

  .stat {
    padding: 3px 6px;
  }

  .stat-label {
    font-size: 10px;
  }

  .stat-value {
    font-size: 13px;
  }

  .controls {
    gap: 8px;
    padding: 8px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }

  .dpad {
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(3, 40px);
    padding: 6px;
  }

  .overlay-card {
    padding: 14px 12px 12px;
  }
}

@media (max-height: 560px) {
  .hud {
    padding: 4px 8px;
    padding-top: max(4px, env(safe-area-inset-top));
  }

  .title {
    font-size: 14px;
  }

  .stat {
    padding: 2px 6px;
  }

  .controls {
    gap: 8px;
    padding: 6px 8px;
    padding-bottom: max(6px, env(safe-area-inset-bottom));
  }

  .prompt-panel {
    gap: 5px;
    padding: 6px 10px;
  }

  .prompt {
    min-height: 26px;
  }

  .prompt-arrow {
    font-size: 26px;
  }

  .dpad {
    grid-template-columns: repeat(3, 36px);
    grid-template-rows: repeat(3, 36px);
    padding: 5px;
  }

  .overlay-card {
    padding: 12px 12px 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .primary-button,
  .pad,
  .mode-button,
  .prompt-arrow,
  .overlay {
    transition: none;
  }
}

/* 캐비닛 장식과 음악·랭킹 상태 */
.title::before { content: "✦"; display: inline-block; margin-right: .35em; color: #fff0a4; text-shadow: 1px 1px #325c80, -1px -1px #325c80; }
.stats { margin-left: auto; }
.overlay-card::before, .overlay-card::after { content: ""; position: absolute; top: 8px; width: 4px; height: 4px; background: #a6dcf6; box-shadow: 0 2px #193253; }
.overlay-card::before { left: 8px; } .overlay-card::after { right: 8px; }
.primary-button::before { content: "▸"; margin-right: .45em; }
.primary-button:disabled { opacity: .78; cursor: wait; }
.music-button, #rankRetry { min-height: 36px; padding: 4px 10px; border: 2px solid #254f77; border-radius: 5px; background: #e8f9ff; color: #173b63; font: inherit; font-size: 12px; cursor: pointer; box-shadow: 0 2px #5285a8; }
#rankRetry { margin-bottom: 9px; }
#rankingStatus:not(:empty) { margin: 0 0 10px; color: #bcefff; font-size: 13px; }
#rankingStatus:empty { display: none; }
button:focus-visible { outline: 3px solid #fff07a; outline-offset: 2px; box-shadow: 0 0 0 6px #16396a; }
@media (max-width: 560px) {
  .hud { justify-content: space-between; }
  .stats { width: 100%; justify-content: space-between; gap: 3px; }
  .music-button { min-height: 38px; }
  .dpad { grid-template-columns: repeat(3,44px); grid-template-rows: repeat(3,44px); }
}
@media (max-height: 490px) {
  .overlay-card { padding: 9px 14px; }
  .overlay-title { font-size: 25px; margin-bottom: 4px; }
  .overlay-kicker { margin-bottom: 0; }
  .overlay-text, .modes { margin-bottom: 7px; }
  .mode-button { min-height: 38px; }
}
