/* ─── Reset & Base ─── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #0a0b0e;
  --bg-secondary: #12141a;
  --bg-card: #181b24;
  --border-glow: rgba(0, 255, 255, 0.15);
  --text-primary: #e8edf5;
  --text-secondary: #8892b0;
  --accent-cyan: #00f0ff;
  --accent-violet: #a855f7;
  --accent-dim: rgba(0, 240, 255, 0.25);
  --font-display: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Courier New', monospace;
  --radius: 16px;
  --shadow-glow: 0 0 60px rgba(0, 240, 255, 0.06), 0 0 120px rgba(168, 85, 247, 0.04);
}

html, body {
  height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-display);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 20%, #0f172a 0%, #0a0b0e 70%);
  min-height: 100vh;
  padding: 16px;
}

/* ─── App Container ─── */
#app {
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 16px 24px;
  background: rgba(18, 20, 26, 0.7);
  backdrop-filter: blur(20px) saturate(1.2);
  -webkit-backdrop-filter: blur(20px) saturate(1.2);
  border-radius: 32px;
  border: 1px solid rgba(0, 240, 255, 0.06);
  box-shadow: var(--shadow-glow);
  position: relative;
  min-height: 520px;
  display: flex;
  flex-direction: column;
}

/* ─── Header ─── */
header {
  text-align: center;
  margin-bottom: 24px;
}

header h1 {
  font-size: 22px;
  font-weight: 500;
  letter-spacing: 4px;
  text-transform: lowercase;
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-violet));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-family: var(--font-mono);
}

.subtitle {
  display: block;
  font-size: 10px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-secondary);
  opacity: 0.5;
  margin-top: 2px;
  font-weight: 300;
}

/* ─── Controls ─── */
#controls {
  margin-bottom: 28px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

#subjectSelect {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 40px;
  padding: 8px 16px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: 0.3px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238892b0' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
  min-width: 160px;
  cursor: pointer;
  transition: border-color 0.3s, box-shadow 0.3s;
}

#subjectSelect:focus {
  outline: none;
  border-color: var(--accent-cyan);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.06);
}

#subjectSelect option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Toggle */
.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  letter-spacing: 0.5px;
  user-select: none;
}

.toggle-label input {
  display: none;
}

.toggle-slider {
  width: 34px;
  height: 18px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 20px;
  position: relative;
  transition: background 0.3s;
  flex-shrink: 0;
}

.toggle-slider::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.3s, background 0.3s;
}

.toggle-label input:checked + .toggle-slider {
  background: var(--accent-cyan);
}

.toggle-label input:checked + .toggle-slider::after {
  transform: translateX(16px);
  background: #0a0b0e;
}

.toggle-text {
  opacity: 0.6;
  transition: opacity 0.3s;
}

.toggle-label input:checked ~ .toggle-text {
  opacity: 1;
}

/* ─── GEN Button ─── */
#genBtn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  margin: 0 auto 28px;
  display: block;
  transition: transform 0.2s, filter 0.3s;
  touch-action: manipulation;
}

#genBtn:active {
  transform: scale(0.94);
}

.btn-ring {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 240, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: border-color 0.4s, box-shadow 0.4s;
  background: rgba(0, 240, 255, 0.02);
}

.btn-ring::before {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: conic-gradient(from 0deg, transparent, var(--accent-cyan), var(--accent-violet), transparent 360deg);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 1px));
  opacity: 0.3;
  animation: spin 12s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn-text {
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 6px;
  text-transform: uppercase;
  color: var(--text-primary);
  font-family: var(--font-mono);
  opacity: 0.8;
  transition: opacity 0.3s;
}

#genBtn:hover .btn-ring {
  border-color: rgba(0, 240, 255, 0.4);
  box-shadow: 0 0 50px rgba(0, 240, 255, 0.05);
}

#genBtn:hover .btn-text {
  opacity: 1;
}

#genBtn:active .btn-ring {
  border-color: var(--accent-cyan);
}

/* Pulse animation when idle */
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 20px rgba(0, 240, 255, 0.02); }
  50% { box-shadow: 0 0 40px rgba(0, 240, 255, 0.06), 0 0 80px rgba(168, 85, 247, 0.02); }
}

.btn-ring {
  animation: pulse-glow 4s ease-in-out infinite;
}

/* ─── Question Card ─── */
#questionCard {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
  margin-bottom: 16px;
  transition: opacity 0.4s ease, transform 0.4s ease;
  flex: 1;
}

#questionCard.hidden {
  display: none;
}

#questionCard.fade-out {
  opacity: 0;
  transform: translateY(8px);
}

#questionCard.fade-in {
  opacity: 1;
  transform: translateY(0);
}

.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.subject-tag {
  color: var(--accent-cyan);
  opacity: 0.7;
  font-weight: 400;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 2px 10px;
  border: 1px solid rgba(0, 240, 255, 0.1);
  border-radius: 20px;
  background: rgba(0, 240, 255, 0.04);
}

.count-badge {
  color: var(--text-secondary);
  opacity: 0.4;
  font-size: 10px;
}

#questionText {
  font-size: 17px;
  line-height: 1.65;
  font-weight: 350;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  margin-bottom: 16px;
  min-height: 80px;
}

/* ─── Actions ─── */
#actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  padding-top: 14px;
}

.action-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 30px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.25s;
  font-family: var(--font-display);
  touch-action: manipulation;
}

.action-btn .icon {
  font-size: 15px;
  line-height: 1;
}

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

.action-btn:active {
  transform: scale(0.95);
}

.action-btn.primary {
  background: rgba(0, 240, 255, 0.06);
  border-color: rgba(0, 240, 255, 0.15);
  color: var(--accent-cyan);
}

.action-btn.primary:hover {
  background: rgba(0, 240, 255, 0.12);
  border-color: rgba(0, 240, 255, 0.25);
}

#discardBtn {
  background: rgba(255, 255, 255, 0.02);
}

/* ─── Footer ─── */
footer {
  margin-top: auto;
  padding-top: 16px;
  text-align: center;
}

#statusText {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  opacity: 0.25;
  letter-spacing: 1px;
}

/* ─── Toast ─── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(18, 20, 26, 0.95);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 40px;
  padding: 10px 24px;
  font-size: 13px;
  color: var(--text-secondary);
  font-family: var(--font-display);
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
  pointer-events: none;
  z-index: 1000;
  white-space: nowrap;
}

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

/* ─── Responsive ─── */
@media (max-width: 420px) {
  #app {
    padding: 16px 12px 20px;
    border-radius: 24px;
    min-height: 480px;
  }

  .btn-ring {
    width: 100px;
    height: 100px;
  }

  .btn-text {
    font-size: 15px;
    letter-spacing: 4px;
  }

  #questionText {
    font-size: 15px;
  }

  #subjectSelect {
    min-width: 130px;
    font-size: 12px;
    padding: 6px 32px 6px 12px;
  }
}

@media (max-width: 360px) {
  .control-row {
    flex-direction: column;
    gap: 8px;
  }

  #subjectSelect {
    width: 100%;
    min-width: unset;
  }
}