/* Sungshin 3-Tier Hill Ski Jump — Final Approved Lavender Panel & Mobile Landscape Theme */
:root {
  --purple-deep: #2E1A53;
  --purple-main: #6440A0;
  --purple-btn: #9971D4;
  --purple-btn-hover: #A680DE;
  --purple-btn-border: #6945A3;
  --purple-btn-shadow: #623E9B;
  --panel-bg: #F7F3FF;
  --panel-border: #AC96D0;
  --panel-shadow: rgba(74, 48, 122, 0.30);
  --purple-soft: #E5DAFA;
  --purple-muted: #5B4978;
  --gold-accent: #FFD84D;
  --border-ink: #5A3B94;
  --font-main: 'Pretendard Variable', 'Pretendard', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #2B4275;
  font-family: var(--font-main);
  color: var(--purple-deep);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  background: radial-gradient(circle at 50% 25%, #4873B8 0%, #263B6B 100%);
}

/* Stage: Exact 16:9 on Desktop, adaptive 16:9..20:9 full-bleed on Mobile Landscape */
.game-stage {
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  height: min(100dvh, calc(100vw * 9 / 16));
  max-width: 1920px;
  max-height: 1080px;
  background: #5EA0F5;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(10, 16, 40, 0.45);
  touch-action: manipulation;
  container-type: size;
}

/* On mobile landscape screens (wide & short), fill entire usable screen edge-to-edge up to 20:9 */
@media (orientation: landscape) and (max-height: 540px) {
  .game-stage {
    width: min(100vw, calc(100dvh * 20 / 9));
    height: 100dvh;
    max-width: none;
    max-height: none;
    box-shadow: none;
  }
}

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

/* Shared Overlay Layer */
.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}

.overlay button,
.overlay input,
.overlay label,
.overlay .modal-card,
.overlay .menu-panel {
  pointer-events: auto;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #7E57C2;
  outline-offset: 2px;
}

/* ============================================================================
   HOME SCREEN — Matches sungshin_home_centered_panel & mobile_landscape mockups
   ============================================================================ */
.overlay-menu {
  align-items: center;
  justify-content: center;
  padding:
    max(12px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  z-index: 20;
}

.menu-top-bar {
  position: absolute;
  top: max(clamp(10px, 2.2cqh, 22px), env(safe-area-inset-top));
  left: max(clamp(12px, 2cqw, 24px), env(safe-area-inset-left));
  right: max(clamp(12px, 2cqw, 24px), env(safe-area-inset-right));
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
  z-index: 5;
}

.menu-icon-group {
  display: flex;
  gap: clamp(6px, 0.9cqw, 10px);
  margin-left: auto;
}

/* Top-Right Purple Game UI Icon Buttons (matching mockup) */
.icon-btn {
  width: clamp(38px, 6.2cqh, 48px);
  height: clamp(38px, 6.2cqh, 48px);
  min-width: 40px;
  min-height: 40px;
  border-radius: 10px;
  border: 2px solid #7553B2;
  background: var(--panel-bg);
  color: #5C3B96;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 #6B49A8;
  transition: transform 0.1s ease, background-color 0.15s ease;
  padding: 0;
}

.icon-btn:hover {
  background: #FFFFFF;
}

.icon-btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #6B49A8;
}

.icon-svg {
  width: 56%;
  height: 56%;
  display: block;
}

/* Subtle Best Badge on Home Top-Left */
.pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--panel-bg);
  border: 2px solid #7553B2;
  border-radius: 10px;
  padding: 5px 12px;
  box-shadow: 0 3px 0 #6B49A8;
  font-size: clamp(12px, 1.8cqh, 15px);
  color: var(--purple-deep);
}

.pill-label {
  font-weight: 800;
  color: #6B49A8;
  font-size: 0.85em;
  letter-spacing: 0.04em;
}

/* Unified Centered Layout Group: Title Logo + Integrated Lavender Menu Panel */
.menu-center-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2.2cqh, 18px);
  /* Visual vertical balance matching sungshin_home_centered_panel.png (slight lower anchor) */
  transform: translateY(1.8cqh);
  max-height: 94cqh;
}

