* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    font-family: 'Nunito', sans-serif;
    background: #000;
    touch-action: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

.hidden {
    display: none !important;
}

/* Mode Toggle Styles */
.mode-toggle-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: rgba(90, 77, 58, 0.08);
    border-radius: 12px;
    border: 1px solid rgba(90, 77, 58, 0.15);
}

.mode-label {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 0.95rem;
    color: #5a4d3a;
    font-weight: 500;
    transition: color 0.3s ease, opacity 0.3s ease;
}

.mode-label-left {
    opacity: 1;
}

.mode-label-right {
    opacity: 0.5;
}

.mode-toggle-container:has(input:checked) .mode-label-left {
    opacity: 0.5;
}

.mode-toggle-container:has(input:checked) .mode-label-right {
    opacity: 1;
}

.mode-toggle {
    position: relative;
    display: inline-block;
    width: 56px;
    height: 28px;
}

.mode-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.mode-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #8b7355, #a08060);
    transition: 0.3s ease;
    border-radius: 28px;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.2);
}

.mode-toggle-slider:before {
    position: absolute;
    content: "";
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: linear-gradient(135deg, #fffdf5, #f4f1e8);
    transition: 0.3s ease;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.mode-toggle input:checked + .mode-toggle-slider {
    background: linear-gradient(135deg, #6b8e6b, #7da67d);
}

.mode-toggle input:checked + .mode-toggle-slider:before {
    transform: translateX(28px);
}

/* App mode toggle (top center when in app) */
.app-mode-toggle-container {
    position: fixed;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 14px;
    background: rgba(244, 241, 232, 0.9);
    border-radius: 20px;
    border: 1px solid rgba(90, 77, 58, 0.2);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 100;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.app-mode-toggle-container .mode-label {
    font-size: 0.8rem;
}

.mode-toggle-small {
    width: 44px;
    height: 22px;
}

.mode-toggle-small .mode-toggle-slider:before {
    height: 16px;
    width: 16px;
}

.mode-toggle-small input:checked + .mode-toggle-slider:before {
    transform: translateX(22px);
}

/* Mode Choice Screen */
#mode-choice-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f4f1e8;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    overflow-y: auto;
    overflow-x: hidden;
}

.mode-choice-content {
    position: relative;
    text-align: center;
    padding: 24px 16px;
    max-width: 100%;
    width: 100%;
    animation: fadeInUp 0.8s ease-out;
    z-index: 2;
}

.mode-choice-content h1 {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: clamp(1.6rem, 5vw, 2.2rem);
    font-weight: 600;
    color: #2c2416;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.mode-choice-subtitle {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: clamp(1.1rem, 4vw, 1.4rem);
    color: #5a4d3a;
    margin-bottom: 32px;
    font-style: italic;
}

.mode-choice-options {
    display: flex;
    justify-content: center;
    gap: 24px;
    flex-wrap: wrap;
    padding: 0 16px;
}

.mode-choice-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: clamp(140px, 40vw, 180px);
    height: clamp(180px, 50vw, 220px);
    background: #fffdf5;
    border: 2px solid rgba(44, 36, 22, 0.15);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 
        0 4px 12px rgba(44, 36, 22, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    padding: 20px;
}

.mode-choice-card:hover {
    transform: translateY(-4px);
    box-shadow: 
        0 8px 24px rgba(44, 36, 22, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.8);
    border-color: rgba(44, 36, 22, 0.25);
}

.mode-choice-card:active {
    transform: translateY(-2px);
}

.mode-choice-icon {
    width: clamp(80px, 25vw, 120px);
    height: clamp(80px, 25vw, 120px);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
}

.mode-choice-icon svg {
    width: 100%;
    height: 100%;
}

.mode-choice-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 4px 12px rgba(44, 36, 22, 0.2));
}

.mode-choice-label {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: clamp(1rem, 4vw, 1.3rem);
    font-weight: 600;
    color: #3d3222;
}

.mode-choice-sublabel {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: clamp(0.7rem, 2.5vw, 0.85rem);
    font-weight: 400;
    font-style: italic;
    color: #6b5d4a;
    margin-top: 4px;
    line-height: 1.2;
    text-align: center;
}

/* Dictation Introduction Screen */
#dictation-intro-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f4f1e8;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
}

