/* =============================================
   Voice Recorder — style.css
   Mobile-first, fullscreen, light/dark theme
   ============================================= */

/* 1. CSS Custom Properties (light theme default) */
:root {
    --bg: #ffffff;
    --text: #1a1a1a;
    --accent: #00b894;
    --accent-bright: #00d2a0;
    --surface: #f5f5f5;
    --error: #e74c3c;
    --error-bg: #fef0ef;
    --btn-record: #e74c3c;
    --btn-record-hover: #c0392b;
    --btn-stopped: #00b894;
    --toast-bg: rgba(0,0,0,0.8);
    --toast-text: #ffffff;
    --step-inactive: #ccc;
}

/* 2. Dark theme override */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1a1a1a;
        --text: #f0f0f0;
        --accent: #00d2a0;
        --accent-bright: #00e6b0;
        --surface: #2d2d2d;
        --error: #ff6b6b;
        --error-bg: #3d2020;
        --btn-record: #ff4444;
        --btn-record-hover: #cc3333;
        --btn-stopped: #00d2a0;
        --toast-bg: rgba(255,255,255,0.9);
        --toast-text: #1a1a1a;
        --step-inactive: #555;
    }
}

/* 3. Base layout */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

/* 3b. Loading spinner */
.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--surface);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* 4. State visibility system */
#app {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 400px;
    height: 100dvh;
    padding: 0 24px;
    position: relative;
}

.state { display: none; flex-direction: column; align-items: center; gap: 16px; }
.state.active { display: flex; }

/* 5. Record button wrapper */
.btn-wrapper {
    position: absolute;
    bottom: 12vh;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
}

.btn-ring-container {
    position: relative;
    width: 80px;
    height: 80px;
}

/* 5b. Record button */
.record-btn {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: none;
    background: var(--btn-record);
    cursor: pointer;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease, transform 0.1s ease;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: none;
}

.record-btn:hover {
    background: var(--btn-record-hover);
}

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

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.08); }
}

.record-btn.recording {
    animation: pulse 1.5s ease-in-out infinite;
}

.record-btn.stopped {
    background: var(--btn-stopped);
}

/* 6. Timer */
#timer {
    font-size: 48px;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
    letter-spacing: 2px;
    color: var(--text);
}

/* 7. Canvas waveform */
#waveform {
    width: 100%;
    max-width: 360px;
    height: 80px;
}

/* 8. Long-press ring (SVG overlay) */
.long-press-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 96px;
    height: 96px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}

.long-press-ring.visible {
    opacity: 1;
}

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

.ring-progress {
    fill: none;
    stroke: var(--accent);
    stroke-width: 4;
    stroke-dasharray: 283;  /* 2 * PI * 45 */
    stroke-dashoffset: 283;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    transition: stroke-dashoffset 0.1s linear;
}

/* 9. Error state */
.error-icon {
    font-size: 48px;
    color: var(--error);
}

.error-text {
    font-size: 18px;
    font-weight: 600;
    color: var(--error);
    text-align: center;
}

.error-instructions {
    font-size: 14px;
    color: var(--text);
    opacity: 0.8;
    text-align: center;
    max-width: 300px;
    line-height: 1.5;
}

.btn-retry {
    padding: 12px 24px;
    border-radius: 8px;
    border: 2px solid var(--accent);
    background: transparent;
    color: var(--accent);
    font-size: 16px;
    cursor: pointer;
}

/* 10. Success animation */
.success-animation {
    font-size: 64px;
    color: var(--btn-stopped);
    animation: scaleIn 0.4s ease-out;
}

@keyframes scaleIn {
    from { transform: scale(0); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* 11. Toast */
.toast {
    position: fixed;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    border-radius: 20px;
    background: var(--toast-bg);
    color: var(--toast-text);
    font-size: 14px;
    z-index: 10;
}

.toast[hidden] { display: none; }

/* 12. Hints */
.hint {
    font-size: 14px;
    color: var(--text);
    opacity: 0.6;
    text-align: center;
}

.hint-stop {
    font-size: 12px;
    margin-top: 8px;
}

/* 12b. Hero block (idle state) */
#state-idle {
    position: absolute;
    top: 8vh;
    left: 0;
    right: 0;
    padding: 0 24px;
}

.hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    max-width: 320px;
    margin: 0 auto;
}

.hero-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.35;
}

.hero-subtitle {
    font-size: 13px;
    color: var(--text);
    opacity: 0.45;
    font-weight: 400;
    letter-spacing: 0.02em;
}

