/* ============================================================
   RESET & VARIABLES
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-from:    #0f0c29;
  --bg-mid:     #302b63;
  --bg-to:      #24243e;

  --glass-bg:      rgba(255, 255, 255, 0.06);
  --glass-border:  rgba(255, 255, 255, 0.10);
  --glass-blur:    blur(16px);
  --glass-radius:  16px;

  --accent:        #6366f1;
  --accent-blue:   #3b82f6;
  --accent-purple: #8b5cf6;

  --text-primary:   #e2e8f0;
  --text-secondary: #94a3b8;
  --text-accent:    #a5b4fc;

  --green:   #4ade80;
  --yellow:  #fbbf24;
  --orange:  #fb923c;
  --red:     #f87171;

  --blob-color-1: #6366f1;
  --blob-color-2: #3b82f6;
  --blob-color-3: #8b5cf6;
}

/* ============================================================
   BASE
   ============================================================ */
html {
  scroll-behavior: smooth;
}

body {
  background: linear-gradient(135deg, var(--bg-from) 0%, var(--bg-mid) 50%, var(--bg-to) 100%);
  min-height: 100vh;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text-primary);
  overflow-x: hidden;
  position: relative;
}

/* ============================================================
   BACKGROUND BLOBS
   ============================================================ */
.bg-blobs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.bg-blobs span {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.15;
  animation: float 20s ease-in-out infinite alternate;
}

.b1 {
  width: 500px;
  height: 500px;
  background: var(--blob-color-1);
  top: -100px;
  left: -100px;
}

.b2 {
  width: 400px;
  height: 400px;
  background: var(--blob-color-2);
  bottom: 200px;
  right: -80px;
  animation-delay: -7s;
}

.b3 {
  width: 300px;
  height: 300px;
  background: var(--blob-color-3);
  top: 50%;
  left: 40%;
  animation-delay: -14s;
}

@keyframes float {
  0%   { transform: translate(0, 0) scale(1); }
  33%  { transform: translate(30px, -40px) scale(1.05); }
  66%  { transform: translate(-20px, 20px) scale(0.95); }
  100% { transform: translate(40px, 10px) scale(1.02); }
}

/* ============================================================
   CRITICAL BANNER
   ============================================================ */
.critical-banner {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background: rgba(220, 38, 38, 0.9);
  backdrop-filter: blur(8px);
  color: white;
  text-align: center;
  padding: 10px 20px;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
  animation: pulse-banner 1s ease-in-out infinite;
}

@keyframes pulse-banner {
  0%, 100% { opacity: 0.9; }
  50%       { opacity: 1; }
}

body.state-critical .critical-banner {
  display: block;
}

/* ============================================================
   APP CONTAINER
   ============================================================ */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 680px;
  margin: 0 auto;
  padding: 40px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

body.state-critical .app-container {
  padding-top: 80px;
}

/* ============================================================
   GLASSMORPHISM
   ============================================================ */
.glass {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--glass-radius);
}

/* ============================================================
   HERO HEADER
   ============================================================ */
.hero {
  text-align: center;
  padding: 20px 0 10px;
}

.hero h1 {
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 800;
  background: linear-gradient(135deg, #e2e8f0 0%, var(--text-accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: 12px;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  padding: 6px 14px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  display: inline-block;
}

.dot.pulse {
  animation: dot-pulse 2s ease-in-out infinite;
}

@keyframes dot-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}

/* ============================================================
   RESULT CARD
   ============================================================ */
.result-card {
  padding: 32px 24px 24px;
  text-align: center;
  transition: box-shadow 0.4s ease, border-color 0.4s ease;
}

body.state-critical .result-card {
  box-shadow: 0 0 40px rgba(220, 38, 38, 0.4);
  border-color: rgba(220, 38, 38, 0.3);
  animation: pulse-border 1.2s ease-in-out infinite;
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 40px rgba(220, 38, 38, 0.4); }
  50%       { box-shadow: 0 0 70px rgba(220, 38, 38, 0.7); }
}

