* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

html.teleprompter-page-active,
body.teleprompter-page-active {
    overflow: hidden;
    overscroll-behavior: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.navbar {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 900;
}

.navbar-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 56px;
    height: auto;
    padding-top: env(safe-area-inset-top);
}

.navbar-logo {
    font-size: clamp(18px, 4vw, 24px);
    font-weight: bold;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-decoration: none;
}

.navbar-menu {
    display: flex;
    gap: 24px;
    list-style: none;
    flex-wrap: wrap;
    align-items: center;
}

.navbar-menu > li {
    position: relative;
}

.navbar-menu a {
    text-decoration: none;
    color: #333;
    font-weight: 500;
    transition: color 0.3s;
    font-size: 14px;
}

.navbar-menu a:hover {
    color: #667eea;
}

.navbar-toggle {
    display: none;
    flex-direction: column;
    cursor: pointer;
    gap: 5px;
    padding: 12px;
    margin: -12px;
    touch-action: manipulation;
}

.navbar-toggle span {
    width: 25px;
    height: 3px;
    background: #333;
    border-radius: 3px;
    transition: 0.3s;
}

.main-content {
    flex: 1;
    padding: clamp(16px, 4vw, 40px) max(16px, env(safe-area-inset-right)) clamp(24px, 5vw, 40px) max(16px, env(safe-area-inset-left));
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

.header {
    text-align: center;
    margin-bottom: clamp(20px, 5vw, 40px);
    color: white;
}

.header h1 {
    font-size: clamp(26px, 6vw, 42px);
    margin-bottom: 12px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    line-height: 1.2;
}

.header p {
    font-size: clamp(14px, 3.5vw, 18px);
    opacity: 0.9;
    line-height: 1.5;
}

.settings-panel {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 16px;
    padding: clamp(20px, 4vw, 35px);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    margin-bottom: 24px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
    gap: clamp(16px, 3vw, 25px);
    margin-bottom: 20px;
}

.setting-item {
    display: flex;
    flex-direction: column;
}

.setting-item label {
    font-size: 13px;
    color: #666;
    margin-bottom: 8px;
    font-weight: 600;
}

.setting-item input,
.setting-item select,
.setting-item textarea {
    padding: 12px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 16px;
    transition: all 0.3s;
    font-family: inherit;
    min-height: 44px;
    touch-action: manipulation;
}

.setting-item textarea {
    min-height: 160px;
    resize: vertical;
}

.setting-item input:focus,
.setting-item select:focus,
.setting-item textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.text-editor {
    grid-column: 1 / -1;
}

.text-editor textarea {
    width: 100%;
    min-height: clamp(140px, 35vh, 220px);
}

.text-editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin-top: 12px;
}

.text-editor-toolbar .btn-outline {
    background: #fff;
    border: 2px solid #667eea;
    color: #667eea;
    box-shadow: none;
    min-width: auto;
    padding: 10px 18px;
    font-size: 15px;
}

.text-editor-toolbar .btn-outline:hover {
    background: rgba(102, 126, 234, 0.08);
    transform: translateY(-1px);
}

.toolbar-inline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.toolbar-label {
    font-size: 13px;
    color: #666;
    font-weight: 600;
    margin: 0;
}

.wrap-max-input {
    width: 4.2rem;
    min-height: 40px;
    padding: 8px 10px;
    text-align: center;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 16px;
}

.toolbar-unit {
    font-size: 14px;
    color: #666;
}

.toolbar-hint {
    flex: 1 1 200px;
    font-size: 12px;
    color: #999;
    line-height: 1.45;
}

@media (max-width: 768px) {
    .text-editor-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .text-editor-toolbar .btn-outline {
        width: 100%;
    }

    .toolbar-inline {
        justify-content: flex-start;
    }
}