.menu-logo-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}

/* Crisp Title Plaque — preserves 992x586 aspect ratio, NO background shape or box shadow */
.menu-title-img {
  height: clamp(118px, 37.5cqh, 290px);
  width: auto;
  max-width: min(470px, 52cqw);
  object-fit: contain;
  display: block;
}

/* Integrated Solid Light Lavender Menu Panel (matching mockup #F7F3FF + #AC96D0 border) */
.menu-panel {
  width: clamp(276px, 34.5cqw, 444px);
  background: var(--panel-bg);
  border: 2px solid var(--panel-border);
  border-radius: clamp(13px, 2.1cqh, 18px);
  box-shadow: 0 4px 0 rgba(100, 72, 152, 0.34), 0 8px 20px rgba(36, 20, 72, 0.14);
  padding: clamp(12px, 2.5cqh, 22px) clamp(14px, 2.2cqw, 24px) clamp(12px, 2.2cqh, 18px);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.menu-copy {
  margin-bottom: clamp(10px, 2.1cqh, 16px);
  line-height: 1.38;
}

.copy-sub {
  margin: 0;
  font-size: clamp(11px, 2.0cqh, 15px);
  font-weight: 500;
  color: var(--purple-muted);
  letter-spacing: -0.015em;
}

.copy-main {
  margin: 2px 0 0;
  font-size: clamp(13.5px, 2.55cqh, 19px);
  font-weight: 800;
  color: var(--purple-deep);
  letter-spacing: -0.02em;
}

/* Primary START CTA inside panel (matches #9971D4 solid bevel purple button) */
.btn-panel-start {
  appearance: none;
  width: 100%;
  min-height: clamp(44px, 7.6cqh, 58px);
  border-radius: clamp(10px, 1.6cqh, 13px);
  border: 2px solid var(--purple-btn-border);
  background: var(--purple-btn);
  color: #FFFFFF;
  font-family: var(--font-main);
  font-size: clamp(16px, 3.1cqh, 23px);
  font-weight: 800;
  letter-spacing: 0.05em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.24),
    0 4px 0 var(--purple-btn-shadow);
  transition: transform 0.1s ease, background-color 0.14s ease;
}

.btn-panel-start:hover {
  background: var(--purple-btn-hover);
}

.btn-panel-start:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--purple-btn-shadow);
}

.start-play-icon {
  width: 0.72em;
  height: 0.72em;
  display: block;
}

/* Secondary RANKING button: full-width light lavender secondary CTA (~68% height of START, flat & crisp) */
.btn-panel-ranking {
  appearance: none;
  width: 100%;
  margin-top: clamp(10px, 1.8cqh, 14px);
  height: clamp(30px, 5.2cqh, 40px);
  min-height: 0;
  padding: 0 16px;
  border: 1.5px solid #C2AEE5;
  border-radius: clamp(10px, 1.6cqh, 13px);
  background: #EFE6FF;
  color: #5C3B96;
  font-family: var(--font-main);
  font-size: clamp(12.5px, 2.05cqh, 15px);
  font-weight: 800;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  cursor: pointer;
  box-shadow: none;
  transition: background-color 0.14s ease, border-color 0.14s ease, transform 0.1s ease;
}

.btn-panel-ranking:hover {
  background: #E7DAFF;
  border-color: #AF96DC;
}

.btn-panel-ranking:active {
  transform: translateY(1px);
  background: #DFCEFF;
}

.trophy-icon {
  width: 1.15em;
  height: 1.15em;
  color: #7956B8;
  display: block;
}