.dictation-icon-container {
    width: clamp(100px, 30vw, 150px);
    height: clamp(100px, 30vw, 150px);
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dictation-icon-large {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 6px 20px rgba(44, 36, 22, 0.2));
}

/* Dictation Editor Styles */
#dictation-editor-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 140px;
    display: flex;
    flex-direction: column;
    padding: 16px;
    padding-bottom: 20px;
    z-index: 50;
    background: #f4f1e8;
}

.dictation-toolbar {
    display: flex;
    gap: 8px;
    padding: 8px;
    background: #fff;
    border: 2px solid #d4c9b5;
    border-bottom: none;
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -2px 8px rgba(44, 36, 22, 0.08);
}

.dictation-format-btn {
    width: 36px;
    height: 36px;
    background: #f4f1e8;
    border: 2px solid #d4c9b5;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Crimson Pro', Georgia, serif;
    font-size: 16px;
    color: #3d3222;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.dictation-format-btn:hover {
    background: #e8e3d8;
    border-color: #8b7355;
}

.dictation-format-btn:active,
.dictation-format-btn.active {
    background: #d4c9b5;
    border-color: #5a4d3a;
}

#dictation-editor {
    flex: 1;
    background: #fff;
    border: 2px solid #d4c9b5;
    border-top: none;
    border-radius: 0 0 12px 12px;
    padding: 16px;
    font-family: 'Crimson Pro', Georgia, serif;
    font-size: 18px;
    line-height: 1.6;
    color: #3d3222;
    overflow-y: auto;
    outline: none;
    min-height: 200px;
    box-shadow: 0 4px 16px rgba(44, 36, 22, 0.1);
}

#dictation-editor:empty:before {
    content: attr(placeholder);
    color: #a89f8a;
    font-style: italic;
}

#dictation-editor:focus {
    border-color: #8b7355;
    box-shadow: 0 4px 20px rgba(44, 36, 22, 0.15);
}

#dictation-status {
    position: fixed;
    bottom: 150px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(90, 77, 58, 0.9);
    color: #f4f1e8;
    padding: 8px 20px;
    border-radius: 20px;
    font-family: 'Nunito', sans-serif;
    font-size: 14px;
    font-weight: 600;
    z-index: 100;
    animation: pulse-status 1.5s ease-in-out infinite;
}

@keyframes pulse-status {
    0%, 100% { opacity: 0.9; }
    50% { opacity: 0.6; }
}

/* Dictation mode mic button adjustment */
body.dictation-mode #mic-btn {
    background: rgba(139, 115, 85, 0.9);
    border-color: rgba(244, 241, 232, 0.5);
}

body.dictation-mode #mic-btn.listening {
    background: rgba(255, 105, 180, 1);
    animation: pulse-mic 1.2s ease-in-out infinite;
}

#permission-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f4f1e8;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    overflow-y: auto;
    overflow-x: hidden;
}

.paper-texture {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background-image: 
        url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    opacity: 0.04;
    z-index: 1;
}

