/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --text-primary: #1a1a1a;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --accent-color: #3b82f6;
    --accent-hover: #2563eb;
    --anchor-color: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius: 8px;
    --transition: all 0.2s ease;
    --header-height: 80px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
        sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background: var(--bg-secondary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

.app-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* ==================== Header ==================== */
.app-header {
    height: var(--header-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
    gap: 2rem;
    flex-shrink: 0;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    white-space: nowrap;
}

.input-bar {
    flex: 1;
    display: flex;
    gap: 0.5rem;
    max-width: 600px;
}

.input-bar .input-field {
    flex: 1;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
}

.input-bar .btn {
    width: auto;
    margin: 0;
    padding: 0.75rem 1.25rem;
    white-space: nowrap;
}

/* ==================== Modal ==================== */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: var(--bg-primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

/* ==================== Three-Panel Layout ==================== */
.panel-container {
    flex: 1;
    display: grid;
    grid-template-columns: 280px 6px 1fr 6px 420px;
    gap: 0;
    padding: 1rem;
    overflow: hidden;
    min-height: 0;
}

/* ==================== Resize Handles ==================== */
.resize-handle {
    width: 6px;
    background: transparent;
    cursor: col-resize;
    position: relative;
    z-index: 10;
    transition: background 0.2s ease;
}

.resize-handle:hover,
.resize-handle.dragging {
    background: var(--accent-color);
}

.resize-handle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 40px;
    background: var(--border-color);
    border-radius: 2px;
    transition: background 0.2s ease;
}

.resize-handle:hover::before,
.resize-handle.dragging::before {
    background: white;
}

.panel {
    background: var(--bg-primary);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
    margin: 0 0.5rem;
}

.panel:first-of-type {
    margin-left: 0;
}

.panel:last-of-type {
    margin-right: 0;
}

.panel-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.panel-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    min-height: 0;
}

/* History Panel (Left) */
.panel-left {
    min-width: 0;
}

.panel-left .panel-content {
    padding: 0.5rem;
}

/* Article Panel (Middle) */
.article-content {
    font-size: 1.1rem;
    line-height: 1.8;
    color: var(--text-primary);
    padding: 1.5rem;
}

.article-content p {
    margin-bottom: 1.5rem;
}

.article-content .empty-state {
    color: var(--text-secondary);
    text-align: center;
    padding: 3rem 1rem;
}

/* RSVP Panel (Right) */
.panel-right {
    min-width: 0;
}

.rsvp-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
}

/* Fullscreen Button */
.fullscreen-btn {
    background: none;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    padding: 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.fullscreen-btn:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

/* ==================== Form Elements ==================== */
.input-field {
    width: 100%;
    padding: 1rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition);
    font-family: inherit;
}

.input-field:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

textarea.input-field {
    resize: vertical;
    min-height: 200px;
}

/* ==================== Buttons ==================== */
.btn {
    padding: 1rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
    margin-top: 1rem;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    width: auto;
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* ==================== Settings Bar ==================== */
.settings-bar {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.settings-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
    min-width: 150px;
}

.settings-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.wpm-slider {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
    outline: none;
    -webkit-appearance: none;
}

.wpm-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    transition: var(--transition);
}

.wpm-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.wpm-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent-color);
    cursor: pointer;
    border: none;
}

/* ==================== RSVP Display ==================== */
.rsvp-container {
    background: var(--bg-secondary);
    border-radius: var(--radius);
    padding: 2rem 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 280px;
}

.rsvp-display {
    text-align: center;
    position: relative;
}

.focus-line {
    height: 2px;
    background: var(--border-color);
    margin: 0.5rem auto;
    max-width: 100%;
    position: relative;
}

.focus-line::after {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 3px;
    height: 50px;
    background: var(--anchor-color);
    opacity: 0.3;
}

.word-display {
    padding: 2rem 1rem;
    min-height: 120px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.word-wrapper {
    position: relative;
    width: 100%;
    height: 4rem;
}

.word-text {
    font-size: 3rem;
    font-weight: 700;
    line-height: 1;
    color: var(--text-primary);
    letter-spacing: 0;
    white-space: nowrap;
    font-family: monospace;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

.before-anchor {
    display: inline;
}

.anchor-letter {
    color: var(--anchor-color);
    display: inline;
}

.after-anchor {
    display: inline;
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    margin-top: 1rem;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent-color);
    width: 0%;
    transition: width 0.1s linear;
}

/* ==================== Controls ==================== */
.controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
}

.control-btn {
    background: var(--bg-primary);
    border: 2px solid var(--border-color);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-primary);
}

.control-btn:hover {
    background: var(--bg-secondary);
    border-color: var(--accent-color);
    color: var(--accent-color);
    transform: scale(1.05);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn-large {
    width: 64px;
    height: 64px;
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}

.control-btn-large:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: white;
}

/* ==================== Stats ==================== */
.stats {
    display: flex;
    justify-content: center;
    gap: 2rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: var(--bg-secondary);
    padding: 0.75rem;
    border-radius: var(--radius);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.stat-item span {
    font-weight: 600;
    color: var(--text-primary);
}

/* ==================== Fullscreen Mode ==================== */
.panel-right:fullscreen,
.panel-right.fullscreen-fallback {
    width: 100vw;
    height: 100vh;
    max-width: none;
    border-radius: 0;
    display: flex;
    flex-direction: column;
}

.panel-right:fullscreen .panel-content,
.panel-right.fullscreen-fallback .panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.panel-right:fullscreen .rsvp-container,
.panel-right.fullscreen-fallback .rsvp-container {
    flex: 1;
    min-height: auto;
}

.panel-right:fullscreen .word-text,
.panel-right.fullscreen-fallback .word-text {
    font-size: 5rem;
}

.fullscreen-fallback {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
}

/* ==================== Responsive: Tablet (1024px) ==================== */
@media (max-width: 1024px) {
    .panel-container {
        grid-template-columns: 220px 6px 1fr 6px 360px;
    }

    .word-text {
        font-size: 2.5rem;
    }
}

/* ==================== Responsive: Mobile (768px) ==================== */
@media (max-width: 768px) {
    .app-header {
        flex-direction: column;
        height: auto;
        padding: 1rem;
        gap: 1rem;
    }

    .input-bar {
        width: 100%;
        max-width: none;
        flex-wrap: wrap;
    }

    .input-bar .input-field {
        flex: 1 1 100%;
    }

    .input-bar .btn {
        flex: 1;
    }

    /* Horizontal scroll for panels */
    .panel-container {
        display: flex;
        overflow-x: auto;
        scroll-snap-type: x mandatory;
        -webkit-overflow-scrolling: touch;
        gap: 1rem;
        padding: 1rem;
    }

    .panel {
        flex: 0 0 calc(100vw - 2rem);
        scroll-snap-align: start;
        min-width: calc(100vw - 2rem);
        margin: 0;
        width: auto !important;
        min-width: calc(100vw - 2rem) !important;
        max-width: none !important;
    }

    /* Hide resize handles on mobile */
    .resize-handle {
        display: none;
    }

    .word-text {
        font-size: 2.5rem;
    }

    .word-wrapper {
        height: 3rem;
    }

    .stats {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ==================== Animations ==================== */
.fade-in {
    animation: fadeIn 0.3s ease;
}

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

.word-transition {
    animation: wordFade 0.15s ease;
}

@keyframes wordFade {
    0% {
        opacity: 0.5;
    }
    100% {
        opacity: 1;
    }
}
