:root {
    --background: #ffffff;
    --surface: #f5f5f5;
    --text: #1a1a1a;
    --text-muted: #666666;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --error: #dc2626;
    --border: #d1d5db;
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --radius: 8px;
}

[data-theme="dark"] {
    --background: #0f0f0f;
    --surface: #1a1a1a;
    --text: #e5e5e5;
    --text-muted: #999999;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --success: #22c55e;
    --error: #ef4444;
    --border: #333333;
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Navigation */
.top-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.nav-home {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
}

.theme-switcher {
    display: flex;
    gap: 0.25rem;
}

.theme-switcher button {
    background: none;
    border: 2px solid transparent;
    border-radius: 6px;
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-muted);
    transition: border-color 0.2s;
}

.theme-switcher button.active {
    border-color: var(--primary);
    color: var(--text);
}

/* Home Mode Grid */
h1 {
    margin-bottom: 1.5rem;
}

.mode-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.mode-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-decoration: none;
    color: var(--text);
    box-shadow: var(--card-shadow);
    transition: transform 0.15s, box-shadow 0.15s;
}

.mode-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.mode-card h2 {
    margin-bottom: 0.5rem;
    color: var(--primary);
}

.mode-card p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* Buttons */
.button {
    display: inline-block;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 0.6rem 1.5rem;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s;
    margin-top: 1rem;
    margin-right: 0.5rem;
}

.button:hover {
    background: var(--primary-hover);
}

.button.secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

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

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

/* Progress Bar */
#progress-bar-container {
    width: 100%;
    height: 6px;
    background: var(--surface);
    border-radius: 3px;
    margin-bottom: 1rem;
    overflow: hidden;
}

#progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    transition: width 0.3s;
    width: 0%;
}

/* Multiple Choice */
#prompt-sentences {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
    line-height: 1.7;
}

#choices {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.choice-button {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    text-align: left;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--text);
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.5;
}

.choice-button:hover:not(:disabled) {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 8%, var(--surface));
}

.choice-button.correct {
    background: color-mix(in srgb, var(--success) 15%, var(--surface));
    border-color: var(--success);
}

.choice-button.wrong {
    background: color-mix(in srgb, var(--error) 15%, var(--surface));
    border-color: var(--error);
}

#feedback {
    margin-top: 1rem;
    font-weight: 600;
    min-height: 1.5em;
}

.feedback-correct { color: var(--success); }
.feedback-wrong { color: var(--error); }

/* Fill in the Blank */
.monospace-display {
    font-family: 'Courier New', Courier, monospace;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    line-height: 2.2;
    margin-bottom: 1rem;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 1rem;
}

.monospace-display .word-group {
    display: inline;
    letter-spacing: 0.15em;
}

.monospace-display .char-revealed {
    color: var(--text);
}

.monospace-display .char-blank {
    color: var(--text-muted);
    opacity: 0.5;
}

.monospace-display .char-typed {
    color: var(--primary);
    font-weight: 700;
}

.monospace-display .char-cursor {
    border-bottom: 2px solid var(--primary);
    animation: blink 1s step-end infinite;
}

.monospace-display .word-error-flash {
    color: var(--error);
    font-weight: 700;
}

.monospace-display .punct {
    letter-spacing: 0;
    color: var(--text-muted);
}

.monospace-display .punct-revealed {
    color: var(--text);
}

@keyframes blink {
    50% { border-bottom-color: transparent; }
}

#hidden-input {
    position: absolute;
    left: -9999px;
    opacity: 0;
    width: 1px;
    height: 1px;
}

#fitb-feedback {
    min-height: 1.5em;
    font-weight: 600;
}

#fitb-tap-hint {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}

/* Sentence Ordering / Word Ordering - Drag and Drop */
#clause-list, #word-bank, #sentence-slots {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

#word-bank {
    flex-direction: row;
    flex-wrap: wrap;
}

.draggable-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    cursor: grab;
    user-select: none;
    transition: transform 0.15s, box-shadow 0.15s, background 0.2s;
    line-height: 1.5;
    touch-action: none;
}

.draggable-item:active {
    cursor: grabbing;
}

.draggable-item.dragging {
    opacity: 0.5;
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.draggable-item.drag-over {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 8%, var(--surface));
}

.draggable-item.correct-position {
    background: color-mix(in srgb, var(--success) 15%, var(--surface));
    border-color: var(--success);
    cursor: default;
}

.draggable-item.wrong-position {
    background: color-mix(in srgb, var(--error) 15%, var(--surface));
    border-color: var(--error);
}

.draggable-item.locked {
    opacity: 0.7;
    cursor: default;
}

/* Word ordering specifics */
.word-chip {
    display: inline-block;
    padding: 0.4rem 0.75rem;
    font-size: 0.95rem;
}

.anchored-word {
    background: color-mix(in srgb, var(--primary) 15%, var(--surface));
    border-color: var(--primary);
    cursor: default;
    opacity: 0.8;
}

#anchored-sentence {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1rem;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 3rem;
    align-items: center;
}

#ordering-feedback, #word-order-feedback {
    min-height: 1.5em;
    font-weight: 600;
    margin-top: 0.5rem;
}

/* Results */
#results-area, #fitb-results, #ordering-results, #word-order-results {
    text-align: center;
}

#results-detail {
    text-align: left;
    margin-top: 1.5rem;
}

.result-item {
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 0;
}

.result-item.missed {
    color: var(--error);
}

/* Responsive */
@media (max-width: 600px) {
    .container {
        padding: 1rem 0.75rem;
    }

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

    .monospace-display {
        font-size: 0.85rem;
        padding: 0.75rem;
    }
}