#permission-screen::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: 
        radial-gradient(ellipse at 20% 20%, rgba(139, 119, 101, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 80%, rgba(139, 119, 101, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 50%, rgba(255, 253, 245, 0.5) 0%, transparent 70%);
    pointer-events: none;
    z-index: 0;
}

.permission-content {
    position: relative;
    text-align: center;
    padding: 16px 16px 24px;
    max-width: 100%;
    width: 100%;
    animation: fadeInUp 0.8s ease-out;
    z-index: 2;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
    justify-content: space-between;
}

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

.permission-content h1 {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: clamp(1.8rem, 6vw, 2.4rem);
    font-weight: 600;
    color: #2c2416;
    margin-bottom: 12px;
    letter-spacing: -0.02em;
    line-height: 1.2;
}

.hedgey-portrait {
    width: clamp(120px, 35vw, 180px);
    height: clamp(120px, 35vw, 180px);
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.hedgey-portrait::before {
    content: '';
    position: absolute;
    width: calc(100% - 16px);
    height: calc(100% - 16px);
    border: 3px solid rgba(44, 36, 22, 0.15);
    border-radius: 50%;
}

.hedgey-portrait img {
    width: 85%;
    height: 85%;
    object-fit: contain;
    image-rendering: auto;
    filter: drop-shadow(0 6px 20px rgba(44, 36, 22, 0.2));
}

.permission-content .intro-text {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: clamp(1.15rem, 4.5vw, 1.5rem);
    color: #3d3222;
    margin-bottom: 8px;
    line-height: 1.35;
    font-style: italic;
    padding: 0 8px;
}

.permission-content .no-cloud-text {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: clamp(1.05rem, 4vw, 1.35rem);
    color: #5a4d3a;
    margin-bottom: 8px;
    line-height: 1.35;
    padding: 0 8px;
}

.permission-content .android-only {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: clamp(1rem, 3.5vw, 1.2rem);
    color: #8b7355;
    margin-bottom: 12px;
    line-height: 1.3;
}

.permission-content .setup-instructions {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: clamp(1.05rem, 4vw, 1.3rem);
    color: #3d3222;
    margin-bottom: 10px;
    line-height: 1.35;
}

.permission-content .setup-instructions a {
    color: #6b5344;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
    transition: color 0.2s ease;
}

.permission-content .setup-instructions a:hover {
    color: #2c2416;
}

.model-chooser-link {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: clamp(0.85rem, 3vw, 1rem);
    color: #5a4d3a;
    margin-bottom: 10px;
    line-height: 1.3;
}

.model-chooser-link a {
    color: #6b5344;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
    cursor: pointer;
    transition: color 0.2s ease;
}

.model-chooser-link a:hover {
    color: #2c2416;
}

.current-model-display {
    font-size: 0.85em;
    color: #8b7355;
    font-style: italic;
}

#current-model-name {
    font-weight: 600;
}

.model-note {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.5rem;
    color: #8b7355;
    margin: 4px 8px 4px;
    font-style: italic;
}

.code-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 12px;
    table-layout: fixed;
}

.code-table th {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 0.7rem;
    font-weight: 600;
    color: #3d3222;
    padding: 4px 4px 6px;
    text-align: center;
    vertical-align: bottom;
}

.code-table td {
    padding: 0 4px;
    vertical-align: top;
    width: 50%;
}

.code-block-container {
    position: relative;
    background: #fffdf5;
    border: 1px solid rgba(44, 36, 22, 0.2);
    border-radius: 6px;
    text-align: left;
    box-shadow: 
        inset 0 1px 3px rgba(44, 36, 22, 0.05),
        0 2px 8px rgba(44, 36, 22, 0.08);
}

.code-block-container.compact {
    margin-bottom: 0;
}

.copy-code-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    padding: 3px 8px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.6rem;
    font-weight: 600;
    color: #5a4d3a;
    background: #f4f1e8;
    border: 1px solid rgba(44, 36, 22, 0.2);
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
}

.copy-code-btn:hover {
    background: #eae6db;
    color: #2c2416;
}

.copy-code-btn:active {
    transform: scale(0.96);
}

.code-block {
    margin: 0;
    padding: 8px;
    padding-top: 28px;
    max-height: 120px;
    overflow: auto;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.5rem;
    line-height: 1.35;
    color: #3d3222;
    white-space: pre;
    -webkit-overflow-scrolling: touch;
}

.code-block-container.compact .code-block {
    max-height: 100px;
}

.code-block code {
    font-family: inherit;
}

#allow-camera-btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 12px 28px;
    font-size: 1rem;
    font-weight: 600;
    font-family: 'Crimson Pro', 'Georgia', serif;
    color: #fffdf5;
    background: #5a4d3a;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 
        0 2px 8px rgba(44, 36, 22, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition: all 0.3s ease;
    letter-spacing: 0.02em;
    margin-top: 8px;
}

.permission-note {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 0.65rem;
    color: #8b7355;
    margin-top: 6px;
    line-height: 1.3;
}

#allow-camera-btn:hover {
    background: #4a3f2e;
    transform: translateY(-2px);
    box-shadow: 
        0 4px 16px rgba(44, 36, 22, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

#allow-camera-btn:active {
    transform: translateY(0);
}

