:root {
  --bg-color: #0b0f19;
  --glass-bg: rgba(22, 28, 45, 0.4);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-highlight: rgba(255, 255, 255, 0.12);
  --accent: #f59e0b;
  --accent-hover: #fbbf24;
  --accent-glow: rgba(245, 158, 11, 0.4);
  --accent-subtle: rgba(245, 158, 11, 0.08);
  --success: #10b981;
  --warning: #f59e0b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dark: #cbd5e1;
  --panel-bg: rgba(15, 23, 42, 0.6);
  --input-bg: rgba(15, 23, 42, 0.8);
  --input-border: rgba(148, 163, 184, 0.2);
  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

/* ========== Background Effects ========== */
.background-effects {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.glow-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.4;
  animation: float 20s ease-in-out infinite alternate;
}

.orb-1 {
  top: -10%;
  left: 20%;
  width: 50vw;
  height: 50vw;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.2) 0%, rgba(0, 0, 0, 0) 70%);
}

.orb-2 {
  bottom: -20%;
  right: -10%;
  width: 60vw;
  height: 60vw;
  background: radial-gradient(circle, rgba(139, 92, 246, 0.15) 0%, rgba(0, 0, 0, 0) 70%);
  animation-delay: -5s;
}

.orb-3 {
  top: 40%;
  left: -20%;
  width: 40vw;
  height: 40vw;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.1) 0%, rgba(0, 0, 0, 0) 70%);
  animation-delay: -10s;
}

@keyframes float {
  0% { transform: translate(0, 0); }
  100% { transform: translate(50px, 50px); }
}

/* ========== Layout ========== */
.app-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

main {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ========== Header ========== */
.glass-header {
  text-align: center;
  margin-bottom: 0.5rem;
  position: relative;
}

.header-links {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.header-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  transition: all 0.2s ease;
  cursor: pointer;
}

.header-link:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.github-link:hover {
  color: #f0f6fc;
  border-color: rgba(240, 246, 252, 0.3);
}

.discord-link:hover {
  color: #5865F2;
  border-color: rgba(88, 101, 242, 0.5);
}

.header-content {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.logo {
  width: 36px;
  height: 36px;
  color: var(--accent);
  filter: drop-shadow(0 0 10px var(--accent-glow));
  animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
  0%, 100% { filter: drop-shadow(0 0 8px rgba(245, 158, 11, 0.3)); }
  50% { filter: drop-shadow(0 0 18px rgba(245, 158, 11, 0.6)); }
}

h1 {
  font-size: 2.8rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 0%, #fbbf24 50%, #f59e0b 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.hero-subtitle {
  color: var(--text-muted);
  font-size: 1.15rem;
  font-weight: 400;
}

/* ========== Cards ========== */
.glass-card {
  background: var(--glass-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* ========== Browser Notice ========== */
.browser-notice {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: rgba(59, 130, 246, 0.06);
  border-color: rgba(59, 130, 246, 0.15);
  font-size: 0.9rem;
  color: #93c5fd;
  animation: fadeIn 0.5s ease;
}

.notice-icon {
  flex-shrink: 0;
  color: #60a5fa;
}

.notice-content strong {
  color: #bfdbfe;
}

/* ========== Troubleshooting Section ========== */
.troubleshooting-notice {
  padding: 1rem 1.25rem;
  background: rgba(245, 158, 11, 0.05);
  border-color: rgba(245, 158, 11, 0.15);
  font-size: 0.95rem;
  animation: fadeIn 0.5s ease;
  transition: all 0.3s ease;
}

.troubleshooting-summary {
  font-weight: 600;
  color: var(--warning);
  cursor: pointer;
  list-style: none;
  position: relative;
  display: flex;
  align-items: center;
  user-select: none;
}

.troubleshooting-summary::-webkit-details-marker {
  display: none;
}

.troubleshooting-summary::before {
  content: '▶';
  font-size: 0.75rem;
  margin-right: 0.6rem;
  transition: transform 0.2s ease;
  color: var(--warning);
}

.troubleshooting-notice[open] .troubleshooting-summary::before {
  transform: rotate(90deg);
}

.troubleshooting-content {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(245, 158, 11, 0.1);
  color: var(--text-main);
}

.troubleshooting-desc {
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
  color: var(--text-dark);
}

.troubleshooting-list {
  padding-left: 1.5rem;
  margin-bottom: 0;
  color: var(--text-main);
}

.troubleshooting-list li {
  margin-bottom: 0.5rem;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ========== Section Header ========== */
.section-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--glass-border);
}

.section-header h2 {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-main);
  margin: 0;
}

.section-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.15rem 0 0;
}

.section-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.preloaded-icon {
  background: rgba(16, 185, 129, 0.1);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.custom-icon {
  background: rgba(139, 92, 246, 0.1);
  color: #a78bfa;
  border: 1px solid rgba(139, 92, 246, 0.2);
}

/* ========== Flash Steps ========== */
.flash-steps {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 1.75rem;
  background: rgba(0, 0, 0, 0.15);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.flash-step {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  transition: background 0.2s ease;
}

.flash-step:not(:last-child) {
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.flash-step:hover {
  background: rgba(255, 255, 255, 0.02);
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-subtle);
  color: var(--accent-hover);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.step-content {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.step-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
}

.step-detail {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.875rem 1.5rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  font-family: inherit;
}

.btn-primary {
  background: var(--accent);
  color: #1a1a2e;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px var(--accent-glow);
}

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

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.1);
  transform: translateY(-2px);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

/* ========== Flash Action ========== */
.flash-action {
  display: flex;
  justify-content: center;
}

.flash-btn {
  width: 100%;
  padding: 1.1rem 2rem;
  font-size: 1.1rem;
  gap: 0.75rem;
  border-radius: var(--radius-md);
  letter-spacing: 0.01em;
}

.flash-btn svg {
  filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.2));
}

/* Unsupported message */
.unsupported-msg {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem 1.25rem;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  color: #fca5a5;
  text-align: left;
}

/* ========== Section Divider ========== */
.section-divider {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.5rem 0;
}

.section-divider::before,
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--glass-border), transparent);
}

