:root {
    --bg: #070910;
    --bg-elevated: #0d1117;
    --amber: #c9a227;
    --amber-glow: rgba(201, 162, 39, 0.15);
    --amber-hover: rgba(201, 162, 39, 0.25);
    --text: #f5f5f5;
    --text-muted: rgba(245, 245, 245, 0.6);
    --border: rgba(255, 255, 255, 0.08);
    --success: #4ade80;
    --error: #ef4444;

    --glass-bg: rgba(13, 17, 23, 0.85);
    --glass-blur: blur(16px);

    --font-family: 'Space Grotesk', system-ui, -apple-system, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.5rem;
    --font-size-xl: 3rem;
    --font-size-2xl: 4.5rem;
    --font-size-3xl: 6rem;
    --font-size-4xl: 8rem;

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;

    --transition-fast: 100ms ease-out;
    --transition-base: 200ms ease-out;
    --transition-slow: 300ms ease-out;
}

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

html, body {
    height: 100%;
    font-family: var(--font-family);
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
}

body {
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse at 50% 0%, rgba(201, 162, 39, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 100% 100%, rgba(201, 162, 39, 0.02) 0%, transparent 40%);
    pointer-events: none;
    z-index: 0;
}

#app {
    position: relative;
    z-index: 1;
    height: 100%;
    width: 100%;
}

.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.amber-glow {
    box-shadow: 0 0 20px var(--amber-glow), 0 0 40px rgba(201, 162, 39, 0.08);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    cursor: pointer;
    transition: all var(--transition-fast);
    user-select: none;
}

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

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

.btn-primary {
    background: var(--amber);
    color: var(--bg);
    border-color: var(--amber);
}

.btn-primary:hover {
    background: #d4b32e;
    border-color: #d4b32e;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    background: var(--amber);
    border-radius: 50%;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: var(--amber);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.progress-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar.clickable {
    cursor: pointer;
    height: 8px;
    transition: height 0.2s ease;
}

.progress-bar.clickable:hover {
    height: 12px;
}

.progress-bar-fill {
    height: 100%;
    background: var(--amber);
    transition: width 100ms linear;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 20px var(--amber-glow); }
    50% { box-shadow: 0 0 30px var(--amber-hover), 0 0 60px var(--amber-glow); }
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes scale-in {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.animate-fade-in {
    animation: fade-in var(--transition-base) ease-out;
}

.animate-slide-up {
    animation: slide-up var(--transition-slow) ease-out;
}

.animate-scale-in {
    animation: scale-in var(--transition-base) ease-out;
}

@media (max-width: 768px) {
    :root {
        --font-size-3xl: 3rem;
        --font-size-2xl: 2.5rem;
        --font-size-xl: 2rem;
    }
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* ==================== READER ==================== */
.reader-container {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    cursor: pointer;
}

.reader-word-display {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    width: 100%;
}

.word-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    font-weight: 500;
    letter-spacing: -0.02em;
}

.word-size-s { font-size: var(--font-size-xl); }
.word-size-m { font-size: var(--font-size-2xl); }
.word-size-l { font-size: var(--font-size-3xl); }
.word-size-xl { font-size: var(--font-size-4xl); }

.word-before, .word-after {
    color: var(--text);
}

.word-orp {
    color: var(--amber);
    position: relative;
}

.orp-line {
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 20px;
    background: var(--amber);
    box-shadow: 0 0 10px var(--amber-glow);
}

.reader-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1.5rem 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.controls-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.controls-header .spacer {
    flex: 1;
}

.controls-main {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
}

.controls-wpm {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.play-btn {
    padding: 1rem 2rem;
    font-size: var(--font-size-base);
    min-width: 120px;
}

.wpm-display {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--amber);
    min-width: 120px;
    text-align: center;
}

.progress-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.font-size-controls, .word-group-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.font-size-controls .btn, .word-group-controls .btn {
    padding: 0.5rem 1rem;
    min-width: 40px;
}

.keyboard-hints {
    display: flex;
    justify-content: center;
    gap: 2rem;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    padding-top: 0.5rem;
}

/* ==================== LIBRARY ==================== */
.library-container {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    overflow: hidden;
}

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

.library-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    letter-spacing: 0.1em;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.search-input {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    outline: none;
    transition: border-color var(--transition-fast);
}

.search-input:focus {
    border-color: var(--amber);
}

.search-input::placeholder {
    color: var(--text-muted);
}

.document-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1.5rem;
    overflow-y: auto;
    padding: 0.5rem;
}

.document-card {
    display: flex;
    flex-direction: column;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    text-decoration: none;
    color: inherit;
    transition: all var(--transition-base);
}

.document-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 30px rgba(201, 162, 39, 0.1);
}

