/* ============================================================
   RHYTHM RING · DESIGN SYSTEM & STYLESHEET
   Knotrix-grade responsive layout, floating panels, pill buttons,
   deep forest green and gold palette, and card modals.
   ============================================================ */

:root {
  --bg: #22403a;
  --panel: rgba(34, 48, 44, 0.94);
  --panel-border: rgba(240, 180, 41, 0.28);
  --ink: #f2e8d5;
  --ink-dim: rgba(242, 232, 213, 0.65);
  --gold: #f0b429;
  --gold-glow: rgba(240, 180, 41, 0.45);
  --red: #d64545;
  --green: #4c9a52;
  --font-main: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius-sm: 12px;
  --radius-md: 18px;
  --radius-pill: 9999px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font-main);
  color: var(--ink);
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ==================== PRELOADER ==================== */
#preloader {
  position: fixed;
  inset: 0;
  background: #182e2a;
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  transition: opacity 0.4s ease, visibility 0.4s ease;
}

#preloader.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  display: none !important;
}

.logo-wrap {
  width: 90px;
  height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-ring-img {
  width: 84px;
  height: 84px;
  object-fit: contain;
  filter: drop-shadow(0 0 16px var(--gold-glow));
}

.spin-anim {
  animation: spinRing 6s linear infinite;
}

@keyframes spinRing {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.pulse-anim {
  animation: pulseScale 2.8s ease-in-out infinite alternate;
}

@keyframes pulseScale {
  0% { transform: scale(0.95); filter: drop-shadow(0 0 8px rgba(240, 180, 41, 0.3)); }
  100% { transform: scale(1.05); filter: drop-shadow(0 0 20px rgba(240, 180, 41, 0.7)); }
}

#preloader h1 {
  font-size: 2.4rem;
  letter-spacing: 6px;
  font-weight: 900;
  color: var(--gold);
}

#preloader p {
  font-size: 0.95rem;
  color: var(--ink-dim);
  max-width: 300px;
  text-align: center;
  min-height: 40px;
}

.bar-track {
  width: 200px;
  height: 6px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--gold), #ffda6b);
  transition: width 0.1s linear;
}

/* ==================== TOPBAR ==================== */
#topbar {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  left: 14px;
  right: 14px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  pointer-events: auto;
}

.top-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  padding: 0;
  outline: none;
}

.icon-btn:hover {
  background: var(--panel-hover);
  border-color: rgba(240, 180, 41, 0.4);
}

.icon-btn:active {
  transform: scale(0.92);
}

.ui-icon-img {
  width: 24px;
  height: 24px;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.35));
}

#levelLabel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 4px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.hud-title {
  font-size: clamp(0.74rem, 2.5vw, 0.86rem);
  font-weight: 800;
  letter-spacing: 0.4px;
  color: var(--ink);
  white-space: nowrap;
}

.hud-title span {
  color: var(--gold);
}

.hud-score {
  font-size: clamp(0.66rem, 2vw, 0.72rem);
  font-weight: 600;
  color: var(--ink-dim);
  white-space: nowrap;
}

.hud-score b {
  color: var(--gold);
}

.combo-tag {
  color: #ffda6b;
  font-weight: 800;
  margin-left: 4px;
}

/* ==================== STAGE ==================== */
#stage {
  flex: 1;
  width: 100%;
  height: 100%;
  position: relative;
}

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

/* ==================== BOTTOMBAR ==================== */
#bottombar {
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 14px;
  right: 14px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
  pointer-events: auto;
}

.bottom-stat {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 90px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--ink-dim);
  text-transform: uppercase;
}

.stat-val {
  font-size: 0.8rem;
  font-weight: 800;
  color: var(--ink);
}

.dhol-row {
  display: flex;
  gap: 6px;
  margin-top: 3px;
}

.dhol-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  transition: all 0.2s ease;
}

.dhol-dot.active {
  background: var(--gold);
  box-shadow: 0 0 6px var(--gold-glow);
}

.dhol-dot.lost {
  background: rgba(255, 255, 255, 0.15);
  transform: scale(0.75);
}

.dhol-icon {
  width: 18px;
  height: 18px;
  object-fit: contain;
  transition: transform 0.2s ease, opacity 0.2s ease, filter 0.2s ease;
}

.dhol-icon.active {
  filter: drop-shadow(0 0 6px var(--gold-glow));
}

.dhol-icon.lost {
  opacity: 0.3;
  transform: scale(0.85);
  filter: grayscale(80%);
}

.pill-btn {
  height: 48px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  font-weight: 800;
  font-size: clamp(0.76rem, 2.4vw, 0.9rem);
  letter-spacing: 0.3px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  outline: none;
}

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

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

.pill-btn.primary {
  background: linear-gradient(135deg, var(--gold), #c99318);
  color: #1a1608;
  border: none;
  box-shadow: 0 6px 18px var(--gold-glow);
}

.pill-btn.primary:hover {
  box-shadow: 0 8px 22px var(--gold-glow);
}

.btn-icon-img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  pointer-events: none;
}