/* Mobile Landscape Home Fine-Tuning (667x375, 800x360, 844x390, 932x430) */
@media (orientation: landscape) and (max-height: 460px) {
  .menu-center-group {
    gap: clamp(5px, 1.8cqh, 10px);
    transform: translateY(0.5cqh);
  }

  .menu-title-img {
    height: clamp(104px, 36.5cqh, 162px);
    max-width: 44cqw;
  }

  .menu-panel {
    width: clamp(268px, 38.5cqw, 350px);
    padding: 9px 14px 10px;
    border-radius: 14px;
  }

  .menu-copy {
    margin-bottom: 8px;
  }

  .copy-sub {
    font-size: clamp(10.5px, 2.8cqh, 12.5px);
  }

  .copy-main {
    font-size: clamp(12.5px, 3.4cqh, 15.5px);
  }

  .btn-panel-start {
    height: 44px;
    min-height: 44px;
    font-size: 17px;
  }

  .btn-panel-ranking {
    margin-top: 9px;
    height: 30px;
    min-height: 30px;
    padding: 0 14px;
    font-size: 12.5px;
  }
}

/* ============================================================================
   SHARED BUTTONS & LOADING OVERLAY
   ============================================================================ */
.btn {
  appearance: none;
  border: 2px solid var(--purple-btn-border);
  border-radius: 11px;
  font-family: var(--font-main);
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.15s ease;
  min-height: 44px;
  padding: 8px 16px;
  font-size: clamp(13px, 1.9cqh, 15.5px);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:active:not(:disabled) {
  transform: translateY(2px);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--purple-btn);
  color: #FFFFFF;
  box-shadow: 0 3px 0 var(--purple-btn-shadow);
}

.btn-primary:hover:not(:disabled) {
  background: var(--purple-btn-hover);
}

.btn-accent {
  background: var(--purple-soft);
  color: var(--purple-deep);
  border-color: var(--panel-border);
  box-shadow: 0 3px 0 rgba(100, 72, 152, 0.32);
}

.btn-accent:hover:not(:disabled) {
  background: #EFE7FF;
}

.btn-secondary {
  background: #FFFFFF;
  color: var(--purple-deep);
  border-color: var(--panel-border);
  box-shadow: 0 3px 0 rgba(100, 72, 152, 0.26);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--panel-bg);
}

.btn-ghost {
  background: transparent;
  color: var(--purple-main);
  border-color: rgba(105, 69, 163, 0.35);
}

.btn-ghost:hover:not(:disabled) {
  background: rgba(153, 113, 212, 0.1);
}

.btn-danger-ghost {
  background: #FFF1F2;
  color: #BE123C;
  border-color: #FDA4AF;
}

.btn-full {
  width: 100%;
}

.overlay-loading {
  background: linear-gradient(180deg, #6EAFF8 0%, #B8D9FF 100%);
  align-items: center;
  justify-content: center;
  z-index: 50;
  pointer-events: auto;
}

.loading-box {
  background: var(--panel-bg);
  border: 2.5px solid #7553B2;
  border-radius: 18px;
  padding: 24px 28px;
  width: min(390px, 86%);
  text-align: center;
  box-shadow: 0 6px 0 rgba(92, 59, 150, 0.35);
}

.loading-title {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 900;
  color: var(--purple-deep);
}

.loading-status {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--purple-main);
  font-weight: 600;
}

.loading-bar-track {
  height: 13px;
  background: #E9DFFD;
  border: 2px solid #7553B2;
  border-radius: 999px;
  overflow: hidden;
}

.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #8B5FD6, #B992FA);
  transition: width 0.15s ease;
}

.loading-error {
  margin-top: 14px;
  color: #BE123C;
  font-size: 13px;
  font-weight: 700;
}

/* ============================================================================
   IN-GAME HUD & DUAL TIMING GAUGE
   ============================================================================ */
.overlay-hud {
  padding:
    max(clamp(8px, 2cqh, 18px), env(safe-area-inset-top))
    max(clamp(10px, 1.8cqw, 22px), env(safe-area-inset-right))
    max(clamp(8px, 2cqh, 18px), env(safe-area-inset-bottom))
    max(clamp(10px, 1.8cqw, 22px), env(safe-area-inset-left));
  z-index: 15;
}

.hud-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}

.hud-left,
.hud-right {
  display: flex;
  align-items: center;
  gap: clamp(6px, 0.9cqw, 11px);
}

