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

html {
    font-size: 16px; /* Prevents iOS auto-zoom on inputs */
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f7f7f8;
    color: #1a1a1a;
    min-height: 100dvh;
    overscroll-behavior: none; /* Prevents pull-to-refresh on iOS */
    -webkit-overflow-scrolling: touch;
}

/* Screen containers */
.screen {
    display: none;
    max-width: 640px;
    margin: 0 auto;
    padding: 24px 16px;
    min-height: 100dvh;
}

.screen.active {
    display: flex;
    flex-direction: column;
}

/* ---------- Login Screen ---------- */
#login-screen {
    justify-content: center;
    align-items: center;
    gap: 24px;
}

.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 32px 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.login-card h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
    text-align: center;
}

.login-card p {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 24px;
    text-align: center;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: #333;
    margin-bottom: 6px;
}

.form-group input {
    width: 100%;
    padding: 12px 14px;
    font-size: 16px; /* iOS: prevents auto-zoom */
    border: 1.5px solid #ddd;
    border-radius: 10px;
    background: #fafafa;
    transition: border-color 0.2s;
    -webkit-appearance: none;
}

.form-group input:focus {
    outline: none;
    border-color: #f4845f;
    background: #fff;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 14px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    -webkit-tap-highlight-color: transparent;
    min-height: 48px; /* Touch-friendly target */
    width: 100%;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #f4845f;
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: #e8714b;
}

.btn-secondary {
    background: #e8e8ec;
    color: #333;
}

.btn-secondary:hover:not(:disabled) {
    background: #d8d8dc;
}

.btn-blue {
    background: #4285f4;
    color: #fff;
}

.btn-blue:hover:not(:disabled) {
    background: #3367d6;
}

.btn-green {
    background: #34a853;
    color: #fff;
}

.btn-green:hover:not(:disabled) {
    background: #2d9249;
}

.btn-danger {
    background: #d93025;
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: #c22a1f;
}

.error-message {
    color: #d93025;
    font-size: 0.85rem;
    margin-top: 8px;
    text-align: center;
    min-height: 1.2em;
}

/* ---------- Permissions Screen ---------- */
#permissions-screen {
    justify-content: center;
    align-items: center;
    gap: 16px;
}

.permissions-card {
    background: #fff;
    border-radius: 16px;
    padding: 32px 24px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    text-align: center;
}

.permissions-card h2 {
    font-size: 1.3rem;
    margin-bottom: 8px;
}

.permissions-card p {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 24px;
}

.permission-step {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-radius: 12px;
    background: #f7f7f8;
    margin-bottom: 12px;
    text-align: left;
}

.permission-step .step-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.permission-step .step-text {
    flex: 1;
}

.permission-step .step-text strong {
    display: block;
    font-size: 0.9rem;
    margin-bottom: 2px;
}

.permission-step .step-text span {
    font-size: 0.8rem;
    color: #888;
}

.step-status {
    font-size: 1.2rem;
    flex-shrink: 0;
}

.step-status.pending { color: #ccc; }
.step-status.success { color: #34a853; }
.step-status.error { color: #d93025; }

.permissions-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
}

/* ---------- Interview Screen ---------- */
#interview-screen {
    padding-top: 12px;
    padding-bottom: 0;
}

.interview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px 12px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    background: #f7f7f8;
    z-index: 10;
}

.interview-header .title {
    font-size: 1rem;
    font-weight: 600;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: #888;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
}

.status-dot.connected { background: #34a853; }
.status-dot.connecting { background: #fbbc04; animation: pulse 1s infinite; }
.status-dot.disconnected { background: #d93025; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 0;
    -webkit-overflow-scrolling: touch;
}

.message {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    animation: fadeIn 0.2s ease;
}

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.message.assistant .message-avatar {
    background: #e8e8ec;
}

.message.user .message-avatar {
    background: #dce8fd;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-role {
    font-size: 0.75rem;
    font-weight: 600;
    color: #888;
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.message-text {
    font-size: 0.95rem;
    line-height: 1.55;
    color: #1a1a1a;
    word-wrap: break-word;
}

.message-text .cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: #f4845f;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 0.8s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Push-to-talk button */
.btn-talk {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 24px;
    font-size: 1.05rem;
    font-weight: 600;
    background: #f4845f;
    color: #fff;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    min-height: 56px;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.btn-talk:disabled {
    background: #f4b8a5;
    cursor: not-allowed;
}

.btn-talk:not(:disabled):hover {
    background: #e8714b;
}

.btn-talk:not(:disabled):active,
.btn-talk.recording {
    background: #d93025;
    transform: scale(0.97);
}

.btn-talk .talk-icon {
    font-size: 1.3rem;
}

.btn-talk.recording .talk-icon {
    animation: pulse 0.6s infinite;
}

.interview-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 0 max(12px, env(safe-area-inset-bottom));
    border-top: 1px solid #eee;
    flex-shrink: 0;
    gap: 12px;
}

.footer-hint {
    text-align: center;
    font-size: 0.8rem;
    color: #888;
    padding-bottom: 4px;
    min-height: 1.4em;
    flex-shrink: 0;
}

.btn-quit {
    padding: 10px 20px;
    font-size: 0.85rem;
    min-height: 40px;
    width: auto;
    flex-shrink: 0;
}

/* ---------- End Screen ---------- */
#end-screen {
    justify-content: center;
    align-items: center;
    gap: 16px;
}

.end-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px 24px;
    width: 100%;
    max-width: 480px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    text-align: center;
}

.end-card .end-icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.end-card h2 {
    font-size: 1.3rem;
    margin-bottom: 16px;
}

.end-card p {
    font-size: 0.95rem;
    color: #444;
    line-height: 1.6;
}

/* ---------- Reconnect overlay ---------- */
.reconnect-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 100;
    justify-content: center;
    align-items: center;
}

.reconnect-overlay.active {
    display: flex;
}

.reconnect-card {
    background: #fff;
    border-radius: 16px;
    padding: 32px 24px;
    max-width: 360px;
    width: 90%;
    text-align: center;
}

.reconnect-card h3 {
    margin-bottom: 12px;
}

.reconnect-card p {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 20px;
}

.reconnect-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.reconnect-actions .btn {
    width: auto;
    padding: 10px 24px;
}

/* ---------- Responsive ---------- */
@media (max-width: 480px) {
    .screen {
        padding: 16px 12px;
    }

    .login-card,
    .permissions-card,
    .end-card {
        padding: 24px 16px;
        border-radius: 12px;
    }

    .message {
        gap: 8px;
    }

    .message-avatar {
        width: 28px;
        height: 28px;
        font-size: 0.95rem;
    }
}

/* Hidden audio element */
#remote-audio {
    display: none;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #ccc;
    border-top-color: #f4845f;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

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