.hero-cta {
    margin-top: 4px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.hero-action {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    line-height: 1.4;
    letter-spacing: 0.03em;
}

.hero-benefit {
    font-size: 14px;
    color: var(--text);
    opacity: 0.65;
    line-height: 1.6;
}

/* Button label under record button */
.btn-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    opacity: 0.5;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-top: 12px;
    text-align: center;
}

.hero-hint {
    margin-top: 8px;
    font-size: 14px;
    color: var(--text);
    opacity: 0.45;
    font-style: italic;
}

/* 13. Button icons */
.btn-icon {
    font-size: 32px;
    line-height: 1;
    color: white;
}

.btn-icon[hidden] { display: none; }

/* 14. Status text */
.status-text {
    font-size: 18px;
    font-weight: 500;
    color: var(--text);
}

/* 15. Final duration (stopped state) */
#final-duration {
    font-size: 16px;
    color: var(--text);
    opacity: 0.7;
}

/* 16. Upload progress */
#upload-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 0;
}

#upload-status[hidden] { display: none; }

.upload-progress-track {
    width: 100%;
    max-width: 280px;
    height: 8px;
    background: var(--surface);
    border-radius: 4px;
    overflow: hidden;
}

.upload-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 4px;
    /* transition handled by JS smooth interpolation */
}

.upload-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.connectivity-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    transition: background-color 0.3s ease;
}

.connectivity-dot.offline {
    background: var(--error);
}

#upload-text {
    font-size: 14px;
    font-weight: 400;
    color: var(--text);
    opacity: 0.7;
    line-height: 1.5;
}

#upload-text.offline {
    color: var(--error);
    opacity: 1;
}

/* Backoff pulsing dot animation */
@keyframes dotPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.connectivity-dot.retrying {
    animation: dotPulse 1s ease-in-out infinite;
}

/* Upload complete fade-out */
.upload-fade-out {
    opacity: 0;
    transition: opacity 0.3s ease-out;
}

/* 17. Step Progress Indicator (Phase 31) */
.step-indicator {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    max-width: 320px;
    padding: 24px 0;
}

.step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.step-circle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--step-inactive);
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 300ms ease, background-color 300ms ease;
}

.step-number {
    font-size: 14px;
    font-weight: 400;
    color: var(--step-inactive);
    line-height: 1;
    transition: color 300ms ease, transform 200ms ease-out;
}

.step-label {
    font-size: 14px;
    font-weight: 400;
    color: var(--text);
    opacity: 0.6;
    line-height: 1.2;
    margin-top: 4px;
    transition: opacity 300ms ease;
}

.step.active .step-circle {
    border-color: var(--accent);
}

.step.active .step-number {
    color: var(--accent);
}

.step.active .step-label {
    opacity: 1.0;
}

.step.completed .step-circle {
    border: none;
    background: var(--accent);
}

.step.completed .step-number {
    color: white;
    /* Replace number with checkmark via JS */
}

.step.completed .step-label {
    opacity: 1.0;
}

.step-line {
    width: 40px;
    height: 2px;
    background: var(--step-inactive);
    margin: 0 8px;
    margin-top: 14px; /* Align to center of 28px circle */
    transition: background-color 200ms ease;
}

.step-line.completed {
    background: var(--accent);
}

/* 18. End Screen */
#state-result {
    width: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 32px;
}

#state-result.active {
    display: flex;
}

.end-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
}

.end-icon {
    font-size: 56px;
    color: var(--accent);
    animation: scaleIn 0.4s ease-out;
}

.end-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

.end-message {
    font-size: 15px;
    color: var(--text);
    opacity: 0.6;
    line-height: 1.5;
    max-width: 280px;
}

#btn-new-recording {
    padding: 14px 32px;
    font-size: 16px;
    background: transparent;
    border: 2px solid var(--accent);
    border-radius: 8px;
    color: var(--accent);
    cursor: pointer;
}

.speaker-label {
    display: block;
    font-size: 20px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
    margin-top: 16px;
    margin-bottom: 4px;
}

.speaker-label:first-child {
    margin-top: 0;
}

.transcript-paragraph {
    font-size: 16px;
    font-weight: 400;
    color: var(--text);
    line-height: 1.6;
    margin-bottom: 8px;
}

#btn-new-recording {
    position: sticky;
    bottom: 16px;
    padding: 16px 24px;
    margin-top: 16px;
    width: 100%;
    font-size: 16px;
    background: var(--bg);
}

/* Result page slide-in animation */
@keyframes resultSlideIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

#state-result.active .transcription-text {
    animation: resultSlideIn 300ms ease-out;
}

/* Status text fade */
#transcribe-status {
    transition: opacity 150ms ease;
}