.document-card.in-progress {
    border-left: 3px solid var(--amber);
}

.document-card.completed {
    opacity: 0.7;
}

.card-progress-bar {
    height: 3px;
    background: var(--border);
}

.card-progress-fill {
    height: 100%;
    background: var(--amber);
}

.card-content {
    padding: 1.5rem;
    flex: 1;
    position: relative;
}

.card-badge {
    position: absolute;
    top: 1rem;
    right: 1rem;
    font-size: var(--font-size-xs);
    color: var(--success);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.card-title {
    font-size: var(--font-size-base);
    font-weight: 600;
    margin-bottom: 0.25rem;
    line-height: 1.3;
}

.card-author {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.card-footer {
    display: flex;
    justify-content: space-between;
    padding: 0 1.5rem;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
}

.card-date {
    padding: 0.75rem 1.5rem;
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    border-top: 1px solid var(--border);
}

.document-card-wrapper {
    position: relative;
}

.btn-delete {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: all var(--transition-fast);
    z-index: 10;
}

.document-card-wrapper:hover .btn-delete {
    opacity: 1;
}

.btn-delete:hover {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

.delete-confirm {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    border-radius: var(--radius-lg);
    z-index: 20;
}

.delete-confirm p {
    font-size: var(--font-size-sm);
    color: var(--text);
}

.delete-confirm-buttons {
    display: flex;
    gap: 0.5rem;
}

.btn-danger {
    background: var(--error);
    border-color: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
    border-color: #dc2626;
}

/* ==================== EMPTY STATE ==================== */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    text-align: center;
}

.empty-icon {
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--border);
    border-radius: var(--radius-xl);
    color: var(--amber);
    animation: pulse-glow 3s ease-in-out infinite;
}

.empty-text {
    font-size: var(--font-size-lg);
    color: var(--text-muted);
}

.empty-formats {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    letter-spacing: 0.2em;
}

.drop-zone {
    margin-top: 1rem;
    padding: 2rem 3rem;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    color: var(--text-muted);
    font-size: var(--font-size-sm);
    transition: all var(--transition-base);
}

.drop-zone:hover {
    border-color: var(--amber);
    background: var(--amber-glow);
}

/* ==================== UPLOAD ==================== */
.upload-zone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 3rem;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    text-align: center;
    transition: all var(--transition-base);
    min-height: 300px;
}

.upload-zone.dragging {
    border-color: var(--amber);
    background: var(--amber-glow);
}

.upload-icon {
    color: var(--amber);
}

.upload-text {
    font-size: var(--font-size-lg);
    font-weight: 500;
}

.upload-or {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.upload-formats {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
}

.upload-error {
    color: var(--error);
    font-size: var(--font-size-sm);
}

.upload-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--amber);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ==================== MODAL ==================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal {
    width: 90%;
    max-width: 500px;
    padding: 2rem;
}

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

.modal-header h2 {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.btn-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    cursor: pointer;
    font-size: var(--font-size-sm);
}

.btn-close:hover {
    border-color: var(--amber);
    color: var(--amber);
}

/* ==================== SETTINGS ==================== */
.settings-container {
    padding: 2rem;
    max-width: 500px;
    margin: 0 auto;
}

.settings-container h2 {
    font-size: var(--font-size-lg);
    margin-bottom: 1.5rem;
}

.settings-section {
    margin-bottom: 2rem;
}

.settings-section h3 {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 0;
    border-bottom: 1px solid var(--border);
}

.setting-item label {
    font-size: var(--font-size-sm);
}

