/* ================================================================
   Deutsche Sprechprüfung - Custom Styles
   Tailwind config extensions + custom animations + components
   ================================================================ */

/* ----------------------------------------------------------------
   Google Fonts import
   ---------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Merriweather:ital,wght@0,400;0,700;1,400&display=swap');

/* ----------------------------------------------------------------
   CSS Custom Properties
   ---------------------------------------------------------------- */
:root {
  --color-primary:    #1E3A5F;
  --color-secondary:  #E63946;
  --color-accent:     #FFB703;
  --color-success:    #2D6A4F;
  --color-bg:         #F8F9FA;
  --color-text:       #1a1a2e;
  --color-muted:      #6c757d;

  --font-heading: 'Inter', system-ui, sans-serif;
  --font-german:  'Merriweather', Georgia, serif;

  --radius-card:   1rem;       /* rounded-2xl */
  --radius-btn:    0.75rem;    /* rounded-xl */
  --shadow-card:   0 10px 40px rgba(30,58,95,0.12);
  --shadow-btn:    0 4px 14px rgba(30,58,95,0.25);
  --transition:    all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ----------------------------------------------------------------
   Base resets
   ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-heading);
  background-color: var(--color-bg);
  color: var(--color-text);
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

/* Minimum touch target */
button, a, input, select, textarea, [role="button"] {
  min-height: 44px;
}

/* ----------------------------------------------------------------
   German Flag Accent Bar
   ---------------------------------------------------------------- */
