/* ===== CSS Variables & Design Tokens ===== */
:root {
  --bg-primary: #0a0a12;
  --bg-secondary: #12121e;
  --bg-card: rgba(18, 18, 34, 0.85);
  --bg-card-hover: rgba(24, 24, 48, 0.9);
  --surface: rgba(255, 255, 255, 0.04);
  --surface-hover: rgba(255, 255, 255, 0.08);
  
  --text-primary: #e8e8f0;
  --text-secondary: #8888a8;
  --text-muted: #555570;
  
  --accent-1: #6c5ce7;
  --accent-2: #a855f7;
  --accent-3: #ec4899;
  --accent-gradient: linear-gradient(135deg, #6c5ce7, #a855f7, #ec4899);
  --accent-glow: rgba(108, 92, 231, 0.3);
  
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.3);
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.3);
  
  --border: rgba(255, 255, 255, 0.06);
  --border-accent: rgba(108, 92, 231, 0.3);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 24px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 48px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 40px var(--accent-glow);
  
  --font-primary: 'Inter', 'Noto Sans KR', sans-serif;
  --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-primary);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ===== Ambient Background ===== */
.ambient-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  opacity: 0.15;
  animation: blobFloat 20s ease-in-out infinite;
}

.blob-1 {
  width: 500px;
  height: 500px;
  background: var(--accent-1);
  top: -10%;
  left: -10%;
  animation-delay: 0s;
}

.blob-2 {
  width: 400px;
  height: 400px;
  background: var(--accent-2);
  top: 50%;
  right: -10%;
  animation-delay: -7s;
}

.blob-3 {
  width: 350px;
  height: 350px;
  background: var(--accent-3);
  bottom: -10%;
  left: 30%;
  animation-delay: -14s;
}

@keyframes blobFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(30px, -50px) scale(1.1); }
  66% { transform: translate(-20px, 20px) scale(0.9); }
}

/* ===== App Container ===== */
.app-container {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  margin-bottom: 24px;
}

.logo-section {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: var(--shadow-glow);
}

.app-header h1 {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.accent-text {
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.header-btn:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border-accent);
}

/* ===== Question Card ===== */
.question-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: var(--shadow-lg);
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.question-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(108, 92, 231, 0.5), transparent);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.question-meta {
  display: flex;
  gap: 8px;
}

.badge {
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.badge-category {
  background: rgba(108, 92, 231, 0.15);
  color: #a78bfa;
  border: 1px solid rgba(108, 92, 231, 0.25);
}

.badge-type {
  background: rgba(236, 72, 153, 0.15);
  color: #f472b6;
  border: 1px solid rgba(236, 72, 153, 0.25);
}

.play-count {
  display: flex;
  gap: 6px;
  align-items: center;
}

.play-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--text-muted);
  transition: var(--transition);
}

.play-dot.active {
  background: var(--accent-1);
  border-color: var(--accent-1);
  box-shadow: 0 0 8px var(--accent-glow);
}

.play-dot.used {
  background: var(--text-muted);
  border-color: var(--text-muted);
}

/* ===== Timer Section ===== */
.timer-section {
  display: flex;
  justify-content: center;
  margin: 16px 0 20px;
}

.timer-ring-container {
  position: relative;
  width: 180px;
  height: 180px;
}

.timer-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-ring-bg {
  fill: none;
  stroke: var(--surface);
  stroke-width: 6;
}