.setting-control {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.radio-group {
    display: flex;
    gap: 1rem;
}

.radio {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: var(--font-size-sm);
    cursor: pointer;
}

.radio input {
    accent-color: var(--amber);
}

.toggle {
    position: relative;
    display: inline-block;
    width: 48px;
    height: 24px;
}

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

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border);
    border-radius: 24px;
    transition: var(--transition-fast);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background: var(--text);
    border-radius: 50%;
    transition: var(--transition-fast);
}

.toggle input:checked + .toggle-slider {
    background: var(--amber);
}

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

/* ==================== STATS ==================== */
.stats-container {
    height: 100%;
    padding: 2rem;
    overflow-y: auto;
}

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

.stats-header h1 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    letter-spacing: 0.1em;
}

.time-filter {
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    text-align: center;
}

.stat-card.highlight {
    border-color: var(--amber);
    box-shadow: 0 0 20px var(--amber-glow);
}

.stat-value {
    display: block;
    font-size: var(--font-size-2xl);
    font-weight: 600;
    color: var(--text);
    line-height: 1;
}

.stat-label {
    display: block;
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin-top: 0.5rem;
}

.stat-change {
    display: block;
    font-size: var(--font-size-xs);
    margin-top: 0.5rem;
}

.stat-change.positive {
    color: var(--success);
}

.stat-change.negative {
    color: var(--error);
}

.stats-section {
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.stats-section h2 {
    font-size: var(--font-size-base);
    font-weight: 600;
    margin-bottom: 1rem;
}

.chart-placeholder {
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--border);
    border-radius: var(--radius-md);
}

.chart-note {
    color: var(--text-muted);
    font-size: var(--font-size-sm);
}

.bottom-nav {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
}

.nav-item {
    padding: 0.75rem 1.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: var(--font-size-sm);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.nav-item:hover, .nav-item.active {
    color: var(--text);
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    color: var(--amber);
}

/* ==================== ADDITIONAL STATES ==================== */
.loading-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    color: var(--text-muted);
}

.upload-success {
    color: var(--success);
    font-size: var(--font-size-sm);
}

.btn-active {
    background: var(--amber);
    color: var(--bg);
    border-color: var(--amber);
}

.card-meta {
    font-size: var(--font-size-sm);
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ==================== ORP GUIDES ==================== */
.orp-guides {
    display: flex;
    justify-content: center;
    width: 100%;
}

.orp-line-top, .orp-line-bottom {
    width: 1px;
    height: 12px;
    background: var(--amber);
    box-shadow: 0 0 8px var(--amber-glow);
}

.orp-line-top {
    margin-bottom: 4px;
}

.orp-line-bottom {
    margin-top: 4px;
}

.word-text {
    display: flex;
    align-items: baseline;
    justify-content: center;
}

.word-text.chunk-display {
    max-width: 80vw;
    text-align: center;
    line-height: 1.4;
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.4em;
    justify-content: center;
}

.word-chunk-item {
    display: inline-block;
}

/* ==================== MINIMAL PROGRESS ==================== */
.reader-minimal-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--border);
}

.minimal-progress-fill {
    height: 100%;
    background: var(--amber);
    transition: width 100ms linear;
}

/* ==================== FOCUS STATES ==================== */
.reader-container:focus {
    outline: none;
}

/* ==================== FULLSCREEN MODE ==================== */
.reader-container.fullscreen-mode .reader-controls {
    display: none !important;
}

.reader-container.fullscreen-mode .reader-minimal-progress {
    display: none !important;
}

.reader-container.fullscreen-mode .reader-word-display {
    height: 100vh;
}

/* ==================== MOBILE ==================== */
@media (max-width: 768px) {
    .library-container {
        padding: 1rem;
        padding-bottom: 5rem;
    }

    .document-grid {
        grid-template-columns: 1fr;
    }

    .reader-controls {
        padding: 1rem;
    }

    .controls-main {
        flex-wrap: wrap;
    }

    .keyboard-hints {
        display: none;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .bottom-nav {
        bottom: 0;
        left: 0;
        right: 0;
        transform: none;
        border-radius: 0;
        justify-content: center;
    }
}