/* ==================== OVERLAYS / MODALS ==================== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(18, 30, 27, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
}

.overlay.show {
  opacity: 1;
  visibility: visible;
}

.card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  box-shadow: var(--shadow);
  animation: popUp 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes popUp {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.card h2 {
  font-size: 1.4rem;
  font-weight: 900;
  color: var(--ink);
}

.subtitle {
  font-size: 0.88rem;
  color: var(--ink-dim);
}

.howto-card {
  max-width: 420px;
}

.howto-row {
  display: flex;
  align-items: center;
  gap: 14px;
  text-align: left;
  width: 100%;
}

.howto-icon-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.45));
}

.howto-row strong {
  display: block;
  font-size: 0.92rem;
  color: var(--ink);
  margin-bottom: 2px;
}

.howto-row p {
  font-size: 0.8rem;
  color: var(--ink-dim);
  line-height: 1.35;
}

.cta {
  width: 100%;
  height: 50px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, var(--gold), #c99318);
  border: none;
  color: #1a1608;
  font-weight: 900;
  font-size: 1.05rem;
  letter-spacing: 0.5px;
  cursor: pointer;
  box-shadow: 0 6px 18px var(--gold-glow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  outline: none;
}

.cta:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px var(--gold-glow);
}

.cta:active {
  transform: scale(0.96);
}

.cta.secondary {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.cta.secondary:hover {
  background: var(--panel-hover);
}

.cta-icon-img {
  width: 22px;
  height: 22px;
  object-fit: contain;
  pointer-events: none;
}

/* Levels Grid */
.levels-card {
  max-width: 420px;
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  width: 100%;
  max-height: 380px;
  overflow-y: auto;
  padding: 6px;
  scrollbar-width: thin;
  scrollbar-color: rgba(240, 180, 41, 0.4) transparent;
}

.levels-grid::-webkit-scrollbar {
  width: 5px;
}

.levels-grid::-webkit-scrollbar-thumb {
  background: rgba(240, 180, 41, 0.4);
  border-radius: 4px;
}

.level-plate {
  aspect-ratio: 1;
  background: rgba(45, 62, 57, 0.7);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.level-plate:active {
  transform: scale(0.92);
}

.level-plate.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.level-plate.current {
  border-color: var(--gold);
  box-shadow: 0 0 10px var(--gold-glow);
}

.lvl-num {
  font-size: 1.1rem;
  font-weight: 900;
}

.lvl-name {
  font-size: 0.62rem;
  color: var(--ink-dim);
}

.lvl-stars {
  font-size: 0.7rem;
  color: var(--gold);
}

.lvl-stars-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  margin-top: 3px;
}

.grid-star-icon {
  width: 13px;
  height: 13px;
  object-fit: contain;
}

.grid-lock-icon {
  width: 15px;
  height: 15px;
  object-fit: contain;
  opacity: 0.65;
}

/* Stars Row in Win Modal */
.stars-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: center;
  margin: 6px 0;
}

.win-star-img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  transition: transform 0.3s ease;
}

.win-star-img.earned {
  filter: drop-shadow(0 0 12px var(--gold-glow));
  animation: starPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.star-icon.earned {
  color: var(--gold);
  text-shadow: 0 0 14px var(--gold-glow);
  animation: starPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes starPop {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

.win-btns {
  display: flex;
  gap: 10px;
  width: 100%;
}

.win-btns .pill-btn {
  flex: 1;
  padding: 0 8px;
}

.fail-btns {
  display: flex;
  gap: 10px;
  width: 100%;
}

.fail-btns .pill-btn {
  flex: 1;
  padding: 0 8px;
}

/* ==================== MENU & PAUSE CARDS ==================== */
.menu-card {
  max-width: 360px;
  padding: 30px 22px;
  gap: 16px;
}

.menu-logo-wrap {
  width: 88px;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.menu-logo-img {
  width: 82px;
  height: 82px;
  object-fit: contain;
  filter: drop-shadow(0 0 16px var(--gold-glow));
}

.menu-stats-pill {
  display: flex;
  justify-content: space-between;
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.8rem;
  color: var(--ink-dim);
}

.menu-stats-pill b {
  color: var(--gold);
}

.menu-btn-stack, .pause-btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.menu-grid-2x2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 100%;
}

.menu-sub-btn {
  height: 48px;
  font-size: 0.88rem;
  padding: 0 8px;
  gap: 8px;
}

/* Settings Modal */
.settings-card {
  max-width: 380px;
  gap: 16px;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  margin: 6px 0;
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: var(--ink);
  font-weight: 700;
}

.toggle-btn {
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  color: var(--gold);
  font-weight: 800;
  font-size: 0.85rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
  outline: none;
}

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

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

.pill-btn.danger {
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
  height: 38px;
  padding: 0 12px;
}

/* ==================== TOAST & CONFETTI ==================== */
#confettiCanvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 150;
}

.toast {
  position: fixed;
  left: 50%;
  top: 76px;
  transform: translateX(-50%) translateY(-10px);
  background: rgba(34, 48, 44, 0.95);
  backdrop-filter: blur(6px);
  border: 1px solid var(--panel-border);
  color: var(--ink);
  padding: 10px 22px;
  border-radius: var(--radius-pill);
  font-weight: 700;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 250;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