/* Gauge */
.gauge-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.gauge {
  width: 220px;
  height: auto;
  overflow: visible;
}

.gauge-center {
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  line-height: 1;
}

.score-number {
  display: block;
  font-size: 2.8rem;
  font-weight: 800;
  color: var(--text-primary);
  transition: color 0.4s ease;
}

.score-label {
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

body.state-critical .score-number {
  animation: pulse-number 0.8s ease-in-out infinite;
}

@keyframes pulse-number {
  0%, 100% { color: var(--text-primary); }
  50%       { color: var(--red); }
}

/* Verdict */
.verdict {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 12px;
}

.verdict-emoji {
  font-size: 2rem;
}

.verdict-text {
  font-size: clamp(1.3rem, 5vw, 1.8rem);
  font-weight: 800;
  color: var(--text-primary);
  transition: color 0.4s ease;
}

/* Verdict color states */
#verdictBox.verdict--yes    .verdict-text { color: var(--green); }
#verdictBox.verdict--caution .verdict-text { color: var(--yellow); }
#verdictBox.verdict--hold   .verdict-text { color: var(--orange); }
#verdictBox.verdict--no     .verdict-text { color: var(--red); }

.verdict-pop {
  animation: verdict-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes verdict-pop {
  0%   { transform: scale(0.92); }
  60%  { transform: scale(1.05); }
  100% { transform: scale(1); }
}

/* Reasoning */
.reasoning-text {
  color: var(--text-secondary);
  font-size: 0.92rem;
  line-height: 1.6;
  max-width: 480px;
  margin: 0 auto 16px;
}

/* Best time banner */
.best-time-banner {
  background: rgba(99, 102, 241, 0.15);
  border: 1px solid rgba(99, 102, 241, 0.3);
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 0.88rem;
  color: var(--text-accent);
}

.best-time-banner strong {
  color: var(--text-primary);
}

/* ============================================================
   CONTROLS CARD
   ============================================================ */
.controls-card {
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  animation: fadeInUp 0.5s ease;
}

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

/* Input group */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.inline-group {
  flex-direction: row;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.inline-group .toggle-strip {
  margin-left: auto;
}

.input-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: rgba(148, 163, 184, 0.7);
  font-size: 0.78rem;
}

/* Pill grid / row */
.pill-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle-strip {
  display: flex;
  gap: 8px;
}

/* Pill buttons */
.pill {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.83rem;
  font-family: inherit;
  transition: all 0.18s ease;
  white-space: nowrap;
  line-height: 1.4;
}

.pill:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.28);
}

.pill.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 0 14px rgba(99, 102, 241, 0.45);
}

/* Emoji strip (urgency) */
.emoji-strip {
  display: flex;
  gap: 10px;
}

.emoji-btn {
  flex: 1;
  padding: 14px 8px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  font-size: 1.5rem;
  text-align: center;
  transition: all 0.18s ease;
  line-height: 1.2;
}

.emoji-btn small {
  display: block;
  font-size: 0.7rem;
  margin-top: 4px;
  color: var(--text-secondary);
}

.emoji-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.28);
  color: var(--text-primary);
}

.emoji-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  box-shadow: 0 0 14px rgba(99, 102, 241, 0.45);
}

.emoji-btn.selected small {
  color: rgba(255, 255, 255, 0.8);
}

/* Sliders */
.slider-val {
  color: var(--text-accent);
  font-weight: 700;
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform 0.15s ease;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.55);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.25);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.55);
}

