* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --color-bg: #0F0F23;
  --color-surface: #161633;
  --color-primary: #7C3AED;
  --color-primary-light: #A78BFA;
  --color-accent: #F43F5E;
  --color-text: #E2E8F0;
  --color-text-secondary: #94A3B8;
  --color-text-muted: #64748B;
  --color-border: #2D2D5E;
  --color-success: #6EE7B7;
  --font-display: 'Orbitron', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-body: -apple-system, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: var(--font-body);
  background: var(--color-bg);
  color: var(--color-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#app {
  width: 100%;
  height: 100%;
  position: relative;
}

/* --- Screens --- */
.screen {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
.screen.active {
  opacity: 1;
  pointer-events: auto;
}

/* --- Menu --- */
.menu-content {
  text-align: center;
}
.game-title {
  font-family: var(--font-display);
  font-size: 44px;
  font-weight: 900;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 12px;
  text-shadow: 0 0 40px rgba(124, 58, 237, 0.3);
}
.game-subtitle {
  color: var(--color-text-muted);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: 2px;
  margin-bottom: 56px;
}
.menu-btn {
  display: block;
  width: 220px;
  margin: 10px auto;
  padding: 16px 0;
  border: none;
  border-radius: 14px;
  font-family: var(--font-body);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(135deg, var(--color-primary), #9333EA);
  color: white;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.3);
}
.menu-btn:active { transform: scale(0.96); }
.menu-btn.secondary {
  background: transparent;
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  box-shadow: none;
}
.menu-btn.small {
  width: auto;
  padding: 12px 28px;
  font-size: 15px;
}

/* --- Level Select --- */
.screen-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  padding: 16px;
  gap: 12px;
}
.screen-header h2 {
  font-size: 20px;
  font-weight: 700;
}
.back-btn {
  background: none;
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  width: 40px; height: 40px;
  border-radius: 10px;
  font-size: 20px;
  cursor: pointer;
}
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, 56px);
  gap: 12px;
  padding: 80px 20px 20px;
  max-height: 100%;
  overflow-y: auto;
}
.level-cell {
  width: 56px; height: 56px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  background: var(--color-surface);
  transition: transform 0.1s;
}
.level-cell:active { transform: scale(0.92); }
.level-cell.passed {
  border-color: var(--color-primary);
  color: var(--color-primary-light);
  background: rgba(124, 58, 237, 0.12);
}
.level-cell.current {
  border-color: var(--color-primary);
  color: #fff;
  background: linear-gradient(135deg, var(--color-primary), #9333EA);
  box-shadow: 0 0 16px rgba(124, 58, 237, 0.4);
}
.level-cell.locked {
  color: #2D2D5E;
  cursor: default;
}
.level-cell.skipped {
  border-color: #F59E0B;
  color: #FBBF24;
  background: rgba(245, 158, 11, 0.1);
}

/* --- Game Screen --- */
#game-area {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}
.game-top {
  text-align: center;
  margin-bottom: 12px;
}
.level-label {
  font-family: var(--font-display);
  font-size: 13px;
  letter-spacing: 6px;
  color: var(--color-text-muted);
  text-transform: uppercase;
}
.level-num {
  font-family: var(--font-display);
  font-size: 42px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 0 20px rgba(124, 58, 237, 0.4);
}
.instruction {
  text-align: center;
  font-size: 20px;
  font-weight: 500;
  color: var(--color-text-secondary);
  margin-bottom: 36px;
  min-height: 30px;
  transition: color 0.3s;
}

/* --- The Button (280x280 container) --- */
.btn-container {
  position: relative;
  width: 280px;
  height: 280px;
}
.progress-ring {
  position: absolute;
  top: 0; left: 0;
  width: 280px; height: 280px;
}
.ring-bg {
  fill: none;
  stroke: var(--color-surface);
  stroke-width: 5;
}
.ring-fill {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 816.81;
  stroke-dashoffset: 816.81;
  transform: rotate(-90deg);
  transform-origin: center;
  transition: stroke-dashoffset 0.1s linear;
  filter: drop-shadow(0 0 6px rgba(124, 58, 237, 0.5));
}
.the-button {
  position: absolute;
  top: 16px; left: 16px;
  width: 248px; height: 248px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), #9333EA);
  color: white;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 50px rgba(124, 58, 237, 0.35), inset 0 -4px 12px rgba(0,0,0,0.2);
  transition: transform 0.08s, box-shadow 0.15s;
}
.the-button:active {
  transform: scale(0.96);
  box-shadow: 0 0 30px rgba(124, 58, 237, 0.5), inset 0 -2px 8px rgba(0,0,0,0.2);
}
.the-button.danger {
  background: linear-gradient(135deg, #F43F5E, #E11D48);
  box-shadow: 0 0 50px rgba(244, 63, 94, 0.35), inset 0 -4px 12px rgba(0,0,0,0.2);
}
.the-button.warning {
  background: linear-gradient(135deg, #FBBF24, #F59E0B);
  color: #1a1a2e;
  box-shadow: 0 0 50px rgba(251, 191, 36, 0.35), inset 0 -4px 12px rgba(0,0,0,0.2);
}
.the-button.ghost {
  opacity: 0;
}
.the-button.tiny {
  width: 36px !important; height: 36px !important;
  top: 122px !important; left: 122px !important;
  font-size: 12px;
}

.pass-rate {
  margin-top: 32px;
  font-size: 14px;
  color: var(--color-text-muted);
  font-weight: 500;
}
.pass-rate .rate-value {
  font-family: var(--font-mono);
  font-weight: 700;
}
.rate-easy { color: #6EE7B7; }
.rate-medium { color: #FBBF24; }
.rate-hard { color: #F87171; }

.timer-display {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 500;
  color: var(--color-text-muted);
  min-height: 22px;
  font-variant-numeric: tabular-nums;
}

/* --- Success Flash (auto-advance) --- */
.success-flash {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(15, 15, 35, 0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 120;
  animation: flashIn 0.3s ease;
}
.success-flash.hidden { display: none; }
.success-flash-icon {
  width: 80px; height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  background: rgba(110, 231, 183, 0.15);
  color: #6EE7B7;
  margin-bottom: 16px;
  box-shadow: 0 0 30px rgba(110, 231, 183, 0.3);
}
.success-flash-text {
  font-family: var(--font-body);
  font-size: 18px;
  font-weight: 600;
  color: var(--color-text-secondary);
}
@keyframes flashIn {
  from { opacity: 0; transform: scale(1.05); }
  to { opacity: 1; transform: scale(1); }
}

/* --- Result Screen (fail only) --- */
.result-content {
  text-align: center;
}
.result-icon {
  width: 88px; height: 88px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin: 0 auto 24px;
  background: rgba(124, 58, 237, 0.15);
  color: var(--color-primary-light);
}
.result-icon.fail {
  background: rgba(244, 63, 94, 0.15);
  color: var(--color-accent);
}
.result-title {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 10px;
}
.result-detail {
  color: var(--color-text-secondary);
  font-size: 15px;
  margin-bottom: 6px;
}
.result-rate {
  font-family: var(--font-mono);
  color: var(--color-text-muted);
  font-size: 14px;
  margin-bottom: 36px;
}
.result-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* --- Overlay --- */
.overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(15, 15, 35, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay.hidden { display: none; }
.overlay-content {
  text-align: center;
  color: var(--color-text);
}
.overlay-content p {
  font-family: var(--font-mono);
  font-size: 20px;
  margin-bottom: 20px;
  font-variant-numeric: tabular-nums;
}

/* --- Fake clone buttons for split trick --- */
.clone-button {
  position: absolute;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), #9333EA);
  color: white;
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 0 50px rgba(124, 58, 237, 0.35);
}

/* --- Fake crash overlay --- */
.fake-crash {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  color: #333;
  font-size: 15px;
}
.fake-crash-dialog {
  background: #f0f0f0;
  border: 1px solid #ccc;
  border-radius: 14px;
  padding: 28px;
  text-align: center;
  max-width: 300px;
}
.fake-crash-dialog h3 {
  margin-bottom: 10px;
  font-size: 17px;
}
.fake-crash-dialog p {
  color: #666;
  margin-bottom: 20px;
  font-size: 14px;
  line-height: 1.5;
}
.fake-crash-dialog button {
  background: #007AFF;
  color: white;
  border: none;
  padding: 10px 36px;
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
}

/* --- Utility --- */
.hidden { display: none !important; }

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.06); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}
.pulse { animation: pulse 1.2s infinite; }
.shake { animation: shake 0.3s; }

/* --- Responsive --- */
@media (max-height: 580px) {
  .game-top { margin-bottom: 4px; }
  .level-num { font-size: 32px; }
  .instruction { margin-bottom: 16px; font-size: 17px; }
  .btn-container { width: 200px; height: 200px; }
  .progress-ring { width: 200px; height: 200px; }
  .the-button { width: 172px; height: 172px; top: 14px; left: 14px; font-size: 24px; }
  .pass-rate { margin-top: 16px; }
}

@media (min-width: 500px) {
  .level-grid {
    grid-template-columns: repeat(10, 56px);
  }
}

/* --- Sound toggle --- */
.sound-toggle {
  position: fixed;
  top: 14px;
  right: 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  width: 40px; height: 40px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  z-index: 50;
}