.german-flag-bar {
  display: flex;
  width: 100%;
  height: 6px;
}
.german-flag-bar .stripe-black { flex: 1; background: #1a1a1a; }
.german-flag-bar .stripe-red   { flex: 1; background: #E63946; }
.german-flag-bar .stripe-gold  { flex: 1; background: #FFB703; }

.german-flag-badge {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: 4px;
  overflow: hidden;
}
.german-flag-badge span {
  display: inline-block;
  width: 14px;
  height: 10px;
}
.german-flag-badge .b { background: #1a1a1a; }
.german-flag-badge .r { background: #E63946; }
.german-flag-badge .g { background: #FFB703; }

/* ----------------------------------------------------------------
   Landing page gradient background animation
   ---------------------------------------------------------------- */
@keyframes gradientShift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

.animated-gradient {
  background: linear-gradient(
    135deg,
    #0d1f35 0%,
    #1E3A5F 25%,
    #163050 50%,
    #1a2e4a 75%,
    #0d1f35 100%
  );
  background-size: 400% 400%;
  animation: gradientShift 12s ease infinite;
}

/* Particle / floating dots decoration */
.floating-dots {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
.floating-dots::before,
.floating-dots::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  opacity: 0.06;
  animation: float 8s ease-in-out infinite;
}
.floating-dots::before {
  width: 400px; height: 400px;
  background: #FFB703;
  top: -100px; left: -100px;
}
.floating-dots::after {
  width: 300px; height: 300px;
  background: #E63946;
  bottom: -80px; right: -80px;
  animation-delay: -4s;
}
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%       { transform: translate(30px, -20px) scale(1.05); }
  66%       { transform: translate(-20px, 30px) scale(0.95); }
}

/* ----------------------------------------------------------------
   Cards
   ---------------------------------------------------------------- */
.card {
  background: #ffffff;
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.card-glass {
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius-card);
}

/* ----------------------------------------------------------------
   Buttons
   ---------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-radius: var(--radius-btn);
  font-family: var(--font-heading);
  font-weight: 600;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  min-height: 48px;
  white-space: nowrap;
}

.btn::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0);
  transition: background 0.2s;
}
.btn:hover::after  { background: rgba(255,255,255,0.08); }
.btn:active::after { background: rgba(255,255,255,0.15); }

.btn-primary {
  background: var(--color-primary);
  color: #ffffff;
  box-shadow: var(--shadow-btn);
}
.btn-primary:hover {
  background: #16304f;
  box-shadow: 0 6px 20px rgba(30,58,95,0.35);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--color-secondary);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(230,57,70,0.3);
}
.btn-secondary:hover {
  background: #cc2f3b;
  box-shadow: 0 6px 20px rgba(230,57,70,0.4);
  transform: translateY(-1px);
}

.btn-accent {
  background: var(--color-accent);
  color: var(--color-primary);
  box-shadow: 0 4px 14px rgba(255,183,3,0.35);
}
.btn-accent:hover {
  background: #e5a500;
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: #ffffff;
  border: 2px solid rgba(255,255,255,0.5);
}
.btn-outline:hover {
  background: rgba(255,255,255,0.1);
  border-color: #ffffff;
}

.btn-lg {
  padding: 1rem 2rem;
  font-size: 1.125rem;
  min-height: 56px;
}

.btn-xl {
  padding: 1.125rem 2.5rem;
  font-size: 1.25rem;
  min-height: 64px;
}

.btn:disabled, .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

/* ----------------------------------------------------------------
   Form inputs
   ---------------------------------------------------------------- */
.form-input {
  width: 100%;
  padding: 0.875rem 1rem;
  border: 2px solid #e2e8f0;
  border-radius: 0.75rem;
  font-family: var(--font-heading);
  font-size: 1rem;
  color: var(--color-text);
  background: #ffffff;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 52px;
  outline: none;
  appearance: none;
}
.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(30,58,95,0.12);
}
.form-input.error {
  border-color: var(--color-secondary);
  box-shadow: 0 0 0 3px rgba(230,57,70,0.12);
}
.form-input::placeholder { color: #a0aec0; }

.form-label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--color-primary);
  margin-bottom: 0.375rem;
  letter-spacing: 0.01em;
}

/* ----------------------------------------------------------------
   Microphone button
   ---------------------------------------------------------------- */
.mic-btn {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: var(--color-primary);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  transition: var(--transition);
  box-shadow: 0 8px 30px rgba(30,58,95,0.4);
  position: relative;
  outline: none;
}

.mic-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 40px rgba(30,58,95,0.5);
}

.mic-btn.recording {
  background: var(--color-secondary);
  box-shadow: 0 8px 30px rgba(230,57,70,0.5);
  animation: micPulse 1.5s ease-in-out infinite;
}

@keyframes micPulse {
  0%, 100% {
    box-shadow: 0 8px 30px rgba(230,57,70,0.5),
                0 0 0 0 rgba(230,57,70,0.4);
    transform: scale(1);
  }
  50% {
    box-shadow: 0 8px 30px rgba(230,57,70,0.5),
                0 0 0 20px rgba(230,57,70,0);
    transform: scale(1.03);
  }
}

/* Ripple rings on recording */
.mic-btn.recording::before,
.mic-btn.recording::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(230,57,70,0.5);
  animation: micRing 1.5s ease-out infinite;
}
.mic-btn.recording::after {
  animation-delay: 0.5s;
}
@keyframes micRing {
  0%   { width: 100px; height: 100px; opacity: 0.8; }
  100% { width: 160px; height: 160px; opacity: 0; }
}

/* ----------------------------------------------------------------
   Camera preview overlay
   ---------------------------------------------------------------- */
.camera-preview {
  position: fixed;
  top: 12px;
  right: 12px;
  width: 120px;
  height: 90px;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid rgba(255,255,255,0.3);
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  background: #000;
  z-index: 100;
}

.camera-preview video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* mirror */
}

.camera-preview .cam-status {
  position: absolute;
  bottom: 4px;
  left: 4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #E63946;
  animation: camBlink 1s ease-in-out infinite;
}
@keyframes camBlink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

/* ----------------------------------------------------------------
   Progress bar
   ---------------------------------------------------------------- */
.progress-track {
  width: 100%;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), #2a5298);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ----------------------------------------------------------------
   Timer circle
   ---------------------------------------------------------------- */