.slider-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.info-card {
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-label {
  font-size: 0.68rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
}

.card-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

/* ============================================================
   CHART CARD
   ============================================================ */
.chart-card {
  padding: 20px 20px 16px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.best-time-badge {
  background: rgba(74, 222, 128, 0.2);
  border: 1px solid rgba(74, 222, 128, 0.4);
  color: var(--green);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

#safetyChart {
  width: 100%;
  display: block;
  border-radius: 8px;
}

/* ============================================================
   FOOTER
   ============================================================ */
footer {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.82rem;
  padding-top: 10px;
  line-height: 1.8;
}

footer a {
  color: var(--text-accent);
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

.footer-sub {
  opacity: 0.6;
}

/* ============================================================
   HERO ROW
   ============================================================ */
.hero-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ============================================================
   ROULETTE BUTTON
   ============================================================ */
.roulette-btn {
  padding: 7px 16px;
  border-radius: 999px;
  border: 1px solid rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.1);
  color: #fbbf24;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.roulette-btn:hover {
  background: rgba(251, 191, 36, 0.2);
  border-color: rgba(251, 191, 36, 0.7);
  transform: scale(1.04);
}

.roulette-btn:active {
  transform: scale(0.97);
}

/* ============================================================
   SHARE BUTTON
   ============================================================ */
.result-actions {
  margin-top: 4px;
  display: flex;
  justify-content: center;
}

.share-btn {
  padding: 8px 22px;
  border-radius: 999px;
  border: 1px solid rgba(99, 102, 241, 0.4);
  background: rgba(99, 102, 241, 0.12);
  color: var(--text-accent);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  transition: all 0.18s ease;
}

.share-btn:hover {
  background: rgba(99, 102, 241, 0.25);
  border-color: rgba(99, 102, 241, 0.7);
  color: white;
}

/* ============================================================
   TOAST NOTIFICATION
   ============================================================ */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(30, 27, 60, 0.96);
  border: 1px solid var(--glass-border);
  backdrop-filter: blur(12px);
  color: var(--text-primary);
  padding: 10px 22px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 200;
  white-space: nowrap;
}

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

/* ============================================================
   FUN FACT TICKER
   ============================================================ */
.fun-fact {
  padding: 14px 20px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

.fun-fact:hover {
  background: rgba(255, 255, 255, 0.09);
}

.fun-fact-label {
  color: var(--text-accent);
  font-weight: 700;
  white-space: nowrap;
  font-size: 0.78rem;
  padding-top: 1px;
}

.fun-fact-text {
  color: var(--text-secondary);
  line-height: 1.5;
  animation: fact-fade 0.4s ease;
}

@keyframes fact-fade {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   AUTO-DETECT BAR
   ============================================================ */
.autodetect-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.autodetect-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-accent);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.autodetect-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.detect-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid rgba(99, 102, 241, 0.4);
  background: rgba(99, 102, 241, 0.1);
  color: var(--text-accent);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.detect-btn:hover {
  background: rgba(99, 102, 241, 0.22);
  border-color: rgba(99, 102, 241, 0.7);
  color: white;
}

.detect-btn.detecting {
  animation: detect-pulse 0.9s ease-in-out infinite;
  pointer-events: none;
}

@keyframes detect-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

.detect-btn.done {
  background: rgba(74, 222, 128, 0.12);
  border-color: rgba(74, 222, 128, 0.4);
  color: var(--green);
}

.detect-icon { font-size: 1rem; }
.detect-label { font-size: 0.78rem; }

.detected-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  width: 100%;
}

.detected-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  background: rgba(74, 222, 128, 0.12);
  border: 1px solid rgba(74, 222, 128, 0.3);
  color: var(--green);
}

.detected-tag.error {
  background: rgba(248, 113, 113, 0.1);
  border-color: rgba(248, 113, 113, 0.3);
  color: var(--red);
}

.autodetect-divider {
  height: 1px;
  background: var(--glass-border);
  margin: 0 -4px;
}

/* ============================================================
   CHART TOOLTIP
   ============================================================ */
.chart-card {
  position: relative;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 600px) {
  .app-container {
    padding: 24px 16px 48px;
  }

  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .emoji-strip {
    gap: 8px;
  }

  .hero h1 {
    font-size: 2rem;
  }

  .result-card {
    padding: 24px 16px;
  }

  .controls-card {
    padding: 20px 16px;
  }
}

@media (max-width: 380px) {
  .emoji-btn {
    padding: 12px 4px;
    font-size: 1.2rem;
  }
}
