:root {
  --bg-deep: #0b1026;
  --bg-mid: #162048;
  --card-bg: rgba(20, 29, 64, 0.78);
  --card-border: rgba(255, 224, 130, 0.25);
  --text-main: #f7f4ff;
  --text-sub: #b8c2e8;
  --accent-gold: #ffd166;
  --accent-coral: #ff758f;
  --accent-mint: #64dfdf;
  --accent-lavender: #c7b8ff;
  --shadow-soft: 0 18px 44px rgba(5, 8, 22, 0.55);
  --font-ui: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, -apple-system, sans-serif;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 15%, rgba(114, 92, 214, 0.35), transparent 42%),
    radial-gradient(circle at 80% 80%, rgba(56, 178, 172, 0.2), transparent 45%),
    linear-gradient(180deg, #090e22 0%, #131c3d 55%, #1c244d 100%);
  color: var(--text-main);
  font-family: var(--font-ui);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.hidden {
  display: none !important;
}

/* ====== Overall Desktop + Mobile Layout ====== */
.app-shell {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 16px 24px;
}

.side-panel {
  width: 280px;
  max-height: min(820px, calc(100dvh - 32px));
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  scrollbar-width: none;
}
.side-panel::-webkit-scrollbar {
  display: none;
}

.panel-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 16px 18px;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-soft);
}

.eyebrow {
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--accent-gold);
  font-weight: 800;
  margin-bottom: 4px;
}

.side-title {
  margin: 0 0 8px;
  font-size: 26px;
  line-height: 1.18;
  background: linear-gradient(135deg, #fff4cc 0%, #ffd166 55%, #ff9eb5 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.side-lead {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-sub);
}

.card-heading {
  margin: 0 0 10px;
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--accent-gold);
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-heading::before {
  content: "✦";
  font-size: 12px;
}

.cast-list, .tips-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cast-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-sub);
}

.cast-list strong {
  display: block;
  color: var(--text-main);
  font-size: 13px;
  margin-bottom: 1px;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-top: 4px;
  flex-shrink: 0;
  box-shadow: 0 0 10px currentColor;
}
.dot-kohaku { background: #ff9f68; color: #ff9f68; }
.dot-mogu { background: #ffd166; color: #ffd166; }
.dot-luna { background: #c7b8ff; color: #c7b8ff; }

.tips-list li {
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-sub);
  padding-left: 14px;
  position: relative;
}
.tips-list li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--accent-mint);
  font-weight: 800;
}

.key-list {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.key-list > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}
.key-list dt {
  color: var(--text-sub);
}
.key-list dd {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
}

kbd {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 11px;
  font-family: inherit;
  color: #fff;
}

.record-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.1);
  font-size: 13px;
  color: var(--text-sub);
}
.record-row:last-child { border-bottom: none; }
.record-row strong {
  color: var(--accent-gold);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

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

.badge-chip {
  font-size: 11px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid rgba(255, 209, 102, 0.35);
  background: rgba(255, 209, 102, 0.14);
  color: #ffe8a3;
  font-weight: 700;
}
.badge-chip.locked {
  border-color: rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.35);
}

/* ====== Game Stage Frame ====== */
.stage-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  flex: 0 0 auto;
}

.stage-frame {
  position: relative;
  height: min(840px, calc(100dvh - 32px));
  aspect-ratio: 9 / 16;
  max-width: calc(100vw - 32px);
  border-radius: 28px;
  overflow: hidden;
  background: #0f1635;
  border: 2px solid rgba(255, 224, 130, 0.35);
  box-shadow:
    0 24px 64px rgba(3, 6, 18, 0.72),
    0 0 40px rgba(126, 105, 230, 0.2);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: pointer;
}

/* ====== HUD ====== */
.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 14px 8px;
  pointer-events: none;
  z-index: 5;
}

.hud-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 8px;
}

.hud-score-box {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.hud-center-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: rgba(13, 20, 48, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 14px;
  padding: 4px 12px 5px;
  backdrop-filter: blur(6px);
}

.hud-label {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: rgba(255, 240, 200, 0.78);
  font-weight: 800;
}

.hud-score {
  font-size: 26px;
  font-weight: 900;
  line-height: 1.05;
  color: #fff;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.55);
  font-variant-numeric: tabular-nums;
}

.hud-combo {
  min-height: 18px;
  font-size: 13px;
  font-weight: 900;
  color: var(--accent-gold);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.65);
  transition: transform 0.12s ease;
}
.hud-combo.pop {
  transform: scale(1.22);
}

.hud-timer {
  font-size: 22px;
  font-weight: 900;
  line-height: 1.1;
  color: #fff;
  font-variant-numeric: tabular-nums;
}
.hud-timer.urgent {
  color: #ff758f;
  animation: pulseUrgent 0.55s ease-in-out infinite alternate;
}