#allow-camera-btn svg {
    width: 20px;
    height: 20px;
    transition: transform 0.3s ease;
}

#allow-camera-btn:hover svg {
    transform: translateX(4px);
}

#error-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #2d1f3d 0%, #1a1a2e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.error-content {
    text-align: center;
    padding: 40px;
    max-width: 400px;
}

.error-icon {
    font-size: 80px;
    margin-bottom: 20px;
}

.error-content h2 {
    font-size: 1.8rem;
    color: #fff;
    margin-bottom: 15px;
}

.error-content p {
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 30px;
    line-height: 1.6;
}

.error-content button {
    padding: 15px 35px;
    font-size: 1.1rem;
    font-weight: 600;
    font-family: 'Nunito', sans-serif;
    color: white;
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.error-content button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(231, 76, 60, 0.4);
}

#app-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

#camera-feed {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 1;
}

#scene-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    pointer-events: none;
}

#scene-container canvas {
    display: block;
}

/* Bottom button container */
.bottom-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: flex-end;
    padding: 24px 20px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    z-index: 100;
    pointer-events: none;
}

.bottom-controls > * {
    pointer-events: auto;
}

#switch-camera-btn {
    position: fixed;
    right: 20px;
    bottom: max(70px, calc(env(safe-area-inset-bottom) + 50px));
    width: 52px;
    height: 52px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    transition: all 0.2s ease;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

#switch-camera-btn:hover {
    background: rgba(0, 0, 0, 0.75);
    transform: scale(1.05);
}

#switch-camera-btn:active {
    transform: scale(0.95);
}

#switch-camera-btn.switching {
    animation: spin 0.3s ease;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(180deg); }
}

#switch-camera-btn svg {
    width: 24px;
    height: 24px;
    color: white;
}

#mic-btn {
    position: fixed;
    bottom: max(66px, calc(env(safe-area-inset-bottom) + 46px));
    left: 50%;
    transform: translateX(-50%);
    width: 72px;
    height: 72px;
    background: rgba(78, 205, 196, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 3px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    transition: all 0.2s ease;
    box-shadow: 
        0 6px 24px rgba(78, 205, 196, 0.4),
        0 2px 8px rgba(0, 0, 0, 0.3);
}

#mic-btn:hover {
    background: rgba(78, 205, 196, 0.95);
    transform: translateX(-50%) scale(1.05);
}

#mic-btn:active {
    transform: translateX(-50%) scale(0.95);
}

#mic-btn.listening {
    background: rgba(255, 105, 180, 1);
    border-color: rgba(255, 255, 255, 0.6);
    animation: pulse-mic 1.2s ease-in-out infinite;
}

@keyframes pulse-mic {
    0%, 100% { 
        box-shadow: 
            0 6px 24px rgba(255, 105, 180, 0.5),
            0 2px 8px rgba(0, 0, 0, 0.3);
    }
    50% { 
        box-shadow: 
            0 6px 36px rgba(255, 105, 180, 0.8),
            0 0 20px rgba(255, 105, 180, 0.4),
            0 2px 8px rgba(0, 0, 0, 0.3);
    }
}

#mic-btn svg {
    width: 32px;
    height: 32px;
    color: white;
}

/* Off-grid label */
#offgrid-label {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 10px 20px;
    border-radius: 25px;
    color: #4ECDC4;
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid rgba(78, 205, 196, 0.4);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    z-index: 100;
    opacity: 0;
    transition: opacity 0.8s ease-in-out;
    pointer-events: none;
}

#offgrid-label.visible {
    opacity: 1;
}

#speech-display {
    position: fixed;
    bottom: 120px;
    left: 16px;
    right: 16px;
    text-align: center;
    z-index: 50;
    pointer-events: none;
}

#speech-display span {
    display: inline-block;
    max-width: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 10px 20px;
    border-radius: 20px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

#speech-display #speech-text {
    color: #4ECDC4;
    font-weight: 700;
}

#app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    text-align: center;
    padding: 8px 12px;
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    font-family: 'Crimson Pro', Georgia, serif;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    background: rgba(0, 0, 0, 0.6);
    border-top: none;
    z-index: 50;
    pointer-events: none;
}

