/* === DARK MODE BASE (shared for blue & red) === */
:root[data-theme="dark"],
:root[data-theme="red"] {
  --bg: #0e0e12;
  --bg-card: #18181f;
  --text: #e6f0ff;
  --muted-text: #9aa0b2;
  --border: #2a2a35;
}

/* === BLUE SABER === */
:root[data-theme="dark"] {
  --accent: #00b4ff;
  --accent-glow: 0 0 8px rgba(0, 180, 255, 0.8);
}

/* === RED SABER === */
:root[data-theme="red"] {
  --accent: #f70072; /* dominant pink */
  --accent-glow: 0 0 10px rgba(247, 0, 114, 0.8);
}

/* === TRANSITIONS === */
html, body, .chat-container, .message, .input-area,
.landing-wrapper, button, input, textarea {
  transition: background-color 0.5s ease, color 0.5s ease,
              border-color 0.5s ease, box-shadow 0.5s ease;
}

/* === GLOBAL === */
html, body {
  background-color: var(--bg) !important;
  color: var(--text) !important;
}

/* === BUTTONS AND ACCENTS === */
.button-primary,
.input-area > button,
.chat-btn.selected,
.slash-btn:hover,
.toggle-calc-btn:hover {
  background: var(--accent) !important;
  color: #000 !important;
  border-color: var(--accent) !important;
  box-shadow: var(--accent-glow);
}

.button-primary:hover,
.input-area > button:hover {
  background: #000 !important;
  color: var(--accent) !important;
  box-shadow: var(--accent-glow);
}

/* === CHAT === */
[data-theme="dark"] .chat-container,
[data-theme="dark"] #chat-box,
[data-theme="red"] .chat-container,
[data-theme="red"] #chat-box {
  background: var(--bg);
  color: var(--text);
}

[data-theme="dark"] .message,
[data-theme="red"] .message {
  background: var(--bg-card);
  color: var(--text);
  border-color: var(--border);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] .message.user,
[data-theme="red"] .message.user {
  background: #000;
  border: 1px solid var(--accent);
  color: var(--accent);
  box-shadow: var(--accent-glow);
}

/* === CHAT BUTTONS === */
[data-theme="dark"] .chat-btn,
[data-theme="dark"] .slash-btn,
[data-theme="dark"] #question,
[data-theme="dark"] .calculation-block,
[data-theme="dark"] .toggle-calc-btn,
[data-theme="red"] .chat-btn,
[data-theme="red"] .slash-btn,
[data-theme="red"] #question,
[data-theme="red"] .calculation-block,
[data-theme="red"] .toggle-calc-btn {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}

[data-theme="dark"] .chat-btn:hover,
[data-theme="dark"] .slash-btn:hover,
[data-theme="dark"] .toggle-calc-btn:hover,
[data-theme="red"] .chat-btn:hover,
[data-theme="red"] .slash-btn:hover,
[data-theme="red"] .toggle-calc-btn:hover {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  box-shadow: var(--accent-glow);
}

/* === Subtle Oops control (theme-aware) === */
[data-theme="dark"] .oops-flag-btn,
[data-theme="red"] .oops-flag-btn {
  background: transparent !important;
  color: var(--muted-text) !important;
  border: 0 !important;
  box-shadow: none !important;
  opacity: 0.82;
}

[data-theme="dark"] .oops-flag-btn:hover,
[data-theme="red"] .oops-flag-btn:hover {
  color: var(--text) !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  opacity: 1;
}

[data-theme="dark"] .oops-flag-btn.flagged,
[data-theme="red"] .oops-flag-btn.flagged {
  color: var(--accent) !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  opacity: 1;
}

[data-theme="dark"] .oops-flag-status,
[data-theme="red"] .oops-flag-status {
  color: var(--muted-text);
}

[data-theme="dark"] .calc-chat-hint,
[data-theme="red"] .calc-chat-hint,
[data-theme="dark"] .calc-chat-example,
[data-theme="red"] .calc-chat-example,
[data-theme="dark"] .calc-chat-status,
[data-theme="red"] .calc-chat-status {
  color: var(--muted-text);
}