.mode-selector {
    grid-column: 1 / -1;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.mode-btn {
    flex: 1;
    min-width: min(100%, 150px);
    padding: 14px 16px;
    border: 2px solid #e0e0e0;
    background: white;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 15px;
    font-weight: 600;
    touch-action: manipulation;
}

.mode-btn.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-color: transparent;
    transform: translateY(-1px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.mode-btn:hover {
    border-color: #667eea;
}

.control-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 24px;
}

.btn {
    padding: 14px 28px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    min-width: min(100%, 160px);
    min-height: 48px;
    touch-action: manipulation;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(245, 87, 108, 0.4);
}

.btn-danger {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    color: white;
    box-shadow: 0 4px 15px rgba(250, 112, 154, 0.4);
}

.teleprompter-screen {
    display: none;
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100vw;
    height: 100%;
    height: 100dvh;
    max-height: 100dvh;
    z-index: 10000;
    overflow: hidden;
    cursor: default;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.teleprompter-screen.active {
    display: block;
}

.teleprompter-screen.teleprompter-screen--manual {
    cursor: pointer;
}

.teleprompter-exit-bar {
    position: fixed;
    top: max(10px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    right: auto;
    z-index: 10003;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    max-width: calc(100% - 24px - env(safe-area-inset-left) - env(safe-area-inset-right));
    pointer-events: auto;
}

.btn-exit-fullscreen {
    margin: 0;
    padding: 12px 18px;
    min-height: 48px;
    border: none;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    touch-action: manipulation;
    line-height: 1.2;
}

.btn-exit-fullscreen:active {
    transform: scale(0.98);
}

.teleprompter-exit-caption {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
    line-height: 1.35;
}

.teleprompter-content {
    padding: clamp(16px, 4vw, 36px) clamp(12px, 4vw, 28px);
    height: 100%;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.teleprompter-text {
    transition: transform 0.45s ease-out;
    width: 100%;
    will-change: transform;
}

@media (prefers-reduced-motion: reduce) {
    .teleprompter-text {
        transition: transform 0.2s ease-out;
    }
}

.text-line {
    display: block;
    opacity: 0.6;
    transition: opacity 0.3s;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    word-break: break-word;
    margin-bottom: clamp(12px, 3vw, 20px);
    hyphens: auto;
}

.text-line.current {
    opacity: 1;
    font-weight: bold;
}

.text-line.read {
    opacity: 0.3;
}

.status-indicator {
    position: fixed;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    left: auto;
    max-width: calc(100% - 24px - env(safe-area-inset-left) - env(safe-area-inset-right));
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.78);
    color: white;
    border-radius: 20px;
    font-size: clamp(11px, 2.8vw, 14px);
    z-index: 10001;
    display: none;
    backdrop-filter: blur(10px);
    line-height: 1.35;
}

.status-indicator.active {
    display: block;
}

.voice-indicator {
    width: 8px;
    height: 8px;
    background: #4CAF50;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
    vertical-align: middle;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(0.85); }
}

.speed-control,
.sensitivity-control {
    display: flex;
    align-items: center;
    gap: 12px;
}

.speed-value,
.sensitivity-value {
    min-width: 52px;
    text-align: center;
    font-weight: 700;
    color: #667eea;
    font-size: 15px;
}

input[type="range"] {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    background: linear-gradient(to right, #667eea 0%, #764ba2 100%);
    touch-action: manipulation;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

input[type="color"] {
    width: 70px;
    min-height: 44px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    cursor: pointer;
}

.sensitivity-item {
    grid-column: 1 / -1;
}

.hint-small {
    color: #999;
    margin-top: 8px;
    font-size: 12px;
    line-height: 1.45;
}

.checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 14px;
    color: #444;
    font-weight: 600;
    cursor: pointer;
    line-height: 1.45;
}

.checkbox-row input {
    margin-top: 4px;
    min-width: 18px;
    min-height: 18px;
    flex-shrink: 0;
    touch-action: manipulation;
}

#voiceExtraOptions {
    display: none;
}

#voiceExtraOptions.visible {
    display: flex;
    flex-direction: column;
}

.footer {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    padding: 24px max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    text-align: center;
    color: #666;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
}

.footer p {
    margin: 5px 0;
    font-size: 13px;
}

.footer a {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
}

.error-message {
    background: linear-gradient(135deg, #ffebee 0%, #ffcdd2 100%);
    color: #c62828;
    padding: 14px 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    display: none;
    border-left: 4px solid #c62828;
    box-shadow: 0 4px 12px rgba(198, 40, 40, 0.2);
    font-size: 14px;
    line-height: 1.5;
}

.error-message.active {
    display: block;
}

.info-message {
    background: linear-gradient(135deg, #e8f5e9 0%, #c8e6c9 100%);
    color: #2e7d32;
    padding: 14px 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    display: none;
    border-left: 4px solid #2e7d32;
    box-shadow: 0 4px 12px rgba(46, 125, 50, 0.15);
    font-size: 14px;
    line-height: 1.5;
}

.info-message.active {
    display: block;
}

.compat-banner {
    background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
    color: #1565c0;
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 16px;
    font-size: 13px;
    line-height: 1.5;
    border-left: 4px solid #1565c0;
    display: none;
}

.compat-banner.active {
    display: block;
}

.debug-panel {
    position: fixed;
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
    right: auto;
    background: rgba(0, 0, 0, 0.9);
    color: #fff;
    padding: 14px;
    border-radius: 10px;
    font-size: 11px;
    max-width: min(96vw, 420px);
    z-index: 10002;
    display: none;
    backdrop-filter: blur(10px);
}

.debug-panel.active {
    display: block;
}

.debug-panel .debug-line {
    margin: 6px 0;
    font-family: ui-monospace, 'Courier New', monospace;
    word-break: break-all;
}

@media (max-width: 768px) {
    .navbar-menu {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: rgba(255, 255, 255, 0.98);
        flex-direction: column;
        padding: 16px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        gap: 12px;
    }

    .navbar-menu.active {
        display: flex;
    }

    .navbar-toggle {
        display: flex;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    .teleprompter-content {
        padding: 12px 10px;
    }

    .mode-btn {
        min-width: 100%;
    }
}

@media (orientation: portrait) {
    .header {
        margin-bottom: 20px;
    }

    .settings-panel {
        border-radius: 14px;
    }

    .text-line {
        margin-bottom: clamp(14px, 4vw, 22px);
    }
}
