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

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Welcome screen ───────────────────────────────────────── */
#welcome-screen {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(150deg, #0c0c1e 0%, #0a0a0a 55%, #1a0a12 100%);
    transition: opacity 0.7s ease;
    overflow: hidden;
}

#welcome-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Soft ambient glow behind content */
#welcome-glow {
    position: absolute;
    width: 500px;
    height: 500px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(110, 70, 255, 0.10) 0%, transparent 70%);
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    animation: glowPulse 5s ease-in-out infinite;
}

@keyframes glowPulse {
    0%, 100% { opacity: 0.6; transform: translate(-50%, -50%) scale(1); }
    50%       { opacity: 1;   transform: translate(-50%, -50%) scale(1.2); }
}

#welcome-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 0 40px;
    gap: 0;
    position: relative;
}

#welcome-title {
    font-size: clamp(44px, 13vw, 68px);
    font-weight: 800;
    color: #fff;
    margin: 0;
    line-height: 1.05;
    letter-spacing: -0.03em;
}

#welcome-tagline {
    font-size: clamp(14px, 3.8vw, 18px);
    color: rgba(255, 255, 255, 0.45);
    margin: 14px 0 0;
    font-weight: 400;
    letter-spacing: 0.025em;
}

#start-btn {
    margin-top: 48px;
    padding: 18px 48px;
    border-radius: 50px;
    border: none;
    background: #fff;
    color: #111;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 0.01em;
    transition: transform 0.15s ease, opacity 0.15s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

#start-btn:active {
    transform: scale(0.95);
    opacity: 0.82;
}

/* ── Scan overlay ─────────────────────────────────────────── */
#scan-overlay {
    position: fixed;
    inset: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    transition: opacity 0.4s ease;
}

#scan-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Toggle between loading and scan guide */
.guide-hidden {
    display: none !important;
}

/* ── Loading guide (phase 1) ──────────────────────────────── */
#loading-guide {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    background: rgba(0, 0, 0, 0.72);
    padding: 36px 48px;
    border-radius: 20px;
}

#loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.guide-text {
    color: rgba(255, 255, 255, 0.85);
    font-size: 15px;
    font-weight: 400;
    text-align: center;
    margin: 0;
}

/* ── Scan guide (phase 2) ─────────────────────────────────── */
#scan-guide {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 0 32px;
}

#postcard-frame {
    position: relative;
    width: min(72vw, 320px);
}

#postcard-preview {
    width: 100%;
    border-radius: 10px;
    opacity: 0.4;
    display: block;
    user-select: none;
    -webkit-user-drag: none;
}

/* Corner markers */
#postcard-frame::before,
#postcard-frame::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-color: #fff;
    border-style: solid;
    opacity: 0.8;
}

#postcard-frame::before {
    top: -4px; left: -4px;
    border-width: 2px 0 0 2px;
    border-radius: 3px 0 0 0;
}

#postcard-frame::after {
    top: -4px; right: -4px;
    border-width: 2px 2px 0 0;
    border-radius: 0 3px 0 0;
}

#scan-hint {
    color: rgba(255, 255, 255, 0.95);
    font-size: 16px;
    font-weight: 500;
    text-align: center;
    margin: 0;
    letter-spacing: 0.01em;
    background: rgba(0, 0, 0, 0.55);
    padding: 12px 22px;
    border-radius: 18px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* ── Hint bar ─────────────────────────────────────────────── */
#hint-bar {
    position: fixed;
    bottom: 155px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none;
    transition: opacity 0.3s ease;
    white-space: nowrap;
}

#hint-bar.hidden {
    opacity: 0;
}

#hint-text {
    display: block;
    color: rgba(255, 255, 255, 0.95);
    font-size: 13px;
    font-weight: 500;
    background: rgba(0, 0, 0, 0.55);
    padding: 8px 18px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    text-align: center;
}

/* ── Recording countdown overlay ──────────────────────────── */
#record-overlay {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: rgba(0, 0, 0, 0.55);
    pointer-events: none;
    transition: opacity 0.2s ease;
}

#record-overlay.hidden {
    opacity: 0;
}

#record-ring {
    width: 110px;
    height: 110px;
    border-radius: 50%;
    border: 3px solid rgba(220, 38, 38, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: recordPulse 1s ease-in-out infinite;
}

#record-count {
    color: #fff;
    font-size: 48px;
    font-weight: 700;
    line-height: 1;
}

#record-label {
    color: #fff;
    font-size: 17px;
    font-weight: 600;
    margin: 0;
}

#record-sublabel {
    color: rgba(255, 255, 255, 0.65);
    font-size: 13px;
    margin: 0;
}

@keyframes recordPulse {
    0%, 100% { border-color: rgba(220, 38, 38, 0.85); transform: scale(1); }
    50%       { border-color: rgba(220, 38, 38, 1);    transform: scale(1.06); }
}

/* ── Recording info bottom sheet ─────────────────────────── */
#record-info-modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: flex-end;
    pointer-events: all;
    transition: opacity 0.3s ease;
}

#record-info-modal.hidden {
    opacity: 0;
    pointer-events: none;
}

#record-info-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

#record-info-sheet {
    position: relative;
    width: 100%;
    background: rgba(18, 18, 28, 0.97);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-radius: 24px 24px 0 0;
    padding: 12px 24px 48px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    transform: translateY(0);
    transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

#record-info-modal.hidden #record-info-sheet {
    transform: translateY(110%);
}

#record-info-handle {
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.2);
    align-self: center;
    margin-bottom: 4px;
}

#record-info-title {
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.01em;
}

#record-steps {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.record-step {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}

.step-num {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 1px;
}

.step-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.step-body strong {
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    display: block;
}

.step-body span {
    color: rgba(255, 255, 255, 0.45);
    font-size: 13px;
}

#record-info-start {
    width: 100%;
    padding: 16px;
    border-radius: 14px;
    border: none;
    background: #fff;
    color: #111;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

#record-info-start:active {
    opacity: 0.82;
    transform: scale(0.98);
}

#record-info-cancel {
    width: 100%;
    padding: 10px;
    border-radius: 14px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.4);
    font-size: 15px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    margin-top: -8px;
}

/* ── Bottom UI ────────────────────────────────────────────── */
#ui {
    position: fixed;
    bottom: 50px;
    left: 0;
    right: 0;
    padding: 16px 20px 36px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.55), transparent);
    pointer-events: none;
    z-index: 10;
}

#room-buttons {
    display: flex;
    gap: 10px;
    pointer-events: all;
}

.room-btn {
    padding: 10px 20px;
    border-radius: 22px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: rgba(255, 255, 255, 0.65);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

.room-btn.active {
    background: rgba(255, 255, 255, 0.92);
    border-color: transparent;
    color: #111;
}

/* ── Mic button ───────────────────────────────────────────── */
#mic-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    pointer-events: all;
    transition: background 0.2s, border-color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

#mic-btn.recording {
    background: rgba(220, 38, 38, 0.85);
    border-color: rgba(220, 38, 38, 0.9);
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); }
    50%       { box-shadow: 0 0 0 10px rgba(220, 38, 38, 0); }
}