.timer-circle {
  position: relative;
  width: 72px;
  height: 72px;
}
.timer-circle svg {
  transform: rotate(-90deg);
}
.timer-circle .timer-bg {
  fill: none;
  stroke: #e2e8f0;
  stroke-width: 5;
}
.timer-circle .timer-arc {
  fill: none;
  stroke: var(--color-primary);
  stroke-width: 5;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear, stroke 0.3s;
}
.timer-circle .timer-arc.warning {
  stroke: var(--color-accent);
}
.timer-circle .timer-arc.danger {
  stroke: var(--color-secondary);
}
.timer-circle .timer-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-primary);
}
.timer-circle .timer-text.warning { color: #c48600; }
.timer-circle .timer-text.danger  { color: var(--color-secondary); }

/* ----------------------------------------------------------------
   Waveform animation (audio recording indicator)
   ---------------------------------------------------------------- */
.waveform {
  display: flex;
  align-items: center;
  gap: 3px;
  height: 40px;
}
.waveform .bar {
  width: 4px;
  border-radius: 2px;
  background: var(--color-secondary);
  animation: wave 0.8s ease-in-out infinite;
}
.waveform .bar:nth-child(1)  { animation-delay: 0s;    height: 12px; }
.waveform .bar:nth-child(2)  { animation-delay: 0.1s;  height: 24px; }
.waveform .bar:nth-child(3)  { animation-delay: 0.2s;  height: 36px; }
.waveform .bar:nth-child(4)  { animation-delay: 0.3s;  height: 28px; }
.waveform .bar:nth-child(5)  { animation-delay: 0.4s;  height: 20px; }
.waveform .bar:nth-child(6)  { animation-delay: 0.3s;  height: 32px; }
.waveform .bar:nth-child(7)  { animation-delay: 0.2s;  height: 40px; }
.waveform .bar:nth-child(8)  { animation-delay: 0.1s;  height: 24px; }
.waveform .bar:nth-child(9)  { animation-delay: 0s;    height: 16px; }

@keyframes wave {
  0%, 100% { transform: scaleY(0.4); }
  50%       { transform: scaleY(1); }
}

.waveform.idle .bar {
  background: #cbd5e1;
  height: 8px !important;
  animation: none;
}

/* ----------------------------------------------------------------
   German sentence display
   ---------------------------------------------------------------- */
.german-sentence {
  font-family: var(--font-german);
  font-size: clamp(1.25rem, 4vw, 2rem);
  line-height: 1.6;
  color: var(--color-primary);
  text-align: center;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.turkish-hint {
  font-family: var(--font-heading);
  font-size: clamp(0.875rem, 2.5vw, 1rem);
  color: var(--color-muted);
  text-align: center;
  font-style: italic;
  transition: opacity 0.3s, max-height 0.3s;
  overflow: hidden;
}
.turkish-hint.hidden-hint {
  opacity: 0;
  max-height: 0;
}
.turkish-hint.visible-hint {
  opacity: 1;
  max-height: 120px;
}

/* ----------------------------------------------------------------
   Proctoring warning overlay
   ---------------------------------------------------------------- */
.proctor-warning {
  position: fixed;
  inset: 0;
  background: rgba(230,57,70,0.92);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  text-align: center;
  padding: 2rem;
  backdrop-filter: blur(4px);
  animation: warningFadeIn 0.2s ease-out;
}
@keyframes warningFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.proctor-warning.hidden { display: none; }

.proctor-warning .warning-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  animation: warningShake 0.5s ease-in-out;
}
@keyframes warningShake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-8px); }
  75%       { transform: translateX(8px); }
}

/* ----------------------------------------------------------------
   Toast notifications
   ---------------------------------------------------------------- */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: calc(100vw - 2rem);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1.125rem;
  border-radius: 0.875rem;
  background: #ffffff;
  box-shadow: 0 8px 30px rgba(0,0,0,0.18);
  color: var(--color-text);
  font-size: 0.9rem;
  font-weight: 500;
  max-width: 360px;
  pointer-events: auto;
  animation: toastSlideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  border-left: 4px solid var(--color-primary);
}
.toast.toast-success { border-left-color: var(--color-success); }
.toast.toast-error   { border-left-color: var(--color-secondary); }
.toast.toast-warning { border-left-color: var(--color-accent); }
.toast.toast-info    { border-left-color: var(--color-primary); }

.toast.toast-exit {
  animation: toastSlideOut 0.25s ease-in forwards;
}

.toast-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
  margin-top: 1px;
}
.toast-body { flex: 1; line-height: 1.4; }

