/* ========================================
   HupHup Friend Webapp — Styles
   ======================================== */

:root {
  --primary: #FF6B35;
  --primary-dark: #E55A28;
  --primary-light: #FF8F62;
  --primary-glow: rgba(255, 107, 53, 0.25);
  --bg: #FFFAF7;
  --surface: #FFFFFF;
  --text: #1A1A2E;
  --text-secondary: #6B7280;
  --border: #E5E7EB;
  --danger: #EF4444;
  --success: #10B981;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ========================================
   Screen system
   ======================================== */

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.35s ease, visibility 0.35s ease;
  z-index: 1;
}

.screen.active {
  opacity: 1;
  visibility: visible;
  z-index: 10;
}

.screen-content {
  width: 100%;
  max-width: 420px;
  padding: 32px 24px;
  text-align: center;
  position: relative;
}

/* ========================================
   Typography
   ======================================== */

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}

.subtitle {
  font-size: 1.05rem;
  color: var(--text-secondary);
  margin-bottom: 32px;
  line-height: 1.55;
}

.emoji-hero {
  font-size: 4rem;
  margin-bottom: 20px;
  line-height: 1;
}

/* ========================================
   Buttons
   ======================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 16px 40px;
  border: none;
  border-radius: 50px;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  min-height: 56px;
  width: 100%;
  max-width: 320px;
  position: relative;
  overflow: hidden;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 16px var(--primary-glow);
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 6px 24px rgba(255, 107, 53, 0.35);
}

.btn-primary:disabled {
  background: #D1D5DB;
  box-shadow: none;
  cursor: not-allowed;
  color: #9CA3AF;
}

.btn-primary:disabled:active {
  transform: none;
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border);
}

.btn-secondary:hover {
  border-color: #CCC;
  background: #F9FAFB;
}

/* ========================================
   Input
   ======================================== */

.input-wrapper {
  position: relative;
  margin-bottom: 28px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

#input-name {
  width: 100%;
  padding: 16px 20px;
  padding-right: 60px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

#input-name:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

#input-name::placeholder {
  color: #B0B0B0;
}

.char-count {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  color: var(--text-secondary);
  pointer-events: none;
}

/* ========================================
   Record button
   ======================================== */

.record-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.timer {
  font-size: 2.5rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  letter-spacing: 0.02em;
}

.timer-bar-wrapper {
  width: 100%;
  max-width: 260px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.15s linear;
}

.btn-record {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  border: 4px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  position: relative;
  padding: 0;
}

.btn-record:hover {
  border-color: #CCC;
}

.btn-record-inner {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--danger);
  transition: all 0.2s ease;
}

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

.btn-record.recording .btn-record-inner {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}

@keyframes record-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
  50% { box-shadow: 0 0 0 16px rgba(239, 68, 68, 0); }
}

.record-hint {
  font-size: 0.95rem;
  color: var(--text-secondary);
  min-height: 1.5em;
}

/* ========================================
   Audio player / waveform
   ======================================== */

.player {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin-bottom: 28px;
  box-shadow: var(--shadow);
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}

.btn-play {
  width: 52px;
  height: 52px;
  min-width: 52px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  padding: 0;
}

.btn-play:hover {
  background: var(--primary-dark);
}

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

.waveform-container {
  flex: 1;
  min-width: 0;
  position: relative;
}

#waveform {
  width: 100%;
  display: block;
}

.playback-time {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}

/* ========================================
   Review buttons
   ======================================== */

.review-buttons {
  display: flex;
  gap: 12px;
  max-width: 360px;
  margin: 0 auto;
}

.review-buttons .btn {
  flex: 1;
  padding: 14px 12px;
  min-height: 52px;
}

/* ========================================
   Loader
   ======================================== */

.loader {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 0 auto 16px;
}

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

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

/* ========================================
   Confetti canvas
   ======================================== */

#confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 100;
}

/* ========================================
   Done screen
   ======================================== */

#screen-done h1 {
  font-size: 2rem;
}

/* ========================================
   Mic instructions
   ======================================== */

.mic-instructions {
  text-align: left;
  max-width: 320px;
  margin: 0 auto 28px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}

.mic-instructions p {
  margin-bottom: 12px;
  font-size: 0.95rem;
}

.mic-instructions ol {
  padding-left: 20px;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.mic-instructions li {
  margin-bottom: 6px;
}

/* ========================================
   Animations for screen transitions
   ======================================== */

.screen.active .screen-content {
  animation: fadeUp 0.4s ease forwards;
}

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

/* ========================================
   Safe area handling (notch/home indicator)
   ======================================== */

@supports (padding: env(safe-area-inset-bottom)) {
  .screen-content {
    padding-bottom: calc(32px + env(safe-area-inset-bottom));
  }
}

/* ========================================
   Desktop / larger screens
   ======================================== */

@media (min-width: 600px) {
  h1 {
    font-size: 2.1rem;
  }

  .subtitle {
    font-size: 1.15rem;
  }

  .screen-content {
    padding: 48px 32px;
  }

  .btn-record {
    width: 112px;
    height: 112px;
  }

  .btn-record-inner {
    width: 64px;
    height: 64px;
  }

  .btn-record.recording .btn-record-inner {
    width: 32px;
    height: 32px;
  }
}

/* ========================================
   Reduce motion preference
   ======================================== */

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