#app-footer a {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: underline;
    pointer-events: auto;
}

@media (max-width: 480px) {
    .permission-content {
        padding: 16px 16px 24px;
    }
    
    .permission-content h1 {
        font-size: clamp(1.7rem, 7vw, 2.2rem);
        margin-bottom: 10px;
    }
    
    .permission-content .intro-text {
        font-size: clamp(1.1rem, 5vw, 1.4rem);
        line-height: 1.4;
        margin-bottom: 10px;
    }
    
    .permission-content .no-cloud-text {
        font-size: clamp(1rem, 4.5vw, 1.3rem);
        line-height: 1.35;
        margin-bottom: 10px;
    }
    
    .permission-content .android-only {
        font-size: clamp(0.95rem, 4vw, 1.15rem);
        line-height: 1.3;
        margin-bottom: 14px;
    }
    
    .permission-content .setup-instructions {
        font-size: clamp(1rem, 4.5vw, 1.25rem);
        line-height: 1.35;
    }
    
    .hedgey-portrait {
        width: clamp(100px, 32vw, 150px);
        height: clamp(100px, 32vw, 150px);
        margin-bottom: 14px;
    }
    
    .hedgey-portrait img {
        width: 85%;
        height: 85%;
    }
    
    .hedgey-portrait::before {
        width: calc(100% - 12px);
        height: calc(100% - 12px);
    }
    
    .code-block {
        font-size: 0.5rem;
        max-height: 90px;
        padding-top: 24px;
    }
    
    .code-block-container.compact .code-block {
        max-height: 85px;
    }
    
    .code-table th {
        font-size: 0.7rem;
    }
    
    #allow-camera-btn {
        padding: 12px 28px;
        font-size: 1rem;
    }
    
    .permission-note {
        font-size: 0.7rem;
    }
    
    #mic-btn {
        width: 68px;
        height: 68px;
        bottom: max(60px, calc(env(safe-area-inset-bottom) + 40px));
    }
    
    #mic-btn svg {
        width: 30px;
        height: 30px;
    }
    
    #switch-camera-btn {
        width: 48px;
        height: 48px;
        bottom: max(66px, calc(env(safe-area-inset-bottom) + 46px));
    }
    
    #exit-cleanly-btn {
        width: 48px;
        height: 48px;
        bottom: max(66px, calc(env(safe-area-inset-bottom) + 46px));
    }
    
    #switch-camera-btn svg {
        width: 22px;
        height: 22px;
    }
    
    #speech-display {
        bottom: 110px;
    }
}

@media (max-height: 600px) {
    .permission-content {
        padding: 10px 12px 18px;
    }
    
    .permission-content h1 {
        font-size: clamp(1.4rem, 5vw, 1.8rem);
        margin-bottom: 6px;
    }
    
    .hedgey-portrait {
        width: clamp(80px, 20vw, 100px);
        height: clamp(80px, 20vw, 100px);
        margin-bottom: 8px;
    }
    
    .hedgey-portrait img {
        width: 85%;
        height: 85%;
    }
    
    .hedgey-portrait::before {
        width: calc(100% - 10px);
        height: calc(100% - 10px);
    }
    
    .permission-content .intro-text,
    .permission-content .no-cloud-text,
    .permission-content .android-only {
        margin-bottom: 4px;
        font-size: clamp(0.95rem, 3.5vw, 1.1rem);
    }
    
    .code-block {
        max-height: 70px;
        padding: 6px;
        padding-top: 22px;
    }
    
    .code-block-container.compact .code-block {
        max-height: 65px;
    }
    
    .code-table {
        margin-bottom: 8px;
    }
}

@supports (-webkit-touch-callout: none) {
    body {
        -webkit-overflow-scrolling: touch;
    }
    
    #app-footer {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    #switch-camera-btn {
        top: max(20px, env(safe-area-inset-top));
    }
}

/* Exit Cleanly Button */
#exit-cleanly-btn {
    position: fixed;
    left: 20px;
    bottom: max(70px, calc(env(safe-area-inset-bottom) + 50px));
    width: 52px;
    height: 52px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 100;
    transition: all 0.2s ease;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

