* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

:root {
  --bg-sky-top: #ffc266;
  --bg-sky-bottom: #d81f3a;
  --accent: #F47725;
  --accent-2: #ffb067;
  --panel: #ffffff;
  --panel-text: #3a2c22;
  --muted: #a68f7d;
  --danger: #EA002C;
  --success: #33d69f;
  --gold: #ffcb3d;
  --shadow: rgba(58, 30, 14, 0.28);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Apple SD Gothic Neo",
    "Malgun Gothic", "Segoe UI", Roboto, sans-serif;
  background: #7a1710;
  color: var(--panel-text);
  width: 100%;
  height: 100dvh;
  height: 100svh;
  position: fixed;
  inset: 0;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  overflow: hidden;
  background: linear-gradient(160deg, var(--bg-sky-top) 0%, var(--accent) 45%, var(--bg-sky-bottom) 100%);
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.35);
}

/* ================= HUD ================= */
.topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: calc(14px + var(--safe-top)) 16px 10px;
  pointer-events: none;
}

.topbar-row {
  width: 100%;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.hud-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex: 1;
}

.hud-block {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 14px;
  padding: 6px 12px;
  min-width: 54px;
  text-align: center;
  box-shadow: 0 4px 12px var(--shadow);
  backdrop-filter: blur(4px);
}

.hud-floor {
  background: rgba(58, 30, 14, 0.85);
}
.hud-floor .hud-label,
.hud-floor .hud-value {
  color: #fff;
}

.hud-combo {
  background: rgba(255, 138, 61, 0.95);
}
.hud-combo .hud-label,
.hud-combo .hud-value {
  color: #fff;
}

.hud-label {
  display: block;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.hud-value {
  display: block;
  font-size: 19px;
  font-weight: 900;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  color: var(--panel-text);
  transition: transform 0.12s ease;
}

.hud-value.bump {
  animation: bump 0.28s ease;
}

@keyframes bump {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); color: var(--accent); }
  100% { transform: scale(1); }
}

.icon-btn {
  pointer-events: auto;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 4px 12px var(--shadow);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.icon-btn:active {
  transform: scale(0.88);
}

/* ================= collect panel ================= */
.collect-panel {
  background: rgba(255, 255, 255, 0.92);
  border-radius: 14px;
  padding: 8px 12px;
  box-shadow: 0 4px 12px var(--shadow);
  backdrop-filter: blur(4px);
  min-width: 148px;
}

.collect-title {
  font-size: 9.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 3px;
}

.collect-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 1.5px 0;
  border-radius: 6px;
  transition: box-shadow 0.2s ease;
}

.collect-label {
  font-size: 11.5px;
  font-weight: 800;
  color: var(--panel-text);
}

.collect-value {
  font-size: 12.5px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  transition: transform 0.12s ease;
}

.collect-value.bump {
  animation: bump 0.28s ease;
}

.collect-row.complete {
  animation: collectGlow 1.1s ease-in-out infinite;
}
.collect-row.complete .collect-value {
  color: var(--gold);
}

@keyframes collectGlow {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 203, 61, 0); }
  50% { box-shadow: 0 0 10px 2px rgba(255, 203, 61, 0.7); }
}

/* ================= combo badge ================= */
.combo-badge {
  position: absolute;
  top: calc(64px + var(--safe-top));
  right: calc(16px + var(--safe-right));
  z-index: 21;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  color: #fff;
  font-weight: 900;
  font-size: 16px;
  padding: 6px 18px;
  border-radius: 999px;
  box-shadow: 0 6px 16px rgba(255, 138, 61, 0.5);
  opacity: 0;
  pointer-events: none;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.combo-badge.show {
  animation: comboPop 0.7s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes comboPop {
  0% { opacity: 0; transform: scale(0.4) translateY(10px); }
  25% { opacity: 1; transform: scale(1.15) translateY(0); }
  40% { transform: scale(1); }
  80% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.9) translateY(-6px); }
}

/* ================= toast (floating text) ================= */
.toast-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 22;
  overflow: hidden;
}

.toast {
  position: absolute;
  font-weight: 900;
  font-size: 15px;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  white-space: nowrap;
  animation: toastFloat 0.9s ease-out forwards;
}

@keyframes toastFloat {
  0% { opacity: 0; transform: translate(-50%, 0) scale(0.7); }
  15% { opacity: 1; transform: translate(-50%, -6px) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -46px) scale(1); }
}

/* ================= commitment celebration ================= */
.commitment-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 22%;
  overflow: hidden;
}

.commitment-flash {
  position: absolute;
  inset: -20%;
  background: radial-gradient(circle at 50% 38%, rgba(255, 235, 170, 0.95) 0%, rgba(255, 187, 61, 0.55) 32%, rgba(244, 119, 37, 0) 68%);
  opacity: 0;
}

.commitment-overlay.show .commitment-flash {
  animation: commitFlash 1.8s ease-out forwards;
}

@keyframes commitFlash {
  0% { opacity: 0; transform: scale(0.7); }
  12% { opacity: 1; transform: scale(1.05); }
  30% { opacity: 0.85; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.15); }
}

.commitment-text {
  position: relative;
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 0.01em;
  background: linear-gradient(135deg, #fff2c4, #ffcb3d 45%, #F47725 85%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: none;
  filter: drop-shadow(0 3px 0 rgba(122, 23, 16, 0.55)) drop-shadow(0 0 22px rgba(255, 203, 61, 0.9));
  opacity: 0;
  transform: translateY(40px) scale(0.6);
  white-space: nowrap;
}

.commitment-bang {
  display: inline-block;
}

.commitment-overlay.show .commitment-text {
  animation: commitText 1.8s cubic-bezier(0.2, 0.9, 0.25, 1.1) forwards;
}

@keyframes commitText {
  0% { opacity: 0; transform: translateY(50px) scale(0.5); }
  30% { opacity: 1; transform: translateY(0) scale(1.18); }
  42% { transform: translateY(0) scale(0.94); }
  52% { transform: translateY(0) scale(1.04); }
  62% { transform: translateY(0) scale(1); }
  85% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-14px) scale(1.03); }
}