.section-divider span {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  white-space: nowrap;
}

/* ========== Custom Controls ========== */
.custom-controls {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.control-row {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.file-picker {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex: 1;
  min-width: 250px;
}

.file-picker-btn {
  white-space: nowrap;
  flex-shrink: 0;
}

.file-name {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-style: italic;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 250px;
}

.file-name.has-file {
  color: #34d399;
  font-style: normal;
  font-weight: 500;
}

.chip-selector {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chip-selector label {
  font-size: 0.8rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* ========== Forms ========== */
.premium-select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: inherit;
  font-size: 1rem;
  transition: all 0.2s ease;
  outline: none;
  appearance: none;
  padding-right: 2.5rem;
  min-width: 160px;
}

.premium-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

.custom-select-wrapper {
  position: relative;
}

.custom-select-wrapper::after {
  content: '';
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 5px solid var(--text-muted);
  pointer-events: none;
}

/* ========== ESP Web Tools Overrides ========== */
esp-web-install-button {
  --esp-tools-button-color: var(--accent);
  --esp-tools-button-text-color: #1a1a2e;
  display: block;
  width: 100%;
}

/* ========== Footer ========== */
.app-footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1.5rem 0 1rem;
  opacity: 0.5;
}

/* ========== Animations ========== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.flasher-section {
  animation: fadeIn 0.5s ease;
}

.flasher-section:nth-child(3) {
  animation-delay: 0.1s;
  animation-fill-mode: both;
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
  .app-container {
    padding: 1.25rem 1rem;
    gap: 1.5rem;
  }

  h1 {
    font-size: 2rem;
  }

  .hero-subtitle {
    font-size: 1rem;
    padding: 0 0.5rem;
  }

  .glass-card {
    padding: 1.25rem;
    border-radius: var(--radius-md);
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .control-row {
    flex-direction: column;
    gap: 1rem;
  }

  .file-picker {
    flex-direction: column;
    align-items: flex-start;
    min-width: unset;
    width: 100%;
  }

  .file-picker-btn {
    width: 100%;
  }

  .file-name {
    max-width: 100%;
  }

  .chip-selector {
    width: 100%;
  }

  .premium-select {
    width: 100%;
  }

  .btn {
    width: 100%;
  }

  .flash-step {
    padding: 0.85rem 1rem;
  }
}

@media (max-width: 480px) {
  h1 {
    font-size: 1.75rem;
  }

  .logo {
    width: 28px;
    height: 28px;
  }

  .section-icon {
    width: 44px;
    height: 44px;
  }
}