/* === INPUT AREA === */
[data-theme="dark"] .input-area,
[data-theme="red"] .input-area {
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

/* === LANDING PAGE === */
[data-theme="dark"] .landing-wrapper,
[data-theme="red"] .landing-wrapper {
  background: var(--bg);
  color: var(--text);
}

/* === PAGE LOADER === */
[data-theme="dark"] .page-loader,
[data-theme="red"] .page-loader {
  background: rgba(14, 14, 18, 0.95);
  color: var(--text);
}

[data-theme="dark"] .page-loader .spinner,
[data-theme="red"] .page-loader .spinner {
  border-color: var(--accent);
  border-top-color: transparent;
}

[data-theme="dark"] .tagline,
[data-theme="red"] .tagline {
  color: var(--muted-text);
}

[data-theme="dark"] .button-primary,
[data-theme="red"] .button-primary {
  background: var(--accent);
  color: #000;
  border: 1px solid var(--accent);
  box-shadow: var(--accent-glow);
}

[data-theme="dark"] .button-primary:hover,
[data-theme="red"] .button-primary:hover {
  background: #000;
  color: var(--accent);
  box-shadow: var(--accent-glow);
}

/* === BASE ELEMENTS === */
[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea,
[data-theme="red"] input,
[data-theme="red"] select,
[data-theme="red"] textarea {
  background: var(--bg-card);
  color: var(--text);
  border-color: var(--border);
}

[data-theme="dark"] th,
[data-theme="red"] th {
  background: var(--bg-card);
  color: var(--accent);
}

[data-theme="dark"] tr:hover,
[data-theme="red"] tr:hover {
  background: rgba(0, 0, 0, 0.2);
}

/* === FOCUS GLOW === */
[data-theme="dark"] input:focus,
[data-theme="dark"] textarea:focus,
[data-theme="red"] input:focus,
[data-theme="red"] textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* === POLISHED SABER TOGGLE (TOP RIGHT) === */
.saber-toggle {
  position: fixed;
  top: var(--saber-top, auto);
  bottom: var(--saber-bottom, 1rem);
  right: var(--corner-control-right, 1rem);
  width: var(--corner-control-width, 70px);
  height: 30px;
  box-sizing: border-box;
  border-radius: 50px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  cursor: pointer;
  overflow: hidden;
  box-shadow: inset 0 0 6px rgba(255,255,255,0.05), 0 0 4px rgba(0,0,0,0.6);
  transition: all 0.3s ease;
  z-index: 9999;
}

.saber-toggle:hover {
  box-shadow: 0 0 10px var(--accent), 0 0 25px var(--accent-glow);
}

/* Track inner highlight */
.saber-toggle::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50px;
  background: linear-gradient(180deg, rgba(255,255,255,0.2), rgba(255,255,255,0.05));
  pointer-events: none;
}

/* Circular button (lightsaber core) */
.saber-toggle::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 8px rgba(255,255,255,0.6);
  transition:
    transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
    background-color 0.35s ease,
    box-shadow 0.35s ease;
}

/* Position + Glow per theme */
.saber-toggle[data-state="light"]::after {
  transform: translateX(0);
  background-color: #fff;
  box-shadow: 0 0 6px rgba(255,255,255,0.8);
}

.saber-toggle[data-state="blue"]::after {
  transform: translateX(var(--saber-blue-offset, 30px));
  background-color: #00b4ff;
  box-shadow: 0 0 14px rgba(0,180,255,0.9);
}

.saber-toggle[data-state="red"]::after {
  transform: translateX(var(--saber-red-offset, 30px));
  background-color: #f70072;
  box-shadow: 0 0 14px rgba(247, 0, 114, 0.9);
}

/* Soft hum animation */
@keyframes saber-hum {
  0%, 100% { box-shadow: 0 0 12px var(--accent); }
  50% { box-shadow: 0 0 18px var(--accent); }
}
[data-theme="dark"] .saber-toggle[data-state="blue"]::after,
[data-theme="red"] .saber-toggle[data-state="red"]::after {
  animation: saber-hum 2.4s ease-in-out infinite;
}