@keyframes toastSlideIn {
  from { opacity: 0; transform: translateX(40px) scale(0.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes toastSlideOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

/* ----------------------------------------------------------------
   Score / result animations
   ---------------------------------------------------------------- */
@keyframes scoreCountUp {
  from { opacity: 0; transform: scale(0.5) translateY(20px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.score-display {
  animation: scoreCountUp 0.8s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.score-ring {
  stroke-dasharray: 283;
  stroke-dashoffset: 283;
  transition: stroke-dashoffset 1.5s cubic-bezier(0.4, 0, 0.2, 1) 0.5s;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(24px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in-up { animation: fadeInUp 0.5s ease-out forwards; }

/* Stagger children */
.stagger > * { opacity: 0; }
.stagger > *:nth-child(1)  { animation: fadeInUp 0.4s ease-out 0.1s forwards; }
.stagger > *:nth-child(2)  { animation: fadeInUp 0.4s ease-out 0.2s forwards; }
.stagger > *:nth-child(3)  { animation: fadeInUp 0.4s ease-out 0.3s forwards; }
.stagger > *:nth-child(4)  { animation: fadeInUp 0.4s ease-out 0.4s forwards; }
.stagger > *:nth-child(5)  { animation: fadeInUp 0.4s ease-out 0.5s forwards; }
.stagger > *:nth-child(6)  { animation: fadeInUp 0.4s ease-out 0.6s forwards; }
.stagger > *:nth-child(7)  { animation: fadeInUp 0.4s ease-out 0.7s forwards; }
.stagger > *:nth-child(8)  { animation: fadeInUp 0.4s ease-out 0.8s forwards; }
.stagger > *:nth-child(9)  { animation: fadeInUp 0.4s ease-out 0.9s forwards; }
.stagger > *:nth-child(10) { animation: fadeInUp 0.4s ease-out 1.0s forwards; }

/* ----------------------------------------------------------------
   Question card
   ---------------------------------------------------------------- */
.question-card {
  background: #ffffff;
  border-radius: 1.5rem;
  box-shadow: 0 12px 50px rgba(30,58,95,0.12);
  padding: 2rem 1.5rem;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

/* ----------------------------------------------------------------
   Score badge
   ---------------------------------------------------------------- */
.score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.score-badge.excellent { background: #d1fae5; color: #065f46; }
.score-badge.good      { background: #dbeafe; color: #1e40af; }
.score-badge.average   { background: #fef3c7; color: #92400e; }
.score-badge.poor      { background: #fee2e2; color: #991b1b; }
.score-badge.unscored  { background: #f1f5f9; color: #64748b; }

/* ----------------------------------------------------------------
   Loading spinner
   ---------------------------------------------------------------- */
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(30,58,95,0.15);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.spinner-sm {
  width: 20px;
  height: 20px;
  border-width: 3px;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ----------------------------------------------------------------
   Status indicator dots
   ---------------------------------------------------------------- */
.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.dot-green  { background: var(--color-success); }
.dot-red    { background: var(--color-secondary); }
.dot-yellow { background: var(--color-accent); }

/* ----------------------------------------------------------------
   Print styles for result page
   ---------------------------------------------------------------- */
@media print {
  body { background: #ffffff !important; }
  .no-print { display: none !important; }
  .camera-preview { display: none !important; }
  .proctor-warning { display: none !important; }
  #toast-container { display: none !important; }
  .card { box-shadow: none !important; border: 1px solid #e2e8f0 !important; }
  a { color: inherit !important; text-decoration: none !important; }

  @page {
    margin: 1.5cm;
    size: A4 portrait;
  }
}

/* ----------------------------------------------------------------
   Responsive utilities
   ---------------------------------------------------------------- */
@media (max-width: 480px) {
  .mic-btn { width: 84px; height: 84px; font-size: 2rem; }
  .mic-btn.recording::before,
  .mic-btn.recording::after { display: none; }
  .question-card { padding: 1.25rem 1rem; border-radius: 1rem; }
  .camera-preview { width: 80px; height: 60px; }
}

@media (min-width: 768px) {
  .question-card { padding: 2.5rem 2rem; }
}

/* ----------------------------------------------------------------
   Accessibility - focus visible
   ---------------------------------------------------------------- */
:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: 4px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .card, .question-card { border: 2px solid #000; }
  .btn { border: 2px solid currentColor; }
}

/* Reduce motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
