:root {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --danger: #ef4444;
    --border: #334155;
    --glass: rgba(30, 41, 59, 0.7);
}

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

button,
input,
optgroup,
select,
textarea {
    font-family: inherit;
    font-size: 100%;
    line-height: 1.15;
    margin: 0;
}

body {
    font-family: 'Inter', 'Noto Serif Khmer', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2rem;
    background-image:
        radial-gradient(circle at 20% 20%, rgba(59, 130, 246, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(236, 72, 153, 0.15) 0%, transparent 40%);
}

.app-container {
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

header {
    text-align: center;
}

h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, #60a5fa, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.1rem;
}

.editor-container {
    background: var(--glass);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

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

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

.status-indicator {
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
}

.status-indicator::before {
    content: '';
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #10b981;
    /* Green for ready */
    box-shadow: 0 0 8px #10b981;
}

.status-indicator.processing::before {
    background-color: #f59e0b;
    /* Amber for processing */
    box-shadow: 0 0 8px #f59e0b;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    border: none;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.btn-secondary {
    background-color: var(--bg-color);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

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

/* Editor Styling as requested: definite width/height, don't expand */
.editor-wrapper {
    position: relative;
    width: 100%;
    height: 400px;
}

.editor {
    width: 100%;
    height: 100%;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1rem;
    overflow-y: scroll;
    font-family: 'Noto Serif Khmer', serif;
    font-size: 1.1rem;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
    background-color: transparent;
    color: var(--text-primary);
    outline: none;
    background-color: rgba(15, 23, 42, 0.8);
    /* Darker background */
}

.unknown-word {
    text-decoration: underline;
    text-decoration-color: var(--danger);
    text-decoration-style: solid;
    text-decoration-thickness: 2px;
    text-decoration-skip-ink: none;
    /* Ensures line is drawn over/through descenders/subscripts if they overlap */
}

/* View Mode Styles */
.editor.view-mode {
    background-color: rgba(30, 41, 59, 0.4);
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 4px;
}

.segment-box {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    vertical-align: middle;
    padding: 2px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.05);
    margin: 1px;
}

.unknown-box {
    border: 1px solid var(--danger);
    background-color: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
}

/* Toggle Switch */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 22px;
}

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

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #334155;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

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

input:focus+.slider {
    box-shadow: 0 0 1px var(--accent);
}

input:checked+.slider:before {
    transform: translateX(18px);
}

.slider.round {
    border-radius: 22px;
}

.slider.round:before {
    border-radius: 50%;
}


.unknown-stat {
    transition: color 0.3s;
}

.stats-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.stats-right-group {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-controls {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    transition: opacity 0.2s, visibility 0.2s;
    opacity: 0;
    visibility: hidden;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 2px;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-icon:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.1);
}

.btn-icon:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Highlight current unknown */
.unknown-word.current-highlight,
.unknown-box.current-highlight {
    box-shadow: 0 0 0 2px var(--accent);
    background-color: rgba(59, 130, 246, 0.2);
    border-radius: 2px;
}

.stats-counts {
    display: flex;
    gap: 1.5rem;
}

footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-top: auto;
}

/* API Highlights - Re-added */
::highlight(unknown-word) {
    text-decoration: underline;
    text-decoration-color: var(--danger);
    text-decoration-style: solid;
    text-decoration-thickness: 2px;
    text-underline-offset: 4px;
    /* Start with standard offset */
    text-decoration-skip-ink: none;
    color: currentColor;
}

::highlight(current-nav) {
    background-color: rgba(59, 130, 246, 0.4);
    color: white;
}