@keyframes pulseUrgent {
  from { transform: scale(1); }
  to { transform: scale(1.12); }
}

.hud-hearts {
  display: flex;
  gap: 4px;
  font-size: 18px;
  line-height: 1.2;
}

.hud-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  pointer-events: auto;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(14, 21, 50, 0.68);
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(6px);
  transition: transform 0.12s ease, background 0.15s ease;
}
.icon-btn:active {
  transform: scale(0.92);
}

.fever-bar-wrap {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.fever-bar-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(12, 16, 36, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

.fever-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #64dfdf 0%, #ffd166 55%, #ff758f 100%);
  transition: width 0.14s ease-out;
  box-shadow: 0 0 12px rgba(255, 209, 102, 0.7);
}
.fever-bar-fill.active {
  background: linear-gradient(90deg, #64dfdf, #c7b8ff, #ff758f, #ffd166);
  background-size: 200% 100%;
  animation: rainbowFlow 0.9s linear infinite;
}

@keyframes rainbowFlow {
  0% { background-position: 0% 50%; }
  100% { background-position: 200% 50%; }
}

.fever-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: #ffe8a3;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
  min-width: 64px;
  text-align: right;
}

/* ====== Mobile Spin FAB ====== */
.dash-fab {
  position: absolute;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid rgba(255, 224, 130, 0.75);
  background: radial-gradient(circle at 30% 25%, #ffe694, #ff9f43 70%, #e85d75 100%);
  color: #1c1330;
  box-shadow: 0 8px 24px rgba(255, 145, 77, 0.45);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 6;
  transition: transform 0.12s ease, opacity 0.2s ease, filter 0.2s ease;
}
.dash-fab:active {
  transform: scale(0.9);
}
.dash-fab.used {
  opacity: 0.42;
  filter: grayscale(0.7);
}
.dash-fab-icon {
  font-size: 20px;
  line-height: 1;
}
.dash-fab-text {
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

/* ====== Banners ====== */
.countdown-banner {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 84px;
  font-weight: 900;
  color: #fff6cf;
  text-shadow: 0 6px 28px rgba(255, 195, 70, 0.75), 0 4px 0 #5b3b8c;
  pointer-events: none;
  z-index: 9;
  animation: popIn 0.35s cubic-bezier(0.22, 1.4, 0.36, 1);
}

.fever-banner {
  position: absolute;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  padding: 7px 18px;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(100, 223, 223, 0.92), rgba(199, 184, 255, 0.94), rgba(255, 117, 143, 0.92));
  color: #161433;
  font-weight: 900;
  font-size: 14px;
  letter-spacing: 0.08em;
  white-space: nowrap;
  box-shadow: 0 6px 24px rgba(199, 184, 255, 0.55);
  pointer-events: none;
  z-index: 7;
  animation: feverFloat 0.6s ease-in-out infinite alternate;
}

@keyframes feverFloat {
  from { transform: translate(-50%, 0); }
  to { transform: translate(-50%, -4px); }
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.55); }
  to { opacity: 1; transform: scale(1); }
}

/* ====== Overlays ====== */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(20px + env(safe-area-inset-top, 0px)) 20px calc(22px + env(safe-area-inset-bottom, 0px));
  z-index: 10;
}

.overlay-title {
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(11, 16, 40, 0.68) 0%, rgba(11, 16, 40, 0.18) 46%, rgba(11, 16, 40, 0.82) 100%);
}

.back-portal-link {
  position: absolute;
  top: calc(12px + env(safe-area-inset-top, 0px));
  left: 14px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(15, 22, 54, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #dce4ff;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, color 0.15s ease;
}
.back-portal-link:hover {
  background: rgba(255, 209, 102, 0.22);
  color: #fff6cf;
}

.overlay-modal {
  background: rgba(8, 12, 30, 0.72);
  backdrop-filter: blur(8px);
}

.title-hero {
  text-align: center;
  margin-top: 14px;
}

.title-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
  color: var(--accent-gold);
  background: rgba(16, 24, 58, 0.72);
  border: 1px solid rgba(255, 209, 102, 0.4);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 10px;
}

.game-logo {
  margin: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.08;
  filter: drop-shadow(0 6px 18px rgba(10, 12, 36, 0.75));
}

.logo-top {
  font-size: 28px;
  font-weight: 900;
  color: #fff6cf;
  letter-spacing: 0.14em;
}