#game-stage.zoom-in {
  transition: transform 0.35s cubic-bezier(0.2, 0.9, 0.25, 1.1);
  transform: scale(1.055);
}

/* ================= game stage ================= */
#game-stage {
  position: absolute;
  inset: 0;
  z-index: 1;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.timer-bar-wrap {
  position: absolute;
  left: 50%;
  bottom: calc(112px + var(--safe-bottom));
  transform: translateX(-50%);
  width: 46%;
  max-width: 220px;
  height: 6px;
  border-radius: 999px;
  background: rgba(43, 33, 64, 0.25);
  overflow: hidden;
  z-index: 15;
}

.timer-bar {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--success), var(--accent-2));
  border-radius: 999px;
  transform-origin: left center;
  transition: background-color 0.2s ease;
}

.timer-bar.warn {
  background: linear-gradient(90deg, var(--accent), var(--danger));
}

/* ================= screens ================= */
.screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(120, 30, 10, 0.35);
  backdrop-filter: blur(2px);
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.screen-card {
  width: 100%;
  max-width: 360px;
  background: var(--panel);
  border-radius: 28px;
  padding: 36px 28px 30px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(60, 20, 8, 0.4);
  animation: cardPop 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes cardPop {
  from { opacity: 0; transform: scale(0.85) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.logo-emoji {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 6px;
  filter: drop-shadow(0 6px 10px rgba(0,0,0,0.15));
  animation: floatY 2.4s ease-in-out infinite;
}

.haru-logo {
  width: 96px;
  margin: 0 auto 6px;
}
.haru-logo svg {
  width: 100%;
  height: auto;
  display: block;
}

@keyframes floatY {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

.sk-wordmark {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.02em;
  color: var(--danger);
  margin-bottom: 2px;
}

.game-title {
  margin: 4px 0 6px;
  font-size: 30px;
  font-weight: 900;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--accent), var(--danger));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.game-tagline {
  margin: 0 0 4px;
  font-size: 14px;
  color: var(--panel-text);
  font-weight: 800;
}

.game-subtitle {
  margin: 0 0 22px;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
}

.primary-btn {
  width: 100%;
  border: none;
  padding: 16px;
  font-size: 18px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--danger));
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 10px 22px rgba(234, 0, 44, 0.4);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.primary-btn:active {
  transform: scale(0.96);
  box-shadow: 0 6px 14px rgba(234, 0, 44, 0.35);
}

.controls-hint {
  display: flex;
  justify-content: center;
  gap: 22px;
  margin-top: 22px;
}

.hint-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}

.hint-key {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: #fff0e2;
  color: var(--accent);
  font-weight: 900;
}

.best-preview {
  margin: 20px 0 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.best-preview strong {
  color: var(--panel-text);
  font-weight: 900;
}

/* ---- game over ---- */
.gameover-emoji {
  animation: shake 0.5s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0) rotate(0); }
  20% { transform: translateX(-6px) rotate(-6deg); }
  40% { transform: translateX(6px) rotate(6deg); }
  60% { transform: translateX(-4px) rotate(-3deg); }
  80% { transform: translateX(4px) rotate(3deg); }
}

.gameover-title {
  margin: 2px 0 18px;
  font-size: 24px;
  font-weight: 900;
  color: var(--danger);
  letter-spacing: 0.02em;
}

.result-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 16px;
  background: #fff3ea;
  border-radius: 12px;
}

.result-row-best {
  background: linear-gradient(135deg, #fff6e0, #ffe9c2);
}

.result-row-commit {
  background: linear-gradient(135deg, #ffe4d1, #ffc9a8);
}

.result-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.result-value {
  font-size: 20px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
}

.new-record-badge {
  display: inline-block;
  margin-bottom: 16px;
  padding: 6px 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffd23d, #ff8a3d);
  color: #fff;
  font-weight: 900;
  font-size: 12.5px;
  letter-spacing: 0.04em;
  animation: comboPop 1s ease infinite;
}

/* ================= controls (mobile/PC buttons) ================= */
.controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  gap: 14px;
  padding: 14px calc(16px + var(--safe-left)) calc(18px + var(--safe-bottom)) calc(16px + var(--safe-right));
}

.dir-btn {
  flex: 1;
  height: 84px;
  border: none;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 8px 18px var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.12s ease;
}

.dir-arrow {
  font-size: 30px;
  color: var(--accent);
  font-weight: 900;
}

.dir-btn:active,
.dir-btn.pressed {
  transform: scale(0.93);
  background: rgba(108, 92, 231, 0.18);
}

/* ================= misc ================= */
[hidden] {
  display: none !important;
}

@media (max-width: 340px) {
  .screen-card { padding: 28px 20px 24px; }
  .game-title { font-size: 26px; }
  .dir-btn { height: 74px; }
  .hud-block { min-width: 44px; padding: 5px 8px; }
  .hud-value { font-size: 15px; }
  .hud-label { font-size: 9px; }
  .collect-panel { min-width: 128px; padding: 6px 9px; top: calc(58px + var(--safe-top)); }
  .collect-label { font-size: 10px; }
  .collect-value { font-size: 11px; }
  .commitment-text { font-size: 32px; }
}

@media (min-height: 780px) {
  .dir-btn { height: 96px; }
}
