.ttt-app {
    --ttt-accent: #2563eb;
    --ttt-accent-strong: #1d4ed8;
    --ttt-accent-soft: rgba(37, 99, 235, 0.14);
    --ttt-accent-soft-strong: rgba(37, 99, 235, 0.2);
    --ttt-surface: #ffffff;
    --ttt-surface-alt: #f8fbff;
    --ttt-surface-subtle: #f3f7fc;
    --ttt-border: #d8e2ee;
    --ttt-border-strong: #c3d2e3;
    --ttt-text: #0f172a;
    --ttt-muted: #64748b;
    --ttt-reference-bg: #0f172a;
    --ttt-reference-bg-soft: #152033;
    --ttt-reference-text: #d6deea;
    --ttt-reference-muted: #91a2bb;
    --ttt-correct-bg: rgba(34, 197, 94, 0.22);
    --ttt-correct-text: #ddfce6;
    --ttt-incorrect-bg: rgba(248, 113, 113, 0.24);
    --ttt-incorrect-text: #ffe3e3;
    --ttt-current-outline: #93c5fd;
    --ttt-shadow-lg: 0 26px 60px rgba(15, 23, 42, 0.10);
    --ttt-shadow-md: 0 10px 30px rgba(15, 23, 42, 0.07);
    --ttt-shadow-sm: 0 6px 16px rgba(15, 23, 42, 0.05);
    color: var(--ttt-text);
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border: 1px solid var(--ttt-border);
    border-radius: 26px;
    padding: 28px;
    box-shadow: var(--ttt-shadow-lg);
    margin: 28px 0;
}

.ttt-app * {
    box-sizing: border-box;
}

.ttt-header,
.ttt-panel-heading,
.ttt-progress-strip-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.ttt-heading-copy {
    max-width: 620px;
}

.ttt-title {
    margin: 0 0 6px;
    font-size: clamp(1.65rem, 1.2rem + 1.5vw, 2.15rem);
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.ttt-subtitle,
.ttt-history-note,
.ttt-control-label,
.ttt-stat-label,
.ttt-status-message,
.ttt-extra-characters,
.ttt-panel-note,
.ttt-reference-tip,
.ttt-stat-note,
.ttt-progress-strip-label {
    color: var(--ttt-muted);
}

.ttt-subtitle,
.ttt-panel-note,
.ttt-reference-tip,
.ttt-stat-note {
    margin: 0;
}

.ttt-controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: min(100%, 360px);
}

.ttt-control-label {
    font-size: 0.84rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.ttt-time-limit-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 6px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid var(--ttt-border);
    border-radius: 999px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.ttt-time-limit-pill {
    appearance: none;
    border: none;
    background: transparent;
    border-radius: 999px;
    color: var(--ttt-muted);
    cursor: pointer;
    font: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1;
    padding: 12px 16px;
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease, box-shadow 0.18s ease;
}

.ttt-time-limit-pill:hover,
.ttt-time-limit-pill:focus-visible {
    background: rgba(37, 99, 235, 0.08);
    color: var(--ttt-accent-strong);
    outline: none;
}

.ttt-time-limit-pill:focus-visible {
    box-shadow: 0 0 0 3px var(--ttt-accent-soft);
}

.ttt-time-limit-pill.is-selected {
    background: linear-gradient(180deg, #3776ff 0%, #2563eb 100%);
    color: #ffffff;
    box-shadow: 0 10px 18px rgba(37, 99, 235, 0.28);
}

.ttt-time-limit-pill:disabled,
.ttt-time-limit-pill[disabled] {
    cursor: not-allowed;
    opacity: 0.7;
}

.ttt-panel {
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid var(--ttt-border);
    border-radius: 22px;
    padding: 22px;
    margin-top: 20px;
    box-shadow: var(--ttt-shadow-sm);
    backdrop-filter: blur(10px);
}

.ttt-panel-heading h3 {
    margin: 0;
    font-size: 1.08rem;
}

.ttt-reference-panel {
    background: linear-gradient(180deg, rgba(255,255,255,0.86) 0%, rgba(245,249,255,0.92) 100%);
}

.ttt-reference-frame {
    margin-top: 16px;
    padding: 16px;
    border-radius: 20px;
    background: linear-gradient(180deg, var(--ttt-reference-bg-soft) 0%, var(--ttt-reference-bg) 100%);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.03), 0 18px 34px rgba(15, 23, 42, 0.22);
}

.ttt-reference-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.ttt-reference-kicker {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,0.08);
    color: #f8fafc;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.ttt-reference {
    --ttt-reference-line-height: 2.05em;
    position: relative;
    margin-top: 0;
    padding: 18px 18px 16px;
    height: calc(var(--ttt-reference-line-height) * 3 + 34px);
    min-height: 0;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(59, 130, 246, 0.17) 0, rgba(59, 130, 246, 0.08) var(--ttt-reference-line-height), transparent var(--ttt-reference-line-height), transparent 100%),
        linear-gradient(180deg, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0.01) 100%);
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 16px;
    color: var(--ttt-reference-text);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    white-space: pre-wrap;
    line-height: 2.05;
    font-size: 1.08rem;
    letter-spacing: 0.01em;
}

