/* ============================================
   TELEPROMPTER PRO - Design System
   ============================================ */

/* ---- CSS Variables ---- */
:root {
    --tp-font-size: 36px;
    --tp-text-width: 85%;
    --tp-line-height: 1.7;

    /* Colors */
    --color-bg-editor: #0a0a0f;
    --color-bg-teleprompter: #000000;
    --color-surface: #141419;
    --color-surface-raised: #1c1c24;
    --color-border: rgba(255, 255, 255, 0.08);
    --color-border-focus: #00bfff;

    --color-text-primary: #e8e8ee;
    --color-text-secondary: #888894;
    --color-text-muted: #55555e;

    --color-accent: #00bfff;
    --color-accent-glow: rgba(0, 191, 255, 0.25);
    --color-success: #00e676;
    --color-warning: #ffab40;
    --color-error: #ff5252;

    /* Teleprompter text colors */
    --color-word-upcoming: #6b6b78;
    --color-word-spoken: #ffffff;
    --color-word-current: #ffffff;

    /* Spacing */
    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
    --transition-slow: 0.5s ease;
}

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

html, body {
    height: 100%;
    height: 100dvh;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--color-bg-editor);
    color: var(--color-text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
}

/* ---- View Management ---- */
.view {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
    z-index: 1;
}

.view.active {
    opacity: 1;
    visibility: visible;
    z-index: 10;
}

/* ---- Buttons Base ---- */
button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* ==================================================
   EDITOR VIEW
   ================================================== */
#editor-view {
    background: var(--color-bg-editor);
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--color-accent), #0066ff);
    border-radius: var(--radius-md);
    color: white;
}

#app-title {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #ffffff, #aaaacc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#btn-settings {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
}

#btn-settings:active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-primary);
}

/* Editor Main */
#editor-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 20px 20px;
    gap: 16px;
    min-height: 0;
}

#script-input {
    flex: 1;
    width: 100%;
    background: var(--color-surface);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    font-family: 'Inter', sans-serif;
    font-size: 16px;
    line-height: 1.7;
    resize: none;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    min-height: 0;
}

#script-input::placeholder {
    color: var(--color-text-muted);
}

#script-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-glow);
}

/* Editor Actions */
#editor-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#word-count {
    font-size: 13px;
    color: var(--color-text-muted);
    font-weight: 500;
}

#btn-start {
    display: flex;
    align-items: center;
    gap: 10px;
    background: linear-gradient(135deg, #00bfff, #0066ff);
    color: white;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.04em;
    border-radius: var(--radius-md);
    padding: 14px 36px;
    transition: all var(--transition-normal);
    box-shadow: 0 4px 20px rgba(0, 120, 255, 0.3);
}

#btn-start:active {
    transform: scale(0.96);
    box-shadow: 0 2px 12px rgba(0, 120, 255, 0.4);
}

/* ==================================================
   TELEPROMPTER VIEW
   ================================================== */
#teleprompter-view {
    background: var(--color-bg-teleprompter);
    overflow: hidden;
}

/* Mirror Mode */
#teleprompter-view.mirror-mode #tp-content-wrapper {
    transform: scaleX(-1);
}

/* Status Bar */
#tp-status-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    padding-top: calc(env(safe-area-inset-top, 12px) + 8px);
    background: linear-gradient(180deg, rgba(0,0,0,0.8) 0%, transparent 100%);
    z-index: 20;
    pointer-events: none;
}

#tp-status-bar > * {
    pointer-events: auto;
}

#btn-exit {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

#btn-exit:active {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Mic Indicator */
#mic-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
}

#mic-dot {
    display: block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-text-muted);
    transition: background var(--transition-normal);
}

#mic-dot.active {
    background: var(--color-success);
    animation: pulse-mic 1.5s ease-in-out infinite;
}

@keyframes pulse-mic {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(0, 230, 118, 0.5);
    }
    50% {
        box-shadow: 0 0 0 7px rgba(0, 230, 118, 0);
    }
}

#mic-label {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
}

#tp-progress {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.5);
    margin-left: auto;
}

#tp-status-text {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    transition: color var(--transition-normal);
}

#tp-status-text.status-off-script {
    color: var(--color-warning);
}

#tp-status-text.status-paused {
    color: var(--color-accent);
}

#tp-status-text.status-complete {
    color: var(--color-success);
}

/* Guide Line */
#tp-guide-line {
    position: fixed;
    top: 33%;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        rgba(0, 191, 255, 0.12) 20%,
        rgba(0, 191, 255, 0.2) 50%,
        rgba(0, 191, 255, 0.12) 80%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 15;
    opacity: 0;
    transition: opacity var(--transition-slow);
}

#teleprompter-view.active #tp-guide-line {
    opacity: 1;
}

/* Content Wrapper */
#tp-content-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    scroll-behavior: auto;
    touch-action: manipulation;
    /* Hide scrollbar */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

#tp-content-wrapper::-webkit-scrollbar {
    display: none;
}

/* Content */
#tp-content {
    padding-top: 35dvh;
    padding-bottom: 70dvh;
    padding-left: 20px;
    padding-right: 20px;
}

.tp-words-container {
    max-width: var(--tp-text-width);
    margin: 0 auto;
    text-align: left;
}

