/* --- Main Container & Typography --- */
.tp-container {
    max-width: 800px;
    margin: 40px auto;
    padding: 30px;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 12px 45px 0 rgba(31, 38, 135, 0.37);
    position: relative;

    /* --- CLS FIX 1 (Primary) --- */
    /* Reserve space for the container before JS loads content */
    /* Height (600.49px) is from your screenshot */
    min-height: 601px; 

    /* --- CLS FIX 2 (Best Practice) --- */
    /* 'transition: all' animates layout changes and makes CLS worse. */
    /* This transitions only non-layout properties. */
    transition: background 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}
/* --- Header & Metrics --- */
.tp-header {
    margin-bottom: 20px;
}
.tp-metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}
.tp-metric {
    text-align: center;
    background: linear-gradient(145deg, #f9f9f9, #e6e6e6);
    padding: 8px 5px;
    border-radius: 12px;
    box-shadow: 3px 3px 7px #d1d1d1, -3px -3px 7px #ffffff;
    transition: all 0.2s ease-in-out;
}
.tp-metric:hover {
    transform: scale(1.05);
}
.tp-metric-label {
    font-size: 0.8em;
    color: #5a5a5a;
    margin-bottom: 4px;
    font-weight: 500;
}
.tp-metric-value {
    font-size: 1.9em;
    font-weight: 700;
    color: #0d47a1;
    transition: transform 0.2s ease-out, color 0.2s ease-out;
}

.tp-metric-value.updated-value {
    transform: scale(1.15);
    color: #42a5f5;
}

/* --- Branding Text Style --- */
.tp-branding {
    font-size: 1em;
    font-weight: 700;
    text-align: center;
    margin-top: 12px;
    background: linear-gradient(90deg, #673ab7, #512da8, #e91e63, #673ab7);
    background-size: 200% auto;
    color: #fff;
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: animated-text-gradient 6s linear infinite;
}

@keyframes animated-text-gradient {
    to {
        background-position: 200% center;
    }
}

/* --- Words Display Area --- */
.tp-words {
    font-size: 1.8em;
    line-height: 1.9;
    background-color: #ffffff;
    padding: 25px;
    border-radius: 15px;
    margin-bottom: 25px;
    border: 1px solid #ddd;
    height: 150px;
    overflow: auto;
    color: #444;
    position: relative;
    box-shadow: inset 0px 2px 8px rgba(0,0,0,0.05);
}
.tp-word.current {
    background-color: #cce7ff;
    color: #0056b3;
    border-radius: 5px;
    padding: 3px 1px;
    font-weight: 500;
}
.tp-letter.correct {
    color: #2e7d32;
    font-weight: 500;
}
.tp-letter.incorrect {
    color: #c62828;
    background-color: #ffcdd2;
    border-radius: 3px;
    text-decoration: none;
}

/* --- Input & Controls --- */
.tp-input-area {
    display: flex;
    gap: 15px;
}
#tp-input {
    flex-grow: 1;
    padding: 18px;
    font-size: 1.3em;
    border: 2px solid transparent;
    border-radius: 12px;
    background-color: #f1f3f4;
    transition: all 0.2s;
}
#tp-input:focus {
    outline: none;
    border-color: #81d4fa;
    background-color: #fff;
    box-shadow: 0 0 0 4px rgba(129, 212, 250, 0.4);
}
#tp-input:disabled {
    background-color: #e9ecef;
    cursor: not-allowed;
}

/* --- Buttons --- */
.tp-button {
    padding: 0 35px;
    font-size: 1.2em;
    font-weight: 700;
    border: none;
    border-radius: 12px;
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    background: linear-gradient(45deg, #673ab7, #512da8);
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
    box-shadow: 0 4px 15px rgba(103, 58, 183, 0.35);
}
.tp-button:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(103, 58, 183, 0.4);
}
.tp-input-area .tp-button {
    min-width: 120px;
    white-space: nowrap;
}
#tp-start-btn {
    background: linear-gradient(45deg, #28a745, #218838);
    min-width: 200px;
}
#tp-start-btn:hover {
    background: linear-gradient(45deg, #218838, #1e7e34);
}

/* --- Paste Area --- */
.tp-paste-area {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px dashed #ccc;
}
.tp-paste-area textarea {
    width: 100%;
    height: 100px;
    margin-bottom: 10px;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #ccc;
}

/* --- Results Screen --- */
.tp-container.results-active .tp-words,
.tp-container.results-active .tp-input-area,
.tp-container.results-active .tp-paste-area {
    display: none;
}
.tp-results-screen {
    display: none;
}
.tp-results-box {
    text-align: center;
    padding: 40px 50px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 15px;
    color: #fff;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    margin-top: 25px;
}
.tp-results-box h3 {
    margin: 0 0 25px 0;
    font-size: 2.8em;
    text-shadow: 2px 2px 4px rgba(0,0,0,0.2);
}
.tp-results-main-stats {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-bottom: 15px;
}
.tp-results-stat-label {
    font-size: 1.1em;
    opacity: 0.8;
}
.tp-results-stat-value {
    font-size: 2.8em;
    font-weight: 700;
}
.tp-results-box p {
    font-size: 1.2em;
    margin-bottom: 20px;
    opacity: 0.9;
}
.tp-results-char-stats {
    display: flex;
    justify-content: center;
    gap: 25px;
    margin-top: 20px;
    padding: 15px;
    background: rgba(255,255,255,0.1);
    border-radius: 10px;
}
.tp-results-char-stat .tp-results-stat-label {
    font-size: 1em;
}
.tp-results-char-stat .tp-results-stat-value {
    font-size: 1.8em;
}
.tp-results-stat-value.green {
    color: #c8e6c9;
}
.tp-results-stat-value.red {
    color: #ffcdd2;
}
#tp-restart-results-btn {
    margin-top: 30px;
    font-size: 1.2em;
    padding: 12px 40px;
    background: #fff;
    color: #673ab7;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
}
#tp-restart-results-btn:hover {
    background: #f1f3f4;
    transform: translateY(-2px);
}