.ttt-reference::before,
.ttt-reference::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    height: 26px;
    pointer-events: none;
    z-index: 3;
}

.ttt-reference::before {
    top: 0;
    background: linear-gradient(to bottom, rgba(15, 23, 42, 0.94), rgba(15, 23, 42, 0));
}

.ttt-reference::after {
    bottom: 0;
    background: linear-gradient(to top, rgba(15, 23, 42, 0.94), rgba(15, 23, 42, 0));
}

.ttt-reference-track {
    will-change: transform;
    transition: transform 0.18s ease;
}

.ttt-char {
    border-radius: 5px;
    padding: 0 1px;
    color: var(--ttt-reference-muted);
}

.ttt-char-correct {
    background: var(--ttt-correct-bg);
    color: var(--ttt-correct-text);
}

.ttt-char-incorrect {
    background: var(--ttt-incorrect-bg);
    color: var(--ttt-incorrect-text);
}

.ttt-char-current {
    outline: 2px solid var(--ttt-current-outline);
    outline-offset: 1px;
    background: rgba(147, 197, 253, 0.12);
    color: #f8fafc;
}

.ttt-extra-characters {
    margin-top: 12px;
    min-height: 22px;
    font-size: 0.95rem;
}

.ttt-action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.ttt-app .button {
    appearance: none;
    border: 1px solid var(--ttt-border-strong);
    background: #ffffff;
    border-radius: 999px;
    color: var(--ttt-text);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1;
    min-height: 44px;
    padding: 12px 18px;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
    transition: transform 0.18s ease, box-shadow 0.18s ease, background-color 0.18s ease, border-color 0.18s ease;
}

.ttt-app .button:hover,
.ttt-app .button:focus-visible {
    transform: translateY(-1px);
    box-shadow: 0 10px 20px rgba(15, 23, 42, 0.1);
    outline: none;
}

.ttt-app .button:focus-visible {
    box-shadow: 0 0 0 4px var(--ttt-accent-soft), 0 10px 20px rgba(15, 23, 42, 0.12);
}

.ttt-app .button.button-primary {
    border-color: #1d4ed8;
    background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
    color: #ffffff;
    box-shadow: 0 14px 28px rgba(37, 99, 235, 0.28);
}

.ttt-app .button.button-secondary {
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
}

.ttt-app .button[disabled],
.ttt-app .button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
    box-shadow: none;
    transform: none;
}

.ttt-input {
    width: 100%;
    margin-top: 16px;
    border-radius: 18px;
    border: 1px solid var(--ttt-border);
    padding: 18px 20px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    color: var(--ttt-text);
    caret-color: var(--ttt-accent-strong);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 1.05rem;
    line-height: 1.9;
    resize: vertical;
    min-height: 210px;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.9);
}

.ttt-input::placeholder {
    color: #94a3b8;
}

.ttt-input:focus {
    outline: none;
    border-color: var(--ttt-accent);
    box-shadow: 0 0 0 4px var(--ttt-accent-soft), 0 16px 32px rgba(37, 99, 235, 0.08);
}

.ttt-status-message {
    margin: 14px 0 0;
    min-height: 24px;
    font-size: 0.96rem;
}

.ttt-status-message[data-state="success"] {
    color: #166534;
}

.ttt-status-message[data-state="error"] {
    color: #b42318;
}

.ttt-dashboard {
    margin-top: 22px;
}

.ttt-stats-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 14px;
}

.ttt-stat-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--ttt-border);
    border-radius: 20px;
    padding: 18px 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: var(--ttt-shadow-sm);
}

.ttt-stat-card--hero {
    grid-column: span 6;
    min-height: 152px;
    justify-content: flex-end;
    position: relative;
    overflow: hidden;
}

.ttt-stat-card--hero::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(37,99,235,0.16) 0%, rgba(37,99,235,0.04) 50%, transparent 100%);
    pointer-events: none;
}

.ttt-stat-card--secondary {
    grid-column: span 4;
}

