
:root[data-theme="dark"] {
    --bg-color: #2b2621;
    --typewriter-body: #1a1613;
    --paper-color: #f2ebd9;
    --ink-color: #2b2b2b;
    --gold-accent: #c5a059;
    --dark-metal: #3a332d;
    --error-color: #a72d2d;
    --correct-color: #4a6b53;
    --key-ring: #7a7066;
    --key-bg: radial-gradient(circle, #2b2b2b 0%, #111 100%);
    --key-text: #f2ebd9;
    --dash-bg: #221d19;
    --input-bg: #111;
}

:root[data-theme="light"] {
    --bg-color: #e3dac9;
    --typewriter-body: #42352b;
    --paper-color: #faf6ee;
    --ink-color: #1a1a1a;
    --gold-accent: #9c7329;
    --dark-metal: #5c4b3e;
    --error-color: #b52626;
    --correct-color: #386b43;
    --key-ring: #94877b;
    --key-bg: radial-gradient(circle, #fcfaf7 0%, #cfc6ba 100%);
    --key-text: #2b2621;
    --dash-bg: #4f4035;
    --input-bg: #f5eedf;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    background-image: radial-gradient(rgba(0,0,0,0.2) 1px, transparent 0);
    background-size: 24px 24px;
    font-family: 'Courier New', Courier, monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    color: #fff;
    padding: 20px;
    transition: background-color 0.4s ease;
}

.typewriter-container {
    background-color: var(--typewriter-body);
    border: 8px solid var(--dark-metal);
    border-radius: 12px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.6), inset 0 2px 10px rgba(255,255,255,0.1);
    width: 100%;
    max-width: 880px;
    padding: 30px;
    position: relative;
    transition: border-color 0.4s ease, background-color 0.4s ease;
}

/* Top Platen/Carriage Roller Area */
.carriage {
    background: linear-gradient(to bottom, #111, #333, #111);
    height: 40px;
    border-radius: 6px;
    margin-bottom: -15px;
    position: relative;
    border-bottom: 3px solid var(--gold-accent);
}

.carriage-knob {
    width: 25px;
    height: 50px;
    background: linear-gradient(to right, #555, #222);
    position: absolute;
    top: -5px;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.5);
}
.carriage-knob.left { left: -20px; }
.carriage-knob.right { right: -20px; }

/* The Paper Stage */
.paper-roll {
    background-color: var(--paper-color);
    background-image: linear-gradient(rgba(0,0,0,0.04) 1px, transparent 0);
    background-size: 100% 2em;
    color: var(--ink-color);
    padding: 40px 50px;
    border-radius: 4px;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.15), 0 10px 20px rgba(0,0,0,0.4);
    height: 220px;
    font-size: 1.35rem;
    line-height: 2em;
    position: relative;
    overflow-y: auto;
    border-left: 1px solid rgba(0,0,0,0.1);
    border-right: 1px solid rgba(0,0,0,0.1);
    transition: background-color 0.4s ease, color 0.4s ease;
}

/* Control Panel Dashboard */
.dashboard {
    display: flex;
    flex-direction: column;
    gap: 15px;
    background-color: var(--dash-bg);
    margin: 20px 0;
    padding: 20px;
    border-radius: 6px;
    border: 2px solid #221d19;
    transition: background-color 0.4s ease;
}

.dashboard-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--gold-accent);
    font-weight: bold;
}

select, button, .file-label {
    background-color: var(--input-bg);
    color: var(--gold-accent);
    border: 2px solid var(--gold-accent);
    padding: 8px 15px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.95rem;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-block;
    text-align: center;
}

select:focus, button:focus {
    outline: none;
    box-shadow: 0 0 8px var(--gold-accent);
}

button:hover, .file-label:hover {
    background-color: var(--gold-accent);
    color: #111;
}

/* Custom Toggle Switch Styling */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 22px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--input-bg);
    border: 2px solid var(--dark-metal);
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 12px; width: 12px;
    left: 3px; bottom: 3px;
    background-color: var(--gold-accent);
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider { border-color: var(--gold-accent); }
input:checked + .slider:before { transform: translateX(24px); }

/* Stats Display Area */
.stats-display {
    display: flex;
    gap: 15px;
}

.stat-box {
    text-align: center;
    background: var(--input-bg);
    padding: 8px 12px;
    border-radius: 4px;
    border-bottom: 3px solid var(--gold-accent);
    min-width: 85px;
    transition: background-color 0.4s ease;
}

.stat-val {
    font-size: 1.3rem;
    font-weight: bold;
    color: #fff;
    display: block;
}
:root[data-theme="light"] .stat-val {
    color: var(--ink-color);
}

.stat-lbl {
    font-size: 0.65rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 2px;
}

/* Custom Text Config Drawer */
.custom-text-section {
    border-top: 1px dashed rgba(255,255,255,0.1);
    padding-top: 15px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
:root[data-theme="light"] .custom-text-section {
    border-top-color: rgba(0,0,0,0.1);
}

.custom-inputs-wrapper {
    display: flex;
    gap: 15px;
    align-items: center;
}

.custom-textarea {
    flex-grow: 1;
    background-color: var(--input-bg);
    border: 1px solid var(--dark-metal);
    border-radius: 4px;
    color: #fff;
    padding: 8px 12px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    resize: none;
    height: 38px;
    transition: background-color 0.4s ease, color 0.4s ease;
}
:root[data-theme="light"] .custom-textarea {
    color: #000;
}
.custom-textarea:focus {
    outline: none;
    border-color: var(--gold-accent);
}

#file-picker { display: none; }

/* Text Display Engine Styles */
.text-container {
    outline: none;
    user-select: none;
}

.char {
    position: relative;
    border-radius: 2px;
}

.char.correct {
    color: var(--correct-color);
    background-color: rgba(74, 107, 83, 0.1);
}

.char.incorrect {
    background-color: rgba(167, 45, 45, 0.2);
    color: var(--error-color);
    border-bottom: 2px dashed var(--error-color);
}

.char.current {
    background-color: rgba(197, 160, 89, 0.3);
    border-left: 2px solid var(--ink-color);
    animation: blink 1s infinite;
}

@keyframes blink { 50% { border-left-color: transparent; } }

/* On-Screen Classical Keyboard */
.v-keyboard {
    background-color: #14110f;
    padding: 20px;
    border-radius: 8px;
    border: 2px solid #221d19;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: inset 0 5px 15px rgba(0,0,0,0.5);
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 8px;
}

.key {
    background: var(--key-bg);
    color: var(--key-text);
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    font-size: 1.1rem;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: 3px solid var(--key-ring);
    box-shadow: 0 4px 0 #000, 0 5px 10px rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    text-transform: uppercase;
    transition: transform 0.05s ease, box-shadow 0.05s ease, border-color 0.05s ease;
    user-select: none;
}

.key.backspace { width: 90px; border-radius: 20px; }
.key.space { width: 340px; border-radius: 20px; }

.key.pressed {
    transform: translateY(4px);
    box-shadow: 0 0px 0 #000, 0 2px 5px rgba(0,0,0,0.8);
    border-color: var(--gold-accent);
    color: var(--gold-accent) !important;
}

.blur-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(242, 235, 217, 0.7);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    color: #111;
    cursor: pointer;
    font-size: 1.4rem;
    text-transform: uppercase;
    letter-spacing: 2px;
    z-index: 10;
}