/* Word Styling */
.word {
    display: inline;
    font-size: var(--tp-font-size);
    font-weight: 700;
    line-height: var(--tp-line-height);
    letter-spacing: -0.01em;
    transition: color 0.4s ease, text-shadow 0.4s ease, opacity 0.4s ease;
    cursor: default;
    -webkit-user-select: none;
    user-select: none;
}

.word.upcoming {
    color: var(--color-word-upcoming);
}

.word.spoken {
    color: var(--color-word-spoken);
}

.word.current {
    color: var(--color-word-current);
    text-shadow: 0 0 30px rgba(255, 255, 255, 0.25);
}

/* Paragraph breaks inside teleprompter */
.para-break {
    display: block;
    height: calc(var(--tp-font-size) * 0.8);
}

/* Pause Overlay */
#tp-pause-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 50;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#tp-pause-overlay.active {
    opacity: 1;
    visibility: visible;
}

.pause-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.pause-label {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: 0.12em;
    color: rgba(255, 255, 255, 0.85);
}

.pause-hint {
    font-size: 14px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.4);
}

/* Off-script visual indicator */
#teleprompter-view.off-script::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 2px solid rgba(255, 171, 64, 0.3);
    pointer-events: none;
    z-index: 12;
    animation: pulse-border 2s ease-in-out infinite;
}

@keyframes pulse-border {
    0%, 100% { border-color: rgba(255, 171, 64, 0.15); }
    50% { border-color: rgba(255, 171, 64, 0.4); }
}

/* ==================================================
   SETTINGS PANEL
   ================================================== */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    justify-content: center;
    align-items: flex-end;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

#settings-panel {
    width: 100%;
    max-width: 500px;
    max-height: 85dvh;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-bottom: none;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform var(--transition-normal);
}

.overlay.active #settings-panel {
    transform: translateY(0);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 24px 0;
    position: sticky;
    top: 0;
    background: var(--color-surface);
    z-index: 1;
}

.settings-header h2 {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.01em;
}

#btn-close-settings {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    color: var(--color-text-secondary);
    transition: all var(--transition-fast);
}

#btn-close-settings:active {
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-primary);
}

.settings-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding-bottom: calc(env(safe-area-inset-bottom, 20px) + 24px);
}

/* Setting Group */
.setting-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.setting-label-row label {
    font-size: 15px;
    font-weight: 600;
    color: var(--color-text-primary);
}

.setting-value {
    font-size: 14px;
    font-weight: 700;
    color: var(--color-accent);
    min-width: 50px;
    text-align: right;
}

.setting-hint {
    font-size: 12px;
    color: var(--color-text-muted);
    line-height: 1.4;
}

/* Range Slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--color-surface-raised);
    border-radius: 6px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    background: var(--color-accent);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 191, 255, 0.3);
    transition: box-shadow var(--transition-fast);
}

input[type="range"]:active::-webkit-slider-thumb {
    box-shadow: 0 2px 16px rgba(0, 191, 255, 0.5);
    transform: scale(1.1);
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 30px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider-toggle {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-surface-raised);
    border-radius: 30px;
    transition: background var(--transition-normal);
}

.slider-toggle::before {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    left: 3px;
    bottom: 3px;
    background: #ffffff;
    border-radius: 50%;
    transition: transform var(--transition-normal);
}

.switch input:checked + .slider-toggle {
    background: var(--color-accent);
}

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

/* Settings Preview */
#settings-preview {
    background: #000000;
    border-radius: var(--radius-md);
    padding: 20px;
    font-size: var(--tp-font-size);
    font-weight: 700;
    line-height: var(--tp-line-height);
    overflow: hidden;
}

#settings-preview .preview-spoken {
    color: var(--color-word-spoken);
}

#settings-preview .preview-current {
    color: var(--color-word-current);
    text-shadow: 0 0 30px rgba(255, 255, 255, 0.25);
}

#settings-preview .preview-upcoming {
    color: var(--color-word-upcoming);
}

/* ==================================================
   TOAST
   ================================================== */
#toast {
    position: fixed;
    bottom: 40px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--color-surface-raised);
    color: var(--color-text-primary);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 14px 24px;
    font-size: 14px;
    font-weight: 600;
    z-index: 200;
    opacity: 0;
    transition: all var(--transition-normal);
    pointer-events: none;
    white-space: nowrap;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ==================================================
   UTILITY & RESPONSIVE
   ================================================== */

/* Landscape adjustments */
@media (orientation: landscape) {
    #tp-content {
        padding-top: 30dvh;
        padding-bottom: 60dvh;
    }

    #tp-guide-line {
        top: 28%;
    }
}

/* Larger screens */
@media (min-width: 768px) {
    #editor-main {
        max-width: 700px;
        margin: 0 auto;
    }

    .overlay {
        align-items: center;
    }

    #settings-panel {
        border-radius: var(--radius-xl);
        border-bottom: 1px solid var(--color-border);
        max-height: 80dvh;
    }

    #btn-start:hover {
        transform: scale(1.03);
        box-shadow: 0 6px 28px rgba(0, 120, 255, 0.4);
    }
}

/* Selection */
::selection {
    background: var(--color-accent);
    color: white;
}

/* Scrollbar for editor */
#script-input::-webkit-scrollbar {
    width: 4px;
}

#script-input::-webkit-scrollbar-track {
    background: transparent;
}

#script-input::-webkit-scrollbar-thumb {
    background: var(--color-text-muted);
    border-radius: 4px;
}
