:root {
    /* Basecoat (shadcn) theme overrides — Florence brand */
    --primary: #10a37f;
    --primary-foreground: #ffffff;
    --background: #f9fafb;
    --ring: #10a37f;

    /* Brand Colors */
    --brand-primary: var(--primary);
    --brand-primary-dark: #0d8b6c;
    --brand-secondary: #6e56cf;

    /* Neutral Palette (aliases onto Basecoat tokens) */
    --surface: var(--card, #ffffff);
    --surface-hover: var(--muted, #f3f4f6);
    --text-primary: var(--foreground, #0d0d0d);
    --text-secondary: var(--muted-foreground, #676767);
    --text-tertiary: #8e8e8e;
    --border-color: var(--border, #e5e7eb);

    /* Semantic Colors */
    --success: #10a37f;
    --warning: #fbbf24;
    --error: #ef4444;
    --listening: #ef4444;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --shadow-xl: 0 20px 40px rgba(0,0,0,0.12);

    /* Typography */
    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;

    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;
}

/* Layered so Basecoat's component styles (components layer) keep their padding */
@layer base {
    * {
        box-sizing: border-box;
        margin: 0;
        padding: 0;
    }
}

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--background);
    height: 100vh;
    overflow: hidden;
    margin: 0;
    padding: 0;
    line-height: var(--leading-normal);
    color: var(--text-primary);
}

.container {
    background: var(--surface);
    max-width: 800px;
    width: 100%;
    height: 100vh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface);
    position: sticky;
    top: 0;
    z-index: 100;
    gap: 1rem;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-icon {
    width: var(--text-3xl);
    height: var(--text-3xl);
    display: block;
    object-fit: contain;
    flex-shrink: 0;
}

.header h1 {
    font-size: var(--text-2xl);
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.header p {
    display: none; /* Hide subtitle for cleaner look */
}

/* View Toggle */
.view-toggle {
    display: flex;
    background: var(--surface-hover);
    border-radius: calc(var(--radius, 0.625rem) - 2px);
    padding: 4px;
    gap: 4px;
}

.view-toggle-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.view-toggle-btn:hover {
    color: var(--text-primary);
}

.view-toggle-btn.active {
    background: var(--surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}

.connection-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #6b7280;
    transition: all 0.3s ease;
}

.connection-indicator.connecting {
    background: var(--warning);
    box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.2);
    animation: pulse-indicator 2s infinite;
}

.connection-indicator.connected {
    background: var(--success);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2);
}

.connection-indicator.disconnected {
    background: #6b7280;
}

@keyframes pulse-indicator {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    padding-bottom: 200px;
    scroll-behavior: smooth;
}

.chat-container.hidden,
.whiteboard-container.hidden {
    display: none;
}

/* Whiteboard Container */
.whiteboard-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.whiteboard-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--background);
    border-bottom: 1px solid var(--border-color);
}