.hud-metric {
  background: rgba(247, 243, 255, 0.94);
  border: 2px solid #7553B2;
  border-radius: 12px;
  padding: clamp(4px, 0.9cqh, 8px) clamp(9px, 1.2cqw, 15px);
  box-shadow: 0 3px 0 #6B49A8;
  display: flex;
  flex-direction: column;
  min-width: clamp(72px, 8.8cqw, 118px);
}

.hud-label {
  font-size: clamp(9.5px, 1.35cqh, 11px);
  font-weight: 800;
  color: #6B49A8;
  letter-spacing: 0.04em;
  line-height: 1.1;
}

.hud-metric strong {
  font-size: clamp(16px, 3.2cqh, 26px);
  font-weight: 900;
  color: var(--purple-deep);
  line-height: 1.12;
  font-variant-numeric: tabular-nums;
}

.hud-metric .unit {
  font-size: 0.56em;
  font-weight: 800;
  margin-left: 2px;
  color: #6B49A8;
}

.hud-speed.compact {
  opacity: 0.72;
  transform: scale(0.9);
  transform-origin: left center;
}

.center-callout {
  position: absolute;
  top: 24%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  background: var(--panel-bg);
  border: 2.5px solid #7553B2;
  border-radius: 16px;
  padding: clamp(9px, 2cqh, 16px) clamp(18px, 2.8cqw, 34px);
  box-shadow: 0 5px 0 rgba(92, 59, 150, 0.35);
}

.callout-main {
  margin: 0;
  font-size: clamp(18px, 3.8cqh, 32px);
  font-weight: 900;
  color: var(--purple-deep);
}

.callout-sub {
  margin: 5px 0 0;
  font-size: clamp(11.5px, 2cqh, 15px);
  font-weight: 700;
  color: #6440A0;
}