.logo-main {
  font-size: 40px;
  font-weight: 900;
  background: linear-gradient(180deg, #ffffff 0%, #ffe082 55%, #ff9eb5 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.title-sub {
  margin: 10px 0 0;
  font-size: 13px;
  color: #e6ebff;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.7);
}

.title-card, .modal-card {
  width: 100%;
  max-width: 340px;
  background: rgba(18, 26, 58, 0.86);
  border: 1.5px solid rgba(255, 224, 130, 0.34);
  border-radius: 24px;
  padding: 18px;
  backdrop-filter: blur(12px);
  box-shadow: 0 20px 50px rgba(4, 7, 20, 0.65);
  text-align: center;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.mode-btn {
  padding: 10px 8px;
  border-radius: 14px;
  border: 1.5px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-sub);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-family: inherit;
  transition: all 0.16s ease;
}
.mode-btn strong {
  font-size: 13px;
  color: var(--text-main);
}
.mode-btn span {
  font-size: 10px;
}
.mode-btn.active {
  border-color: var(--accent-gold);
  background: rgba(255, 209, 102, 0.18);
  box-shadow: 0 0 18px rgba(255, 209, 102, 0.24);
}
.mode-btn.active strong {
  color: #fff6cf;
}

.best-strip {
  display: flex;
  justify-content: space-around;
  padding: 7px 10px;
  border-radius: 12px;
  background: rgba(8, 13, 32, 0.5);
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 12px;
}
.best-strip strong {
  color: var(--accent-gold);
  font-variant-numeric: tabular-nums;
}

.btn-primary, .btn-secondary, .btn-ghost {
  width: 100%;
  border: none;
  border-radius: 16px;
  font-family: inherit;
  font-weight: 900;
  cursor: pointer;
  transition: transform 0.12s ease, filter 0.15s ease;
}
.btn-primary:active, .btn-secondary:active, .btn-ghost:active {
  transform: translateY(2px) scale(0.98);
}

.btn-primary {
  padding: 14px 18px;
  font-size: 18px;
  color: #1f1436;
  background: linear-gradient(180deg, #ffe787 0%, #ffc44d 55%, #ff9f43 100%);
  box-shadow: 0 5px 0 #b8621d, 0 10px 26px rgba(255, 179, 71, 0.42);
}

.btn-secondary {
  padding: 12px 16px;
  font-size: 15px;
  color: #fff;
  background: linear-gradient(180deg, #5d6bc4 0%, #4450a3 100%);
  box-shadow: 0 4px 0 #2b3370;
}

.btn-ghost {
  padding: 11px 16px;
  font-size: 14px;
  color: var(--text-sub);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.audio-toggles {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.toggle-chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-sub);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.toggle-chip.active {
  border-color: rgba(100, 223, 223, 0.6);
  background: rgba(100, 223, 223, 0.16);
  color: #dffefe;
}

.mini-controls-hint {
  margin: 12px 0 0;
  font-size: 11px;
  line-height: 1.5;
  color: rgba(206, 214, 245, 0.8);
}

/* ====== Modal & Result ====== */
.modal-title {
  margin: 0 0 10px;
  font-size: 22px;
  color: #fff6cf;
}

.modal-buttons {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-rank-badge {
  width: 68px;
  height: 68px;
  margin: -42px auto 8px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  font-weight: 900;
  color: #201238;
  background: linear-gradient(135deg, #fff3b0 0%, #ffd166 55%, #ff8fab 100%);
  border: 3px solid #fff;
  box-shadow: 0 8px 24px rgba(255, 209, 102, 0.55);
}

.new-record-tag {
  display: inline-block;
  margin-bottom: 8px;
  padding: 3px 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff758f, #ffd166);
  color: #1f1133;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.08em;
}

.result-score-main {
  padding: 10px;
  border-radius: 16px;
  background: rgba(9, 14, 34, 0.58);
  margin-bottom: 10px;
}
.result-score-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--text-sub);
}
.result-score-num {
  font-size: 36px;
  font-weight: 900;
  color: var(--accent-gold);
  font-variant-numeric: tabular-nums;
}

.result-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat-pill {
  padding: 8px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-pill span {
  font-size: 11px;
  color: var(--text-sub);
}
.stat-pill strong {
  font-size: 17px;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.result-badge-unlock {
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(100, 223, 223, 0.55);
  background: rgba(100, 223, 223, 0.14);
  font-size: 12px;
}
.result-badge-unlock span {
  display: block;
  color: var(--accent-mint);
  font-size: 10px;
  font-weight: 800;
}
.result-badge-unlock strong {
  color: #fff;
  font-size: 14px;
}

/* ====== Responsive Breakpoints ====== */
@media (max-width: 1120px) {
  .side-panel {
    width: 230px;
  }
}

@media (max-width: 900px) {
  .side-panel {
    display: none;
  }
  .app-shell {
    padding: 0;
  }
  .stage-wrap {
    width: 100%;
    height: 100%;
  }
  .stage-frame {
    width: 100%;
    height: 100%;
    max-width: 100%;
    aspect-ratio: auto;
    border-radius: 0;
    border: none;
    box-shadow: none;
  }
}