.whiteboard-viewport {
    flex: 1;
    overflow-y: auto;
    background: linear-gradient(to bottom, #fefefe 0%, #fafafa 100%);
    position: relative;
}

.whiteboard-page {
    min-height: 100%;
    padding: 2rem 1.5rem;
    padding-bottom: 200px;
}

.page-content {
    max-width: 700px;
    margin: 0 auto;
    background: white;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: var(--shadow-sm);
    min-height: 400px;
    /* Lined paper effect */
    background-image:
        linear-gradient(90deg, #e5e7eb 1px, transparent 1px),
        linear-gradient(#f9fafb 23px, #e5e7eb 24px);
    background-size: 100% 24px;
    background-position: 0 0;
}

.page-topic {
    font-size: var(--text-2xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 3px solid var(--brand-primary);
    background: white;
}

/* Content Blocks */
.content-block {
    margin-bottom: 1.5rem;
    padding: 1rem;
    border-left: 4px solid var(--brand-primary);
    background: white;
    border-radius: 4px;
    animation: blockSlideIn 0.4s ease-out;
}

@keyframes blockSlideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.content-block.text-block {
    border-left-color: #6366f1;
}

.content-block.equation-block {
    border-left-color: #ec4899;
    text-align: center;
    font-size: var(--text-lg);
}

.equation-line {
    margin: 0.75rem 0;
    line-height: 2;
}

.equation-text {
    font-size: var(--text-base);
    color: var(--text-secondary);
    font-weight: 500;
    margin: 0.5rem 0;
    text-align: center;
}

.content-block.steps-block {
    border-left-color: #10b981;
}

.content-block.list-block {
    border-left-color: #f59e0b;
}

.block-content {
    color: var(--text-primary);
    line-height: var(--leading-relaxed);
}

.steps-block ol {
    margin: 0;
    padding-left: 1.5rem;
    list-style: decimal; /* Basecoat's reset strips list markers */
}

.steps-block li {
    margin-bottom: 0.75rem;
    line-height: var(--leading-relaxed);
}

.list-block ul {
    margin: 0;
    padding-left: 1.5rem;
    list-style: disc; /* Basecoat's reset strips list markers */
}

.list-block li {
    margin-bottom: 0.5rem;
}

/* Question Blocks */
.question-block {
    margin-bottom: 1.5rem;
    padding: 1rem 1.25rem;
    background: rgba(251, 191, 36, 0.1);
    border: 2px solid #f59e0b;
    border-radius: 0.5rem;
}

.question-text {
    color: var(--text-primary);
    font-size: var(--text-base);
    font-weight: 500;
    line-height: var(--leading-relaxed);
}

.question-hint {
    margin-top: 0.5rem;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    font-style: italic;
}

/* Drawing Blocks */
.drawing-block {
    margin-bottom: 1.5rem;
    padding: 1.5rem;
    background: white;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    animation: blockSlideIn 0.4s ease-out;
}

.drawing-block svg {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    text-align: center;
    color: var(--text-secondary);
}

.empty-icon {
    margin-bottom: 1rem;
    color: var(--text-tertiary);
    opacity: 0.7;
}

.empty-icon svg {
    display: block;
}

.empty-state p {
    margin: 0.5rem 0;
    font-size: var(--text-base);
}

.empty-hint {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    font-style: italic;
}

.status-banner {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: var(--text-sm);
    font-weight: 500;
    z-index: 200;
    max-width: 90%;
    animation: slideDown 0.3s ease-out;
    transition: opacity 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.status-banner.hidden {
    display: none;
}

.status-banner.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.status-banner.info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #93c5fd;
}

.status-banner.warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

.status-banner.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 1rem;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius, 0.625rem);
    box-shadow: var(--shadow-xl);
    padding: 2rem;
    max-width: 420px;
    width: 100%;
    text-align: center;
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-icon {
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.modal-icon svg {
    display: inline-block;
}

.modal h2 {
    font-size: var(--text-xl);
    margin-bottom: 0.75rem;
}

.modal p {
    font-size: var(--text-base);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
    margin-bottom: 1.5rem;
}

.modal a {
    color: var(--brand-primary);
    font-weight: 500;
}

.talk-button-container {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 800px;
    padding: 2rem 1.5rem;
    background: linear-gradient(to top, var(--surface) 70%, transparent);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    z-index: 50;
}

.talk-button {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: none;
    background: var(--brand-primary);
    color: white;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.talk-button:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: var(--shadow-xl);
}

.talk-button:active:not(:disabled) {
    transform: scale(0.98);
}

.talk-button:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    box-shadow: var(--shadow-sm);
}

.talk-button.live {
    background: rgba(253, 186, 116, 0.55);
    color: #7c2d12;
    animation: buttonPulse 1.5s infinite;
}

.talk-button.paused {
    background: rgba(134, 239, 172, 0.55);
    color: #14532d;
}

@keyframes buttonPulse {
    0% {
        box-shadow: var(--shadow-lg), 0 0 0 0 rgba(251, 146, 60, 0.6);
    }
    50% {
        box-shadow: var(--shadow-lg), 0 0 0 20px rgba(251, 146, 60, 0);
    }
    100% {
        box-shadow: var(--shadow-lg), 0 0 0 0 rgba(251, 146, 60, 0);
    }
}

.talk-button .icon svg {
    width: 2rem;
    height: 2rem;
    display: block;
}

.button-text {
    font-size: 0.625rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.spacebar-hint {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.talk-button:focus-visible {
    outline: 3px solid var(--brand-secondary);
    outline-offset: 4px;
}

.talk-button:focus:not(:focus-visible) {
    outline: none;
}

.transcript {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.transcript h3 {
    display: none; /* Hide "Conversation" heading */
}

.message {
    padding: 1rem 1.25rem;
    border-radius: 12px;
    margin-bottom: 1.5rem;
    max-width: 85%;
    line-height: var(--leading-relaxed);
    animation: messageSlideIn 0.3s ease-out;
}

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

.message.user {
    background: var(--brand-primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    background: var(--surface-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.message.system {
    background: #fef3c7;
    color: #92400e;
    text-align: center;
    font-size: var(--text-sm);
    padding: 0.75rem 1rem;
    max-width: 100%;
    border-radius: 8px;
}

.visualizer {
    display: flex;
    gap: 3px;
    height: 32px;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.5rem;
}

.visualizer-bar {
    width: 3px;
    background: var(--brand-primary);
    border-radius: 2px;
    transition: height 0.1s ease;
    opacity: 0.6;
}

.talk-button.live ~ .visualizer .visualizer-bar {
    background: var(--listening);
    opacity: 1;
}

.tips-section {
    margin: 1.5rem;
    padding: 1rem;
    background: #f0f9ff;
    border-radius: 8px;
    border: 1px solid #bae6fd;
}

.tips-section summary {
    color: var(--brand-secondary);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    list-style-position: inside;
}

.tips-section summary:hover {
    color: var(--brand-primary);
}

.tips-section ul {
    color: var(--text-secondary);
    padding-left: 1.25rem;
    margin-top: 0.75rem;
    line-height: var(--leading-relaxed);
    list-style: disc; /* Basecoat's reset strips list markers */
}

.tips-section li {
    margin-bottom: 0.5rem;
}

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

/* Mobile responsiveness */
@media (max-width: 640px) {
    .header {
        padding: 0.75rem 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .logo-icon {
        width: var(--text-2xl);
        height: var(--text-2xl);
    }

    .header h1 {
        font-size: var(--text-xl);
    }

    .view-toggle {
        order: 3;
        width: 100%;
    }

    .view-toggle-btn {
        flex: 1;
        padding: 0.4rem 0.75rem;
    }

    .chat-container {
        padding: 1rem;
        padding-bottom: 180px;
    }

    .message {
        max-width: 90%;
        font-size: var(--text-sm);
        padding: 0.875rem 1rem;
    }

    .whiteboard-page {
        padding: 1rem;
        padding-bottom: 180px;
    }

    .page-content {
        padding: 1rem;
    }

    .page-topic {
        font-size: var(--text-xl);
    }

    .content-block {
        padding: 0.75rem;
        font-size: var(--text-sm);
    }

    .drawing-block {
        padding: 1rem;
    }

    .whiteboard-nav {
        padding: 0.75rem 1rem;
    }

    .talk-button {
        width: 72px;
        height: 72px;
    }

    .talk-button .icon svg {
        width: 1.75rem;
        height: 1.75rem;
    }

    .talk-button-container {
        padding: 1.5rem 1rem;
    }

    .tips-section {
        margin: 1rem;
    }
}

/* Landscape mobile */
@media (max-height: 600px) and (orientation: landscape) {
    .talk-button-container {
        padding: 1rem;
        position: relative;
        background: none;
    }

    .chat-container {
        padding-bottom: 140px;
    }
}

/* Auth Page Styles */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: var(--background);
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius, 0.625rem);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    padding: 2.5rem;
    animation: fadeInUp 0.5s ease-out;
}

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

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header .logo-icon {
    width: 3rem;
    height: 3rem;
    display: block;
    margin: 0 auto 0.5rem;
}

.auth-header h1 {
    font-size: var(--text-3xl);
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.auth-subtitle {
    font-size: var(--text-base);
    color: var(--text-secondary);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.error-message,
.success-message {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-size: var(--text-sm);
    margin-top: -0.5rem;
}

.error-message {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fca5a5;
}

.success-message {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
}

.error-message.hidden,
.success-message.hidden {
    display: none;
}

/* Layout tweaks on top of Basecoat's .btn */
.auth-submit-btn {
    width: 100%;
    margin-top: 0.5rem;
}

.auth-toggle {
    text-align: center;
    margin-top: 1.5rem;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.auth-toggle a {
    color: var(--brand-primary);
    text-decoration: none;
    font-weight: 600;
    margin-left: 0.25rem;
}

.auth-toggle a:hover {
    text-decoration: underline;
}

/* Header right container */
.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Mobile auth page */
@media (max-width: 640px) {
    .auth-container {
        padding: 1rem;
    }

    .auth-card {
        padding: 2rem 1.5rem;
    }

    .auth-header h1 {
        font-size: var(--text-2xl);
    }

    .header-right {
        gap: 0.5rem;
    }
}