#exit-cleanly-btn:hover {
    background: rgba(139, 69, 69, 0.75);
    transform: scale(1.05);
}

#exit-cleanly-btn:active {
    transform: scale(0.95);
}

#exit-cleanly-btn svg {
    width: 24px;
    height: 24px;
    color: white;
}

/* Exit Cleanly Modal */
#exit-cleanly-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.exit-modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
}

.exit-modal-content {
    position: relative;
    background: #f4f1e8;
    border-radius: 16px;
    padding: 24px;
    max-width: 320px;
    width: 90%;
    text-align: center;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.exit-modal-content h3 {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 1.4rem;
    font-weight: 600;
    color: #2c2416;
    margin-bottom: 12px;
}

.exit-modal-content p {
    font-family: 'Nunito', sans-serif;
    font-size: 0.9rem;
    color: #5a4d3a;
    margin-bottom: 16px;
}

.exit-code-block {
    background: #2c2416;
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
}

.exit-code-block code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.95rem;
    color: #4ecdc4;
}

.exit-copy-btn {
    display: block;
    width: 100%;
    padding: 12px 20px;
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 1rem;
    font-weight: 600;
    color: #fffdf5;
    background: #5a4d3a;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 10px;
    transition: all 0.2s ease;
}

.exit-copy-btn:hover {
    background: #4a3f2e;
}

.exit-close-btn {
    display: block;
    width: 100%;
    padding: 10px 20px;
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 0.95rem;
    color: #5a4d3a;
    background: transparent;
    border: 1px solid rgba(44, 36, 22, 0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.exit-close-btn:hover {
    background: rgba(44, 36, 22, 0.05);
}

/* Model Chooser Bottom Sheet Overlay */
.model-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

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

.model-overlay-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.model-bottom-sheet {
    position: relative;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    background: #f4f1e8;
    border-radius: 20px 20px 0 0;
    padding: 20px 16px 24px;
    box-shadow: 0 -4px 30px rgba(44, 36, 22, 0.3);
    overflow-y: auto;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.model-sheet-header {
    text-align: center;
    margin-bottom: 16px;
}

.model-sheet-header h3 {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 1.5rem;
    font-weight: 600;
    color: #2c2416;
    margin: 0 0 4px;
}

.model-sheet-subtitle {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 0.95rem;
    color: #5a4d3a;
    font-style: italic;
    margin: 0;
}

.model-tier-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.model-tier-card {
    background: #fffdf5;
    border: 2px solid rgba(44, 36, 22, 0.15);
    border-radius: 10px;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.model-tier-card:hover {
    border-color: rgba(44, 36, 22, 0.35);
    background: #fff;
}

.model-tier-card.selected {
    border-color: #5a4d3a;
    background: #fffdf5;
    box-shadow: 0 2px 8px rgba(44, 36, 22, 0.15);
}

.model-tier-card.selected::before {
    content: '✓';
    font-size: 1rem;
    color: #5a4d3a;
    font-weight: bold;
    margin-right: 4px;
}

.model-tier-name {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 1.1rem;
    font-weight: 600;
    color: #2c2416;
}

.model-tier-desc {
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 0.9rem;
    color: #5a4d3a;
    font-style: italic;
}

.model-tier-model {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.7rem;
    color: #8b7355;
    background: rgba(44, 36, 22, 0.08);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: auto;
}

.model-sheet-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.model-btn-primary {
    padding: 14px 24px;
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 1.05rem;
    font-weight: 600;
    color: #fffdf5;
    background: #5a4d3a;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.model-btn-primary:hover {
    background: #4a3f2e;
}

.model-btn-secondary {
    padding: 12px 24px;
    font-family: 'Crimson Pro', 'Georgia', serif;
    font-size: 1rem;
    color: #5a4d3a;
    background: transparent;
    border: 1px solid rgba(44, 36, 22, 0.3);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.model-btn-secondary:hover {
    background: rgba(44, 36, 22, 0.05);
}

/* Debug HUD styles - ensure text is selectable */
#debug-hud pre {
    -webkit-user-select: text !important;
    user-select: text !important;
}