/* === LIGHT THEME: SIMPLIFIED + MORE WHITESPACE === */
:root[data-theme="light"] .saber-toggle {
  background: #f8f8f8;
  border: 1px solid rgba(0, 0, 0, 0.1);
  box-shadow: inset 0 0 3px rgba(0, 0, 0, 0.05);
}

:root[data-theme="light"] .saber-toggle:hover {
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.1);
}

/* Give the toggle a bit more horizontal space */
.saber-toggle {
  width: var(--corner-control-width, 70px);
  height: 32px;
  padding: 0 2px;
}

/* Center and resize the circular knob perfectly */
.saber-toggle::after {
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
}

/* Neutral white circle with subtle shadow for contrast */
:root[data-theme="light"] .saber-toggle::after {
  background: #fff;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.25);
}

/* Slightly reduce hover brightness on light mode */
:root[data-theme="light"] .saber-toggle:hover::after {
  box-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
}

/* === FIX KNOB ALIGNMENT (Perfect Centering) === */
.saber-toggle {
  width: var(--corner-control-width, 70px);
  height: 32px;
  padding: 0;
  position: fixed;
  top: var(--saber-top, auto);
  bottom: var(--saber-bottom, 1rem);
  right: var(--corner-control-right, 1rem);
  border-radius: 50px;
}

.saber-toggle::after {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              background-color 0.35s ease,
              box-shadow 0.35s ease;
}

/* Light (left) position */
.saber-toggle[data-state="light"]::after {
  transform: translateX(0);
}

/* Blue (middle) position — exactly centered */
.saber-toggle[data-state="blue"]::after {
  transform: translateX(var(--saber-blue-offset, 18px));
}

/* Red (right) position — equal spacing on both sides */
.saber-toggle[data-state="red"]::after {
  transform: translateX(var(--saber-red-offset, 36px));
}

/* ✅ Light mode override: replace accent blue with grey (scoped correctly now) */
:root[data-theme="light"] .button-primary,
:root[data-theme="light"] .input-area > button,
:root[data-theme="light"] .chat-btn.selected,
:root[data-theme="light"] .slash-btn:hover,
:root[data-theme="light"] .toggle-calc-btn:hover {
  background: #666 !important;
  color: #fff !important;
  border-color: #666 !important;
  box-shadow: 0 0 8px rgba(102,102,102,0.4) !important;
}

/* === COMPLETED BUTTON GLOW === */
[data-theme="dark"] .chat-btn.completed,
[data-theme="red"] .chat-btn.completed,
[data-theme="light"] .chat-btn.completed {
  border-color: var(--accent) !important;
  box-shadow: 0 0 12px var(--accent), 0 0 24px var(--accent-glow) !important;
  animation: completed-pulse 2s ease-in-out infinite;
}

/* Subtle breathing pulse */
@keyframes completed-pulse {
  0%, 100% { box-shadow: 0 0 10px var(--accent); }
  50%      { box-shadow: 0 0 18px var(--accent); }
}

/* === FIX: Better contrast for red saber buttons === */
:root[data-theme="red"] .button-primary,
:root[data-theme="red"] .input-area > button,
:root[data-theme="red"] .chat-btn.selected,
:root[data-theme="red"] .slash-btn:hover,
:root[data-theme="red"] .toggle-calc-btn:hover {
  color: #fff !important; /* use white for higher contrast */
  background: var(--accent) !important;
  border-color: var(--accent) !important;
  box-shadow: var(--accent-glow);
}

/* Keep the hover behavior consistent */
:root[data-theme="red"] .button-primary:hover {
  background: #000 !important;
  color: var(--accent) !important;
  border-color: var(--accent) !important;
}

/* === LIGHT THEME: Improved button contrast === */
:root[data-theme="light"] .button-primary {
  background: #000 !important;      /* black button */
  color: #fff !important;           /* white text */
  border: 1px solid #000 !important;
  box-shadow: none !important;      /* keep it clean */
  transition: all 0.3s ease;
}

/* Invert on hover */
:root[data-theme="light"] .button-primary:hover {
  background: #fff !important;      /* white background */
  color: #000 !important;           /* black text */
  border: 1px solid #000 !important;
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.25) !important;
}