.judgment-banner {
  position: absolute;
  top: 17%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  animation: popIn 0.18s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

@keyframes popIn {
  from { transform: translateX(-50%) scale(0.78); opacity: 0; }
  to { transform: translateX(-50%) scale(1); opacity: 1; }
}

.judgment-text {
  font-size: clamp(19px, 4.4cqh, 38px);
  font-weight: 900;
  letter-spacing: 0.03em;
  padding: 4px 16px;
  border-radius: 13px;
  border: 2.5px solid #5B3896;
  box-shadow: 0 4px 0 rgba(74, 48, 122, 0.4);
}

.judgment-text.grade-PERFECT { background: #FFF2A6; color: #5B21B6; }
.judgment-text.grade-GREAT   { background: #CCFBF1; color: #115E59; }
.judgment-text.grade-GOOD    { background: #DBEAFE; color: #1E40AF; }
.judgment-text.grade-MISS    { background: #FFE4E6; color: #9F1239; }

.judgment-sub {
  font-size: clamp(13px, 2.3cqh, 19px);
  font-weight: 800;
  color: var(--purple-deep);
  background: var(--panel-bg);
  padding: 3px 14px;
  border-radius: 999px;
  border: 2px solid #7553B2;
}

/* Timing Gauge — high-center, crisp & readable on both PC and 360px-tall phones */
.timing-container {
  position: absolute;
  top: clamp(54px, 12.5cqh, 92px);
  left: 50%;
  transform: translateX(-50%);
  width: min(460px, 64cqw);
  background: var(--panel-bg);
  border: 2.5px solid #7553B2;
  border-radius: 15px;
  padding: clamp(6px, 1.4cqh, 12px) clamp(11px, 1.6cqw, 18px);
  box-shadow: 0 4px 0 rgba(92, 59, 150, 0.34);
}

.timing-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.timing-prompt {
  font-size: clamp(13px, 2.6cqh, 19px);
  font-weight: 900;
  color: var(--purple-deep);
}

.timing-key-hint {
  font-size: clamp(9.5px, 1.6cqh, 12px);
  font-weight: 800;
  color: #6440A0;
  background: #EDE4FF;
  border: 1.5px solid #8E68CC;
  border-radius: 999px;
  padding: 2px 8px;
}

.timing-track {
  position: relative;
  height: clamp(22px, 4.2cqh, 32px);
  background: #EDE9FE;
  border: 2px solid #5B3896;
  border-radius: 999px;
  overflow: hidden;
}

.timing-zone {
  position: absolute;
  top: 0;
  bottom: 0;
}

.zone-good { background: #BFDBFE; }
.zone-great { background: #99F6E4; }
.zone-perfect {
  background: #FDE047;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: 1.5px solid rgba(59, 32, 105, 0.35);
  border-right: 1.5px solid rgba(59, 32, 105, 0.35);
}

.zone-marker-label {
  font-size: clamp(7.5px, 1.3cqh, 10px);
  font-weight: 900;
  color: var(--purple-deep);
  letter-spacing: 0.03em;
}

.timing-target-line {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--purple-deep);
  opacity: 0.72;
  transform: translateX(-50%);
}

.timing-cursor {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 10px;
  background: var(--purple-deep);
  border: 2px solid #FFFFFF;
  border-radius: 6px;
  transform: translateX(-50%);
  box-shadow: 0 0 8px rgba(43, 22, 79, 0.45);
}

/* Accessible Touch Action Pad (bottom-right, generous touch target, never covers character) */
.action-pad {
  position: absolute;
  right: max(clamp(12px, 2cqw, 26px), env(safe-area-inset-right));
  bottom: max(clamp(12px, 3cqh, 26px), env(safe-area-inset-bottom));
  min-width: clamp(92px, 13cqw, 134px);
  min-height: clamp(52px, 11cqh, 74px);
  border-radius: 16px;
  border: 2.5px solid var(--purple-btn-border);
  background: var(--purple-btn);
  color: #FFFFFF;
  font-family: var(--font-main);
  font-size: clamp(16px, 3.2cqh, 22px);
  font-weight: 900;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.25), 0 4px 0 var(--purple-btn-shadow);
  cursor: pointer;
}

.action-pad.pulse {
  background: #FFD84D;
  color: var(--purple-deep);
  border-color: #7A5400;
  box-shadow: 0 4px 0 #8F6300;
  transform: scale(1.04);
}

.action-pad:active {
  transform: translateY(3px);
}

.hud-rank-notice {
  position: absolute;
  left: max(14px, env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  background: rgba(46, 26, 83, 0.85);
  color: #F7F3FF;
  font-size: 11.5px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
}

/* ============================================================================
   MODALS, RESULT SCREEN & ONLINE RANKING
   ============================================================================ */
.overlay-modal {
  position: fixed;
  inset: 0;
  background: rgba(28, 16, 56, 0.56);
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(10px, env(safe-area-inset-top))
    max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-left));
  z-index: 40;
  pointer-events: auto;
}

.modal-card {
  background: var(--panel-bg);
  border: 2.5px solid var(--panel-border);
  border-radius: 20px;
  box-shadow: 0 6px 0 rgba(92, 59, 150, 0.35), 0 18px 40px rgba(18, 9, 40, 0.42);
  width: min(560px, 94vw);
  max-height: min(92dvh, 660px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.compact-card {
  width: min(440px, 92vw);
}

.ranking-card {
  width: min(580px, 94vw);
  height: min(600px, 90dvh);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px 10px;
  border-bottom: 2px solid #E5DAFA;
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: clamp(17px, 2.4vw, 22px);
  font-weight: 900;
  color: var(--purple-deep);
}

.modal-subtitle {
  margin: 2px 0 0;
  font-size: 12.5px;
  font-weight: 600;
  color: #6B49A8;
}

.modal-close {
  width: 40px;
  height: 40px;
  min-width: 44px;
  min-height: 44px;
  border-radius: 11px;
  border: 2px solid var(--panel-border);
  background: #FFFFFF;
  color: var(--purple-deep);
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.modal-body {
  padding: 14px 18px;
  overflow-y: auto;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.modal-footer {
  padding: 10px 18px 14px;
  border-top: 2px solid #E5DAFA;
  flex-shrink: 0;
}

/* Result Card — Centered Game-Like Visual Hierarchy (Character + Distance Side-by-Side) */
.result-card {
  width: min(630px, 90vw);
  max-height: 90dvh;
  padding: clamp(16px, 3vh, 26px) clamp(18px, 3vw, 28px) clamp(14px, 2.4vh, 22px);
  gap: clamp(8px, 1.4vh, 12px);
  overflow-y: auto;
}

.new-record-ribbon {
  background: var(--purple-main);
  color: #FFFFFF;
  border-radius: 10px;
  padding: 5px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: clamp(11.5px, 1.7vh, 14px);
  font-weight: 800;
  flex-shrink: 0;
}

.nr-badge {
  background: var(--gold-accent);
  color: var(--purple-deep);
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.85em;
  font-weight: 900;
}

.result-layout {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: clamp(8px, 1.5vh, 13px);
}

/* Top Center Group: Transparent Character (left) + Final Distance (right) */
.result-hero-pair {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 2.2vw, 20px);
}

.result-character-img {
  height: clamp(68px, 14vh, 108px);
  width: auto;
  max-width: 120px;
  object-fit: contain;
  display: block;
  flex-shrink: 0;
  background: transparent;
}

.result-dist-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.result-distance-label {
  display: block;
  font-size: clamp(11.5px, 1.8vh, 14px);
  font-weight: 700;
  color: #7960A8;
  letter-spacing: -0.01em;
}

.result-distance-val {
  display: block;
  font-size: clamp(36px, 7vh, 56px);
  font-weight: 900;
  color: var(--purple-deep);
  line-height: 1.04;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}

/* Centered Title & Result Message directly beneath Hero Pair */
.result-title-box {
  text-align: center;
  margin-top: -2px;
}

.result-title-name {
  margin: 0;
  font-size: clamp(17px, 3vh, 23px);
  font-weight: 900;
  color: #5C3B96;
  letter-spacing: -0.02em;
}

.result-title-msg {
  margin: 3px 0 0;
  font-size: clamp(12.5px, 2vh, 15px);
  font-weight: 500;
  color: #705D90;
}

/* Middle: 3 Equal Subtle White Boxes */
.result-grades {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(7px, 1.2vw, 11px);
}

.grade-pill {
  background: #FFFFFF;
  border: 1.5px solid #DED3F5;
  border-radius: 12px;
  padding: clamp(7px, 1.3vh, 11px) 8px;
  text-align: center;
}

.grade-key {
  display: block;
  font-size: clamp(10.5px, 1.55vh, 12px);
  font-weight: 600;
  color: #7E6AA3;
}

.grade-val {
  display: block;
  margin-top: 3px;
  font-size: clamp(13px, 2.1vh, 16px);
  font-weight: 800;
  color: var(--purple-deep);
}

.grade-val.is-miss {
  color: #C2284B;
}

/* Plain Compact Text Notice (no red box!) */
.result-fail-note {
  margin: 0;
  font-size: clamp(11.5px, 1.75vh, 13px);
  font-weight: 600;
  color: #C23052;
  background: transparent;
  padding: 0;
  text-align: center;
}

.result-rank-status {
  margin: 0;
  font-size: clamp(11px, 1.6vh, 12.5px);
  font-weight: 600;
  color: #746099;
  text-align: center;
}

/* Primary CTA + Unified 2x2 Secondary Buttons */
.result-actions {
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.4vh, 11px);
  margin-top: 2px;
}

.btn-result-retry {
  min-height: clamp(44px, 6.8vh, 52px);
  font-size: clamp(15.5px, 2.4vh, 18.5px);
  letter-spacing: 0.01em;
}

.result-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: clamp(7px, 1.2vw, 10px);
}

.result-sub-btn {
  width: 100%;
  min-height: clamp(36px, 5.4vh, 44px);
  padding: 6px 12px;
  border-radius: clamp(10px, 1.6cqh, 12px);
  border: 1.5px solid #C6B4E8;
  background: #FFFFFF;
  color: #5C3B96;
  font-size: clamp(12.5px, 1.9vh, 14.5px);
  font-weight: 700;
  box-shadow: none;
}

.result-sub-btn:hover:not(:disabled) {
  background: #F4EEFF;
  border-color: #AF96DC;
}

.result-sub-accent {
  background: #EAE0FB;
  border-color: #BEA8E6;
}

.result-sub-accent:hover:not(:disabled) {
  background: #E1D3FA;
}

/* Mobile Landscape Compact Scaling — preserves unified centered layout & outer breathing room on 360~430px height */
@media (orientation: landscape) and (max-height: 460px) {
  .overlay-modal {
    padding:
      max(12px, env(safe-area-inset-top))
      max(20px, env(safe-area-inset-right))
      max(12px, env(safe-area-inset-bottom))
      max(20px, env(safe-area-inset-left));
  }

  .result-card {
    width: min(560px, 86vw);
    max-height: calc(100dvh - 24px);
    padding: 10px 18px 11px;
    gap: 5px;
    border-radius: 17px;
  }

  .new-record-ribbon {
    padding: 3px 10px;
    font-size: 11px;
  }

  .result-layout {
    gap: 6px;
  }

  .result-hero-pair {
    gap: 12px;
  }

  .result-character-img {
    height: clamp(54px, 15.5dvh, 66px);
  }

  .result-distance-label {
    font-size: 10.5px;
  }

  .result-distance-val {
    font-size: clamp(28px, 8.2dvh, 36px);
  }

  .result-title-name {
    font-size: clamp(14.5px, 4.1dvh, 17px);
  }

  .result-title-msg {
    margin-top: 1px;
    font-size: clamp(11px, 3dvh, 12.5px);
  }

  .result-grades {
    gap: 7px;
  }

  .grade-pill {
    padding: 5px 6px;
    border-radius: 10px;
  }

  .grade-key {
    font-size: 10px;
  }

  .grade-val {
    margin-top: 1px;
    font-size: 12.5px;
  }

  .result-fail-note,
  .result-rank-status {
    font-size: 11px;
  }

  .result-actions {
    gap: 6px;
    margin-top: 1px;
  }

  .btn-result-retry {
    min-height: 38px;
    height: 38px;
    font-size: 14.5px;
  }

  .result-actions-grid {
    gap: 6px;
  }

  .result-sub-btn {
    min-height: 31px;
    height: 31px;
    padding: 0 10px;
    font-size: 12px;
    border-radius: 9px;
  }
}

/* Help & Pause Content */
.help-main-copy {
  margin: 0 0 12px;
  font-size: 14.5px;
  line-height: 1.5;
  font-weight: 700;
  color: var(--purple-deep);
  background: #FFFFFF;
  border: 1.5px solid #DCD0F5;
  padding: 11px 13px;
  border-radius: 12px;
}

.help-list {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 13px;
  line-height: 1.45;
}

.help-list code {
  background: #E9DFFD;
  padding: 1px 6px;
  border-radius: 6px;
  font-weight: 700;
}

.toggle-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

.pause-note {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--purple-muted);
  line-height: 1.45;
}

.stack-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Ranking Modal */
.ranking-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ranking-my-bar {
  background: #FFFFFF;
  border: 1.5px solid #DCD0F5;
  border-radius: 12px;
  padding: 9px 13px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

.ranking-state {
  text-align: center;
  padding: 22px 16px;
  background: #FFFFFF;
  border: 2px dashed var(--panel-border);
  border-radius: 14px;
  color: var(--purple-deep);
}

.ranking-state strong {
  display: block;
  font-size: 15.5px;
  margin-bottom: 6px;
  color: var(--purple-main);
}

.ranking-state p {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--purple-muted);
}

.ranking-podium {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  align-items: end;
}

.podium-item {
  background: #FFFFFF;
  border: 2px solid #DCD0F5;
  border-radius: 13px;
  padding: 9px 7px;
  text-align: center;
}

.podium-item.rank-1 {
  background: linear-gradient(180deg, #FFFBEB 0%, #FEF3C7 100%);
  border-color: #F59E0B;
  order: 2;
}

.podium-item.rank-2 { order: 1; }
.podium-item.rank-3 { order: 3; }

.podium-medal { font-size: 12.5px; font-weight: 900; color: var(--purple-main); }
.podium-name { margin: 3px 0 2px; font-size: 13.5px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.podium-dist { font-size: 16px; font-weight: 900; color: var(--purple-deep); }
.podium-grade { font-size: 11px; font-weight: 700; color: #6B5796; }

.ranking-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rank-row {
  display: grid;
  grid-template-columns: 44px 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #FFFFFF;
  border: 1.5px solid #E5DAFA;
  font-size: 13px;
}

.rank-row.is-me {
  background: #EFE5FF;
  border-color: var(--purple-main);
}

.rank-num { font-weight: 900; color: var(--purple-main); }
.rank-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-tag { font-size: 11px; color: #826DAE; margin-left: 4px; }
.rank-dist { font-weight: 900; font-variant-numeric: tabular-nums; }
.rank-land { font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 999px; background: var(--panel-bg); border: 1px solid #D8C4FA; }
.rank-land.is-miss { background: #FFF1F2; color: #BE123C; border-color: #FDA4AF; }

.ranking-footer {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

/* Nickname Form — mobile keyboard safe scrolling */
.field-label { display: block; font-size: 13px; font-weight: 800; margin-bottom: 6px; }
.text-input {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  border: 2px solid #7553B2;
  border-radius: 11px;
  font-family: var(--font-main);
  font-size: 16px; /* Prevents iOS auto-zoom on focus! */
  font-weight: 700;
  color: var(--purple-deep);
  background: #FFFFFF;
}

.field-hint { margin: 6px 0 10px; font-size: 12px; color: var(--purple-muted); line-height: 1.42; }

.consent-box {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 11px;
  background: #FFFFFF;
  border: 1.5px solid #DCD0F5;
  border-radius: 11px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

.consent-box input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--purple-main); }
.field-sub-note { margin: 8px 0 0; font-size: 11.5px; color: #746299; line-height: 1.4; }
.form-error { margin: 8px 0 0; color: #BE123C; font-size: 12.5px; font-weight: 700; }

.modal-footer-inline {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(46, 26, 83, 0.94);
  color: #FFFFFF;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  z-index: 80;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  pointer-events: none;
}

/* ============================================================================
   MOBILE PORTRAIT ORIENTATION GATE ("화면을 가로로 돌려주세요!")
   ============================================================================ */
.rotate-overlay {
  position: fixed;
  inset: 0;
  z-index: 35; /* Below modals (z-index: 40) so Result & Ranking remain readable in portrait! */
  background: linear-gradient(180deg, #5B9AF2 0%, #8FC3FC 55%, #D9E9FF 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.rotate-card {
  background: var(--panel-bg);
  border: 2.5px solid var(--panel-border);
  border-radius: 20px;
  box-shadow: 0 6px 0 rgba(92, 59, 150, 0.34), 0 14px 30px rgba(32, 20, 68, 0.22);
  padding: 28px 24px;
  width: min(320px, 88vw);
  text-align: center;
}

.rotate-phone-wrap {
  width: 72px;
  height: 72px;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.rotate-phone-svg {
  width: 68px;
  height: 68px;
  animation: phoneTilt 2.1s ease-in-out infinite;
}

@keyframes phoneTilt {
  0%, 15%   { transform: rotate(0deg); }
  45%, 65%  { transform: rotate(-90deg); }
  90%, 100% { transform: rotate(0deg); }
}

@media (prefers-reduced-motion: reduce) {
  .rotate-phone-svg {
    animation: none;
    transform: rotate(-90deg);
  }
}

.rotate-title {
  margin: 0;
  font-size: 20px;
  font-weight: 900;
  color: var(--purple-deep);
  letter-spacing: -0.02em;
}

.rotate-sub {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--purple-muted);
  line-height: 1.48;
}
