:root {
    --bg-color: #232323;
    --card-bg: #2d2d2d;
    --text-primary: #e0e0e0;
    --text-secondary: #a0a0a0;

    /* Typing Colors */
    --text-untyped: #555555;
    --text-typed: #ffffff;
    --cursor-color: #B39DDB;
    /* Pastel Purple */

    /* Accents */
    --accent-primary: #B39DDB;
    /* Pastel Purple */
    --accent-hover: #9575cd;
    --accent-secondary: #80CBC4;
    /* Pastel Teal */

    --font-sans: 'Inter', sans-serif;
    --font-mono: 'Roboto Mono', monospace;
}

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

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-sans);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

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

/* Tab Bar */
.tab-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    scrollbar-width: none;
    /* Hide scrollbar */
}

.tab-btn {
    background: #333;
    border: none;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background 0.2s, color 0.2s;
    min-width: 120px;
    max-width: 200px;
    white-space: nowrap;
    position: relative;
}

.tab-btn:hover {
    background: #444;
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--card-bg);
    color: var(--accent-primary);
    font-weight: 500;
}

.tab-btn .close-tab {
    margin-left: auto;
    opacity: 0;
    font-size: 1.1rem;
    line-height: 1;
    padding: 2px;
    border-radius: 50%;
    transition: opacity 0.2s, background 0.2s;
}

.tab-btn:hover .close-tab {
    opacity: 0.7;
}

.tab-btn .close-tab:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
    color: #ef5350;
}

.tab-btn.new-tab {
    min-width: auto;
    width: 40px;
    justify-content: center;
    border-radius: 8px;
    font-size: 1.2rem;
    background: transparent;
    border: 1px dashed #444;
}

.tab-btn.new-tab:hover {
    border-color: var(--accent-secondary);
    color: var(--accent-secondary);
    background: rgba(128, 203, 196, 0.1);
}

.tab-title {
    overflow: hidden;
    text-overflow: ellipsis;
}

header {
    margin-bottom: 2rem;
    text-align: center;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: 0.5rem;
}

header p {
    color: var(--text-secondary);
}

main {
    flex: 1;
    background-color: var(--card-bg);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Screens */
.screen {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: 100%;
    overflow: hidden;
}

/* Input Screen */
.input-wrapper {
    flex: 1;
    margin-bottom: 1.5rem;
}

textarea {
    width: 100%;
    height: 100%;
    background-color: #1a1a1a;
    border: 2px solid #3d3d3d;
    border-radius: 8px;
    padding: 1.5rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 1rem;
    line-height: 1.6;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}

textarea:focus {
    border-color: var(--accent-primary);
}

/* Buttons */
.btn {
    padding: 0.8rem 2rem;
    border: none;
    border-radius: 8px;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
}

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

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

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

.btn.secondary {
    background-color: transparent;
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
}

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

.actions {
    display: flex;
    justify-content: flex-end;
}

/* Practice Mode Overrides */
.app-container.practice-mode {
    box-shadow: none;
    border-radius: 0;
    padding: 2rem 10%;
    /* Horizontal padding for readability */
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.app-container.practice-mode .typing-area {
    font-size: 2rem;
    /* Larger text */
    line-height: 2;
    padding-bottom: 50vh;
    /* Allow scrolling past end */
}

/* Typing Screen */
.stats-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #3d3d3d;
    flex-shrink: 0;
}

.typing-area {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 1.5rem;
    line-height: 1.8;
    overflow-y: auto;
    white-space: pre-wrap;
    outline: none;
    cursor: text;
    padding-right: 1rem;
    /* Hide scrollbar but allow scroll */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.typing-area::-webkit-scrollbar {
    display: none;
}

/* Character States */
.char {
    color: var(--text-untyped);
    transition: color 0.1s;
}

.char.typed {
    color: var(--text-typed);
    text-shadow: 0 0 2px rgba(255, 255, 255, 0.3);
}

.char.current {
    background-color: transparent;
    border-bottom: 3px solid var(--cursor-color);
    /* color: var(--text-primary); Removed to keep untyped color */
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0% {
        border-bottom-color: var(--cursor-color);
    }

    50% {
        border-bottom-color: transparent;
    }

    100% {
        border-bottom-color: var(--cursor-color);
    }
}

.char.error {
    color: #ef5350;
    background-color: rgba(239, 83, 80, 0.1);
}

#completion-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-top: 2rem;
    animation: fadeIn 0.5s ease;
}

#completion-message h2 {
    color: var(--accent-secondary);
    margin-bottom: 1rem;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

footer {
    margin-top: auto;
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.5;
    padding-top: 1rem;
    font-family: var(--font-mono);
}

.hidden {
    display: none !important;
}

.char.newline {
    display: inline-block;
    min-width: 0.5em;
}

.char.newline.current::after {
    content: '↵';
    color: var(--text-untyped);
    opacity: 0.5;
}

/* Fixed Progress Indicator */
.progress-info {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    background-color: var(--card-bg);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 1px solid #3d3d3d;
    z-index: 100;
    font-family: var(--font-mono);
    font-size: 1.2rem;
    color: var(--accent-secondary);
    transition: opacity 0.3s;
    display: flex;
    gap: 1rem;
}

.progress-info:hover {
    opacity: 0.8;
}

#wpm-display {
    color: var(--accent-primary);
    border-left: 1px solid #3d3d3d;
    padding-left: 1rem;
}

/* Adjust stats-bar since it's now empty or just has back button */
.stats-bar {
    justify-content: flex-start;
    /* Was space-between */
    border-bottom: none;
    /* Optional: remove border if it looks weird */
    margin-bottom: 1rem;
}

/* Dot Grid Background */
.dot-grid {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    width: 100%;
    position: fixed;
    /* Fixed to cover background */
    top: 0;
    left: 0;
    z-index: -1;
    /* Behind content */
}

.dot-grid__wrap {
    width: 100%;
    height: 100%;
    position: relative;
}

.dot-grid__canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}