:root {
    --bg: #000000;
    --card: #111111;
    --accent: #0071FF;
    --accent-glow: rgba(0, 113, 255, 0.3);
    --text: #FFFFFF;
    --text-dim: #888888;
    --danger: #FF3B30;
    --success: #34C759;
    --font: 'Plus Jakarta Sans', 'Noto Sans Thai', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
    user-select: none;
}

body {
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font);
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
}

#app {
    width: 100%;
    max-width: 480px;
    height: 100%;
    position: relative;
    background: radial-gradient(circle at 50% -20%, #1a1a1a 0%, #000 100%);
}

.view {
    position: absolute;
    inset: 0;
    opacity: 0;
    visibility: hidden;
    transform: scale(0.98);
    transition: all 0.4s cubic-bezier(0.2, 0, 0, 1);
    display: flex;
    flex-direction: column;
    padding: 24px;
}

.view.active {
    opacity: 1;
    visibility: visible;
    transform: scale(1);
}

/* Home View */
.hero {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}

.badge {
    background: var(--accent-glow);
    color: var(--accent);
    padding: 6px 16px;
    border-radius: 100px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 24px;
    text-transform: uppercase;
}

h1 {
    font-size: 40px;
    font-weight: 800;
    line-height: 1.1;
    margin-bottom: 16px;
    background: linear-gradient(to bottom, #fff, #888);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

p {
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 40px;
}

/* Buttons */
.btn-primary {
    background: var(--text);
    color: var(--bg);
    border: none;
    padding: 18px 40px;
    border-radius: 16px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    width: 100%;
    transition: transform 0.2s;
}

.btn-primary:active {
    transform: scale(0.96);
}

.btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border: none;
    padding: 18px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 12px;
}

.btn-icon {
    background: #222;
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    cursor: pointer;
}

/* Test Layout */
.test-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
}

.test-info {
    flex: 1;
    margin-right: 20px;
}

#label-row {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dim);
}

.header-main-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}

.live-stats {
    display: flex;
    gap: 16px;
    font-size: 14px;
    font-weight: 700;
}

#live-speed {
    color: var(--text-dim);
}

#live-combo {
    color: var(--accent);
    transition: transform 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.combo-pop {
    transform: scale(1.3);
}

.timer-wrapper {
    height: 4px;
    background: #222;
    border-radius: 2px;
    margin-top: 8px;
    overflow: hidden;
}

.timer-bar {
    height: 100%;
    background: var(--accent);
    width: 100%;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-toggle {
    background: #222;
    border: 1px solid #333;
    color: var(--text-dim);
    padding: 8px 16px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-toggle.active {
    background: var(--accent-glow);
    color: var(--accent);
    border-color: var(--accent);
}

.test-viewport {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.show-hint-value {
    position: absolute;
    top: -40px;
    font-size: 32px;
    font-weight: 800;
    color: var(--success);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.2s;
}

.show-hint-value.visible {
    opacity: 1;
    transform: translateY(0);
}

.answer-feedback {
    position: absolute;
    font-size: 80px;
    font-weight: 900;
    pointer-events: none;
    opacity: 0;
    z-index: 10;
}

.answer-feedback.correct {
    color: var(--success);
    animation: feedback-pop 0.4s ease-out;
}

.answer-feedback.wrong {
    color: var(--danger);
    animation: feedback-pop 0.4s ease-out;
}

@keyframes feedback-pop {
    0% {
        opacity: 0;
        transform: scale(0.5);
    }

    50% {
        opacity: 0.8;
        transform: scale(1.2);
    }

    100% {
        opacity: 0;
        transform: scale(1.5);
    }
}

.test-track {
    display: flex;
    align-items: center;
    position: absolute;
    left: 50%;
    /* Start the track from center */
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1);
    white-space: nowrap;
}

.digit {
    width: 60px;
    flex-shrink: 0;
    /* Prevent shrinking */
    text-align: center;
    font-size: 48px;
    font-weight: 800;
    color: #333;
    transition: all 0.2s;
}

.digit.active {
    color: var(--text-dim);
}

.digit.highlight {
    color: var(--text);
    transform: scale(1.1);
}

.focus-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.focus-bracket {
    width: 120px;
    /* Precise for 2 digits */
    height: 90px;
    border: 3px solid var(--accent);
    border-radius: 20px;
    box-shadow: 0 0 40px var(--accent-glow);
}

/* Numpad */
.numpad-container {
    padding-bottom: 24px;
}

.numpad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.numpad-btn {
    background: #111;
    border: 1px solid #222;
    color: white;
    padding: 24px;
    font-size: 24px;
    font-weight: 700;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.1s;
}

.numpad-btn:active {
    background: #222;
    transform: scale(0.95);
    border-color: var(--accent);
}

.numpad-btn[data-value="0"] {
    grid-column: span 3;
}

/* Modal Content */
.modal {
    flex: 1;
    display: flex;
    align-items: center;
}

.modal-content {
    background: #0a0a0a;
    border: 1px solid #222;
    width: 100%;
    border-radius: 32px;
    padding: 32px;
}

h2 {
    margin-bottom: 24px;
    text-align: center;
}

.chart-wrapper {
    height: 200px;
    margin-bottom: 24px;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 32px;
}

.result-card {
    background: #111;
    padding: 16px;
    border-radius: 16px;
    text-align: center;
}

.res-label {
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
}

.res-value {
    font-size: 18px;
    font-weight: 800;
    display: block;
    margin-top: 4px;
}

.history-list {
    max-height: 55vh;
    /* Larger scrollable area */
    overflow-y: auto;
    padding-right: 8px;
    /* Space for scrollbar */
    margin-top: 16px;
}

/* Custom Scrollbar for modern look */
.history-list::-webkit-scrollbar {
    width: 4px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 10px;
}

.history-list::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

.history-item {
    background: #111;
    padding: 16px;
    border-radius: 16px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.history-item:hover {
    background: #1a1a1a;
    border-color: #333;
    transform: translateY(-2px);
}

.history-item:active {
    transform: translateY(0);
}

.hidden {
    display: none !important;
}