:root {
  --bg-dark: #080c14;
  --bg-surface: #0f172a;
  --card-bg: rgba(15, 23, 42, 0.78);
  --card-border: rgba(255, 255, 255, 0.1);
  --accent-cyan: #06b6d4;
  --accent-violet: #8b5cf6;
  --accent-pink: #ec4899;
  --accent-gold: #f59e0b;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(6, 182, 212, 0.14), transparent 50%),
    radial-gradient(circle at 85% 85%, rgba(236, 72, 153, 0.12), transparent 50%);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  padding: 16px;
}

#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

.app-container {
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  position: relative;
  z-index: 1;
}

/* Nav Header */
.top-nav {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--card-border);
  border-radius: 99px;
  backdrop-filter: blur(12px);
  font-size: 0.85rem;
  font-weight: 700;
}

.nav-home-link {
  color: #ffffff;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.2s;
}

.nav-home-link:hover {
  opacity: 0.8;
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(6, 182, 212, 0.15);
  border: 1px solid rgba(6, 182, 212, 0.4);
  color: #38bdf8;
  padding: 3px 12px;
  border-radius: 99px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.15rem;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
}

.btn-icon:hover {
  color: #ffffff;
}

/* Header & 5-Round Gauntlet Stepper */
.game-header {
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.game-title-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-title {
  font-size: clamp(2rem, 6vw, 2.4rem);
  font-weight: 900;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #ffffff 40%, #38bdf8 80%, var(--accent-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1.15;
}

.game-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  max-width: 440px;
  line-height: 1.4;
}

/* 5-Round Progress Stepper */
.gauntlet-stepper {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 6px 0;
}

.round-step {
  flex: 1;
  padding: 6px 4px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.68rem;
  font-weight: 800;
  color: var(--text-muted);
  transition: all 0.25s ease;
}

.round-step.active {
  background: rgba(6, 182, 212, 0.2);
  border-color: var(--accent-cyan);
  color: #ffffff;
  box-shadow: 0 0 16px rgba(6, 182, 212, 0.35);
  transform: translateY(-2px);
}

.round-step.completed {
  background: rgba(16, 185, 129, 0.16);
  border-color: rgba(16, 185, 129, 0.5);
  color: #34d399;
}

.round-step-num {
  font-size: 0.74rem;
  letter-spacing: 0.5px;
}

.round-step-sub {
  font-size: 0.62rem;
  opacity: 0.85;
}

/* Glass Main Panel */
.glass-panel {
  width: 100%;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 22px;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  padding: clamp(16px, 3vh, 22px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* Stats Banner */
.stats-banner {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 14px;
  padding: 10px 14px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  font-weight: 700;
}

.stat-val {
  font-size: 1.05rem;
  font-weight: 800;
  color: #ffffff;
}

.stat-val.highlight {
  color: var(--accent-cyan);
}

.stat-val.gold {
  color: var(--accent-gold);
}

/* Canvas Area */
.canvas-wrapper {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 440px;
  position: relative;
  touch-action: none;
}

#slice-canvas {
  width: 100%;
  height: 100%;
  border-radius: 18px;
  background: radial-gradient(circle at 50% 50%, rgba(30, 41, 59, 0.45), rgba(15, 23, 42, 0.95));
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.6);
  cursor: crosshair;
}

.canvas-hint {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.88);
  padding: 5px 14px;
  border-radius: 99px;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-muted);
  pointer-events: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  white-space: nowrap;
}

/* Cut Preview Action Bar */
.preview-action-bar {
  width: 100%;
  display: none;
  gap: 10px;
  animation: fadeIn 0.2s ease;
}

.preview-action-bar.visible {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.btn {
  font-family: inherit;
  font-weight: 800;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s ease;
  text-decoration: none;
  font-size: 0.95rem;
  padding: 13px 20px;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, #06b6d4 0%, #3b82f6 100%);
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(6, 182, 212, 0.35);
}

.btn-primary:hover {
  box-shadow: 0 8px 26px rgba(6, 182, 212, 0.5);
  transform: translateY(-1px);
}

.btn-gold {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  color: #ffffff;
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.35);
}

.btn-gold:hover {
  box-shadow: 0 8px 26px rgba(245, 158, 11, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 12, 20, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 460px;
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 24px;
  padding: clamp(20px, 4vh, 28px);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.75);
  transform: translateY(12px) scale(0.96);
  transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-overlay.active .modal-card {
  transform: translateY(0) scale(1);
}

.modal-icon-orb {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
  background: rgba(6, 182, 212, 0.15);
  border: 2px solid var(--accent-cyan);
  box-shadow: 0 0 24px rgba(6, 182, 212, 0.35);
}

.modal-icon-orb.crown {
  background: radial-gradient(circle at 35% 35%, #fbbf24, #f59e0b 60%, #b45309);
  border-color: #fbbf24;
  box-shadow: 0 0 35px rgba(245, 158, 11, 0.6);
  animation: pulse-crown 2.5s infinite ease-in-out;
}

@keyframes pulse-crown {
  0%, 100% { transform: scale(1); box-shadow: 0 0 30px rgba(245, 158, 11, 0.5); }
  50% { transform: scale(1.05); box-shadow: 0 0 50px rgba(245, 158, 11, 0.7); }
}

.modal-icon-orb.fail {
  background: rgba(239, 68, 68, 0.15);
  border-color: var(--accent-red);
  box-shadow: 0 0 24px rgba(239, 68, 68, 0.35);
}

.modal-title {
  font-size: 1.6rem;
  font-weight: 900;
  color: #ffffff;
  letter-spacing: -0.5px;
}

.modal-desc {
  font-size: 0.92rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Rank Badge in Modal */
.rank-badge-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fbbf24;
  padding: 6px 16px;
  border-radius: 99px;
  font-size: 0.9rem;
  font-weight: 900;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.results-rounds-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 14px;
  padding: 10px;
}

.results-round-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  padding: 4px 6px;
  border-radius: 6px;
}

.results-round-row:nth-child(even) {
  background: rgba(255, 255, 255, 0.03);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(50px);
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid var(--accent-cyan);
  color: #fff;
  padding: 8px 18px;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 700;
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 10000;
  pointer-events: none;
}

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