/* --- AI Feedback Section --- */
.tp-loader {
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 4px solid #fff;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#tp-detailed-analysis-list li {
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 12px 15px;
    margin-bottom: 10px;
    display: flex;
    align-items: flex-start;
    gap: 15px;
    border-left: 4px solid #42a5f5;
    color: #e0e0e0;
    line-height: 1.5;
}
#tp-detailed-analysis-list li .dashicons {
    font-size: 20px;
    color: #42a5f5;
    padding-top: 3px;
}
#tp-detailed-analysis-list li strong {
    color: #fff;
    font-weight: 600;
}

/* --- Leaderboard Styles --- */
#tp-leaderboard-container {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.08); /* Card style */
    padding: 25px;
    margin-top: 30px;
    border: 1px solid #eee;
}

.tp-leaderboard-loader {
    text-align: center;
    padding: 20px;
}

/* Table Styles */
.tp-leaderboard-table {
    width: 100%;
    border-collapse: collapse; /* Ensure no gaps */
    overflow: hidden;
    border-radius: 8px 8px 0 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.tp-leaderboard-table thead tr {
    background: linear-gradient(135deg, #673ab7, #512da8);
    color: #fff;
    text-align: left;
    font-weight: bold;
}

.tp-leaderboard-table th {
    padding: 12px 15px;
    font-size: 0.95em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: none;
}

.tp-leaderboard-table tbody tr {
    border-bottom: 1px solid #f0f0f0;
    transition: background-color 0.2s;
}

.tp-leaderboard-table tbody tr:nth-of-type(even) {
    background-color: #f8f9fa;
}

.tp-leaderboard-table tbody tr:hover {
    background-color: #f1f3f4; /* Subtle hover */
}

.tp-leaderboard-table tbody tr:last-of-type {
    border-bottom: 2px solid #673ab7;
}

.tp-leaderboard-table td {
    color: #333;
    font-size: 0.95em;
}

/* Medal Styles */
.tp-medal {
    display: inline-block;
    width: 24px;
    height: 24px;
    line-height: 24px;
    border-radius: 50%;
    color: #fff;
    text-align: center;
    font-weight: bold;
    font-size: 0.85em;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.tp-medal.gold {
    background: linear-gradient(145deg, #ffd700, #ffb300);
    border: 1px solid #ffecb3;
}

.tp-medal.silver {
    background: linear-gradient(145deg, #c0c0c0, #9e9e9e);
    border: 1px solid #e0e0e0;
}

.tp-medal.bronze {
    background: linear-gradient(145deg, #cd7f32, #a1662f);
    border: 1px solid #d7ccc8;
}

/* WPM Green Text Overrides inline style if needed */
.tp-leaderboard-table td:nth-child(3) {
    color: #2e7d32; /* Dark green for readability */
}

/* Show All Button */
#tp-show-all-leaderboard {
    background: transparent;
    border: 2px solid #673ab7;
    color: #673ab7;
    margin-top: 20px;
    font-weight: 600;
}

#tp-show-all-leaderboard:hover {
    background: #673ab7;
    color: #fff;
    transform: none; /* Reset main button transform */
    box-shadow: none;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
    .tp-container { margin: 10px; padding: 20px; }
    .tp-metrics { grid-template-columns: repeat(2, 1fr); }
    .tp-words { font-size: 1.4em; height: 120px; padding: 15px; }
    .tp-input-area { flex-direction: column; gap: 12px; }
    .tp-button { width: 100%; padding: 15px 0; }
    .tp-results-box { padding: 30px 20px; width: 100%; box-sizing: border-box; }
}

/* ====================================================================
    NEW RATING STYLES
====================================================================
*/
.tp-rating-section {
    max-width: 800px;
    margin: 25px auto;
    padding: 20px;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    text-align: center;
    background: #f8f9fa;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}
.tp-rating-section h4 {
    margin: 0 0 10px 0;
    font-size: 1.2em;
    color: #444;
}
.tp-rating-summary p {
    margin: 0 0 10px;
    color: #666;
    font-size: 0.9em;
}
.tp-rating-input-area p {
    margin: 0 0 5px 0;
    font-size: 1em;
    color: #333;
}
.tp-star-rating {
    display: inline-block;
    direction: rtl; /* Makes stars fill from right-to-left */
}
.tp-star-rating .tp-star {
    font-size: 2.5em;
    color: #ddd;
    cursor: pointer;
    transition: color 0.2s;
}
.tp-star-rating .tp-star:hover,
.tp-star-rating .tp-star:hover ~ .tp-star,
.tp-star-rating .tp-star.hover,
.tp-star-rating .tp-star.hover ~ .tp-star {
    color: #ffc107;
}
.tp-rating-thank-you {
    font-weight: bold;
    color: #28a745;
    font-size: 1.1em;
}