.timer-ring-progress {
  fill: none;
  stroke: url(#timerGradient);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 565.48;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}

.timer-display {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.timer-value {
  display: block;
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.timer-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-top: 6px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* Timer states */
.timer-ring-progress.warning {
  stroke: var(--warning) !important;
}

.timer-ring-progress.danger {
  stroke: var(--danger) !important;
  animation: timerPulse 0.5s ease-in-out infinite;
}

@keyframes timerPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.timer-value.warning {
  -webkit-text-fill-color: var(--warning);
}

.timer-value.danger {
  -webkit-text-fill-color: var(--danger);
  animation: timerPulse 0.5s ease-in-out infinite;
}

/* ===== Question Text ===== */
.question-text-area {
  margin: 16px 0;
  padding: 16px 20px;
  background: rgba(108, 92, 231, 0.06);
  border: 1px solid rgba(108, 92, 231, 0.12);
  border-radius: var(--radius-lg);
  display: none;
}

.question-text-area.visible {
  display: block;
  animation: fadeInUp 0.5s ease;
}

.question-text {
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text-secondary);
  font-weight: 400;
}

/* ===== Audio Visualizer ===== */
.visualizer-container {
  margin: 16px 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  display: none;
}

.visualizer-container.active {
  display: block;
  animation: fadeIn 0.3s ease;
}

#audioVisualizer {
  width: 100%;
  height: 80px;
  display: block;
}

/* ===== Status Message ===== */
.status-message {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius-md);
  margin-top: 16px;
}

.status-icon {
  font-size: 1.2rem;
}

.status-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.status-message.recording {
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.status-message.recording .status-text {
  color: var(--danger);
}

.status-message.success {
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-message.success .status-text {
  color: var(--success);
}

/* ===== Controls ===== */
.controls-area {
  margin-top: 28px;
  padding-bottom: 32px;
}

.controls-row {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.ctrl-btn {
  flex: 1;
  max-width: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 20px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font-primary);
  position: relative;
  overflow: hidden;
}

.ctrl-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--radius-lg);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.ctrl-btn:hover:not(:disabled)::before {
  opacity: 1;
}

.ctrl-btn:active:not(:disabled) {
  transform: scale(0.97);
}

.ctrl-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

/* Replay Button */
.ctrl-replay {
  border-color: rgba(108, 92, 231, 0.2);
}

.ctrl-replay::before {
  background: rgba(108, 92, 231, 0.06);
}

.ctrl-replay .btn-icon {
  color: var(--accent-1);
}

.ctrl-replay:hover:not(:disabled) {
  border-color: rgba(108, 92, 231, 0.4);
  box-shadow: 0 4px 20px rgba(108, 92, 231, 0.15);
}

/* Record Button */
.ctrl-record {
  border-color: rgba(239, 68, 68, 0.2);
}

.ctrl-record::before {
  background: rgba(239, 68, 68, 0.06);
}

.ctrl-record:hover:not(:disabled) {
  border-color: rgba(239, 68, 68, 0.4);
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.15);
}

.record-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.record-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--danger);
  transition: var(--transition);
}

.ctrl-record.recording .record-icon {
  border-color: var(--danger);
  animation: recordPulse 1.5s ease-in-out infinite;
}

.ctrl-record.recording .record-dot {
  border-radius: 3px;
  width: 12px;
  height: 12px;
}

@keyframes recordPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(239, 68, 68, 0); }
}

/* Random Button */
.ctrl-random {
  border-color: rgba(168, 85, 247, 0.2);
}

.ctrl-random::before {
  background: rgba(168, 85, 247, 0.06);
}

.ctrl-random .btn-icon {
  color: var(--accent-2);
}

.ctrl-random:hover:not(:disabled) {
  border-color: rgba(168, 85, 247, 0.4);
  box-shadow: 0 4px 20px rgba(168, 85, 247, 0.15);
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.btn-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.25s ease;
}

.modal-content {
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.modal-body {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

.empty-history {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 48px 0;
  color: var(--text-muted);
}

.empty-history p {
  font-size: 0.9rem;
}

/* History Item */
.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 12px;
  transition: var(--transition);
}

.history-item:hover {
  background: var(--surface-hover);
  border-color: var(--border-accent);
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.history-item-meta {
  display: flex;
  gap: 6px;
  align-items: center;
}

.history-item-date {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.history-item-question {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-item-actions {
  display: flex;
  gap: 8px;
}

.history-play-btn, .history-delete-btn {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-family: var(--font-primary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 4px;
}

.history-play-btn:hover {
  background: rgba(108, 92, 231, 0.15);
  color: #a78bfa;
  border-color: rgba(108, 92, 231, 0.3);
}

.history-delete-btn:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.3);
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

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

/* ===== SVG Gradient for Timer ===== */
/* Added via JS */

/* ===== Responsive ===== */
@media (max-width: 600px) {
  .app-container {
    padding: 12px;
  }
  
  .question-card {
    padding: 20px;
    border-radius: var(--radius-lg);
  }
  
  .timer-ring-container {
    width: 150px;
    height: 150px;
  }
  
  .timer-value {
    font-size: 2rem;
  }
  
  .controls-row {
    gap: 8px;
  }
  
  .ctrl-btn {
    padding: 16px 12px;
  }
  
  .app-header h1 {
    font-size: 1.25rem;
  }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--surface-hover);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