.ttt-stat-card--timer {
    border-color: rgba(37, 99, 235, 0.28);
}

.ttt-stat-card--wpm {
    border-color: rgba(56, 189, 248, 0.28);
}

.ttt-stat-label {
    position: relative;
    z-index: 1;
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.ttt-stat-value {
    position: relative;
    z-index: 1;
    font-size: 1.65rem;
    line-height: 1;
    letter-spacing: -0.03em;
}

.ttt-stat-card--hero .ttt-stat-value {
    font-size: clamp(2.35rem, 2rem + 1.1vw, 3.15rem);
}

.ttt-stat-note {
    position: relative;
    z-index: 1;
    font-size: 0.92rem;
}

.ttt-progress-strip {
    margin-top: 14px;
    padding: 16px 18px;
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid var(--ttt-border);
    border-radius: 18px;
    box-shadow: var(--ttt-shadow-sm);
}

.ttt-progress-strip-value {
    font-size: 1rem;
}

.ttt-progress-bar {
    margin-top: 12px;
    width: 100%;
    height: 12px;
    border-radius: 999px;
    background: #e8eef7;
    overflow: hidden;
}

.ttt-progress-fill {
    display: block;
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #3b82f6 0%, #06b6d4 100%);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
    transition: width 0.12s linear;
}

.ttt-history-note {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.08);
    font-size: 0.88rem;
    font-weight: 600;
}

.ttt-history-wrap {
    overflow-x: auto;
    margin-top: 14px;
}

.ttt-history-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--ttt-border);
    border-radius: 18px;
    overflow: hidden;
}

.ttt-history-table th,
.ttt-history-table td {
    padding: 13px 16px;
    border-bottom: 1px solid #e8eef7;
    text-align: left;
    white-space: nowrap;
}

.ttt-history-table thead th {
    background: #eef5fd;
    color: #334155;
    font-size: 0.84rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.ttt-history-table tbody tr:nth-child(even) {
    background: #fbfdff;
}

.ttt-history-table tbody tr:hover {
    background: #f5f9ff;
}

.ttt-history-table tbody tr:last-child td {
    border-bottom: none;
}

.ttt-history-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.08);
    color: var(--ttt-accent-strong);
    font-size: 0.84rem;
    font-weight: 700;
}

.ttt-history-empty-row td {
    color: var(--ttt-muted);
    text-align: center;
    white-space: normal;
}

@media (max-width: 980px) {
    .ttt-stat-card--hero {
        grid-column: span 12;
    }

    .ttt-stat-card--secondary {
        grid-column: span 4;
    }
}

@media (max-width: 782px) {
    .ttt-app {
        padding: 20px;
        border-radius: 22px;
    }

    .ttt-panel {
        padding: 18px;
        border-radius: 18px;
    }

    .ttt-reference-frame {
        padding: 14px;
    }

    .ttt-reference {
        font-size: 1rem;
    }

    .ttt-input {
        min-height: 190px;
        font-size: 1rem;
    }

    .ttt-stat-card--secondary {
        grid-column: span 6;
    }
}

@media (max-width: 640px) {
    .ttt-app {
        padding: 16px;
    }

    .ttt-time-limit-group {
        border-radius: 22px;
    }

    .ttt-time-limit-pill {
        flex: 1 1 calc(50% - 8px);
        justify-content: center;
        text-align: center;
    }

    .ttt-action-buttons,
    .ttt-action-buttons .button {
        width: 100%;
    }

    .ttt-action-buttons .button {
        justify-content: center;
    }

    .ttt-stat-card--secondary,
    .ttt-stat-card--hero {
        grid-column: span 12;
    }

    .ttt-history-table {
        border: none;
        background: transparent;
    }

    .ttt-history-table thead {
        display: none;
    }

    .ttt-history-table,
    .ttt-history-table tbody {
        display: block;
    }

    .ttt-history-table tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px 16px;
        margin-bottom: 12px;
        padding: 14px;
        border: 1px solid var(--ttt-border);
        border-radius: 16px;
        background: rgba(255, 255, 255, 0.92);
        box-shadow: var(--ttt-shadow-sm);
    }

    .ttt-history-table td {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
        padding: 0;
        border: none;
        white-space: normal;
    }

    .ttt-history-table td::before {
        content: attr(data-label);
        color: var(--ttt-muted);
        font-size: 0.76rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
    }

    .ttt-history-empty-row td {
        display: block;
        width: 100%;
        text-align: center;
        padding: 4px 0;
    }

    .ttt-history-empty-row td::before {
        display: none;
    }
}
