:root {
    --background-color: #f5f5f7;
    --text-color: #1d1d1f;
    --primary-color: #0071e3;
    --secondary-color: #86868b;
    --highlight-color: #2997ff;
    --error-color: #ff3b30;
    --success-color: #34c759;
    --warning-color: #ff9500;
    --container-bg: rgba(255, 255, 255, 0.8);
    --rank-first-bg: #ffdb00;
    --rank-second-bg: #00d800;
    --rank-third-bg: #0096ea;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto',
        'Helvetica', 'Arial', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    user-select: none;
    transition: background-color 0.5s ease, color 0.5s ease;
}

.container {
    background-color: var(--container-bg);
    border-radius: 20px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    padding: 40px;
    width: 90%;
    max-width: 800px;
    backdrop-filter: blur(20px);
    margin-bottom: 20px;
    transition: all 0.5s ease;
    animation: fadeIn 0.5s ease-out;
    margin-top: 30px;
}

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

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

h1,
h2 {
    text-align: center;
    color: var(--text-color);
    font-weight: 700;
    margin-bottom: 20px;
    transition: color 0.3s ease;
}

h1 {
    font-size: 2.5em;
    animation: slideDown 0.5s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }

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

h2 {
    font-size: 1.8em;
}

.subtitle {
    text-align: center;
    color: var(--secondary-color);
    font-size: 1.2em;
    margin-bottom: 30px;
    min-height: 1.5em;
    transition: color 0.3s ease;
}

#text-display {
    font-size: 24px;
    margin-bottom: 30px;
    line-height: 1.5;
    text-align: left;
    padding: 20px;
    background-color: rgba(255, 255, 255, 0.5);
    border-radius: 15px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    max-height: 300px;
    overflow-y: auto;
    transition: all 0.3s ease;
    animation: fadeIn 0.5s ease-out;
}

#pinyin-display {
    font-size: 16px;
    margin-bottom: 10px;
    line-height: 1.5;
    text-align: left;
    padding: 10px 20px;
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    color: var(--secondary-color);
    transition: all 0.3s ease;
    animation: fadeIn 0.5s ease-out 0.2s;
    opacity: 0;
    animation-fill-mode: forwards;
}

#input-field {
    width: 100%;
    padding: 15px;
    font-size: 18px;
    border: none;
    border-radius: 10px;
    margin-bottom: 30px;
    background-color: rgba(255, 255, 255, 0.5);
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    animation: fadeIn 0.5s ease-out 0.4s;
    opacity: 0;
    animation-fill-mode: forwards;
}

#input-field:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--highlight-color);
}

#stats {
    display: flex;
    justify-content: space-around;
    margin-top: 30px;
    padding: 20px;
    border-radius: 15px;
    background-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    transition: all 0.3s ease;
    animation: fadeIn 0.5s ease-out 0.6s;
    opacity: 0;
    animation-fill-mode: forwards;
}

.stat {
    text-align: center;
    transition: transform 0.3s ease;
}

.stat:hover {
    transform: scale(1.05);
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary-color);
    transition: color 0.3s ease;
}

.stat-label {
    font-size: 14px;
    color: var(--secondary-color);
    margin-top: 5px;
    transition: color 0.3s ease;
}

.highlight {
    background-color: var(--highlight-color);
    color: white;
}

.error {
    background-color: var(--error-color);
    color: white;
}

.typed {
    background-color: var(--highlight-color);
    color: white;
    border-radius: 0;
    padding: 2px 0;
    transition: all 0.2s ease;
}

.typed:first-child {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
    padding-left: 4px;
}

.typed:last-child {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
    padding-right: 4px;
}

.controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 30px;
    animation: fadeIn 0.5s ease-out 0.8s;
    opacity: 0;
    animation-fill-mode: forwards;
}

.btn {
    padding: 12px 25px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    color: white;
    border: none;
    border-radius: 20px;
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.2);
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:disabled {
    background-color: var(--secondary-color) !important;
    cursor: not-allowed;
    transform: none;
    opacity: 0.7;
}

#start-btn {
    background-color: var(--success-color);
}

#pause-btn {
    background-color: var(--warning-color);
}

#reset-btn {
    background-color: var(--error-color);
}

#language-select {
    display: block;
    margin: 20px auto;
    padding: 10px;
    font-size: 16px;
    border-radius: 10px;
    border: none;
    background-color: var(--container-bg);
    color: var(--text-color);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    animation: fadeIn 0.5s ease-out 1s;
    opacity: 0;
    animation-fill-mode: forwards;
}

#language-select:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--highlight-color);
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

.pulse {
    animation: pulse 0.5s infinite;
}

footer {
    text-align: center;
    padding: 10px;
    font-size: 14px;
    color: var(--secondary-color);
    transition: color 0.3s ease;
    animation: fadeIn 0.5s ease-out 1.2s;
    opacity: 0;
    animation-fill-mode: forwards;
}

.top-group {
    position: absolute;
    top: 20px;
    right: 20px;
    transition: all 0.3s ease;
    animation: fadeIn 0.5s ease-out 1.4s;
    opacity: 0;
    animation-fill-mode: forwards;
}

.top-group .status {
    color: var(--text-color);
    padding: 4px;
    padding-inline: 8px;
    border-radius: 16px;
    opacity: 0.7;
    transition: all 0.3s ease;
    margin-right: 10px;
}

.top-group .status:hover {
    opacity: 1;
    margin-right: 12px;
}

.status.success {
    background-color: var(--success-color);
}
.status.secondary {
    background-color: var(--secondary-color);
}
.status.primary {
    background-color: var(--primary-color);
}
.status.warning {
    background-color: var(--warning-color);
}
.status.error {
    background-color: var(--error-color);
}

#settings-btn {
    background-color: var(--primary-color);
}

#ranks-btn {
    background-color: var(--warning-color);
}

.modal {
    display: none;
    position: fixed;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.4);
    transition: background-color 0.3s ease;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal.show {
    opacity: 1;
}

.modal-content {
    background-color: var(--container-bg);
    margin: 15% auto;
    padding: 30px;
    border-radius: 20px;
    width: 80%;
    max-width: 500px;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(20px);
    transition: all 0.3s ease;
    transform: scale(0.8);
    opacity: 0;
}

.modal.show .modal-content {
    transform: scale(1);
    opacity: 1;
}

.close {
    color: var(--secondary-color);
    float: right;
    font-size: 28px;
    font-weight: bold;
    transition: color 0.3s ease;
}

.close:hover,
.close:focus {
    color: var(--text-color);
    text-decoration: none;
    cursor: pointer;
}

.setting-item {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.3s ease;
}

.setting-item:hover {
    transform: translateX(5px);
}

.setting-item label {
    font-size: 16px;
    color: var(--text-color);
    transition: color 0.3s ease;
}

.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--secondary-color);
    transition: 0.4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: '';
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: 0.4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:focus + .slider {
    box-shadow: 0 0 1px var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(26px);
}

.setting-item select,
.setting-item input[type='number'] {
    padding: 10px;
    border-radius: 10px;
    border: none;
    background-color: var(--container-bg);
    color: var(--text-color);
    font-size: 16px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.setting-item select:focus,
.setting-item input[type='number']:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--highlight-color);
}

.setting-item input[type='number'] {
    width: 80px;
}

#name-modal {
    animation: fadeIn 0.5s ease-out 1.6s;
    opacity: 0;
    animation-fill-mode: forwards;
}

.name-item input#name-field {
    width: 100%;
    padding: 10px;
    font-size: 16px;
    border: none;
    border-radius: 10px;
    margin-top: 10px;
    margin-bottom: 30px;
    background-color: var(--container-bg);
    color: var(--text-color);
    transition: all 0.3s ease;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
    animation: fadeIn 0.5s ease-out 0.4s;
    opacity: 0;
    animation-fill-mode: forwards;
}

.name-item .btn-group {
    display: flex;
    justify-content: end;
}

.name-item .btn-group * {
    margin-left: 10px;
}

.name-item .btn-group #guest-btn {
    background-color: var(--primary-color);
}

.name-item .btn-group #confirm-btn {
    background-color: var(--success-color);
}

.rank-table {
    color: var(--text-color);
    overflow: scroll;
    height: min-content;
}

.rank-table #rank-table-data {
    width: 100%;
    text-align: center;
}

.rank-table .table-header {
    background-color: var(--primary-color);
    color: var(--text-color);
}

.rank-table .table-header th {
    border-radius: 4px;
}

.rank-table table tr:nth-child(2) {
    color: var(--rank-first-bg);
}

.rank-table table tr:nth-child(3) {
    color: var(--rank-second-bg);
}

.rank-table table tr:nth-child(4) {
    color: var(--rank-third-bg);
}

body.dark-mode {
    --background-color: #1a1a1a;
    --text-color: #f5f5f7;
    --container-bg: rgba(40, 40, 40, 0.8);
    --secondary-color: #a1a1a6;
}

body.dark-mode #text-display,
body.dark-mode #pinyin-display,
body.dark-mode #input-field {
    background-color: rgba(60, 60, 60, 0.5);
    color: white;
}

body.dark-mode #stats {
    background-color: rgba(60, 60, 60, 0.5);
}

body.dark-mode .btn {
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

body.dark-mode .btn:hover:not(:disabled) {
    box-shadow: 0 7px 20px rgba(0, 0, 0, 0.4);
}

body.dark-mode #language-select,
body.dark-mode .setting-item select,
body.dark-mode .setting-item input[type='number'] {
    background-color: rgba(60, 60, 60, 0.8);
    color: var(--text-color);
}

@media (prefers-color-scheme: dark) {
    body.auto-mode {
        --background-color: #1a1a1a;
        --text-color: #f5f5f7;
        --container-bg: rgba(40, 40, 40, 0.8);
        --secondary-color: #a1a1a6;
    }

    body.auto-mode #text-display,
    body.auto-mode #pinyin-display,
    body.auto-mode #input-field,
    body.auto-mode #stats {
        background-color: rgba(60, 60, 60, 0.5);
    }

    body.auto-mode .btn {
        box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    }

    body.auto-mode .btn:hover:not(:disabled) {
        box-shadow: 0 7px 20px rgba(0, 0, 0, 0.4);
    }

    body.auto-mode #language-select,
    body.auto-mode .setting-item select,
    body.auto-mode .setting-item input[type='number'] {
        background-color: rgba(60, 60, 60, 0.8);
        color: var(--text-color);
    }
}

.confetti {
    position: fixed;
    top: -10px;
    width: 10px;
    height: 10px;
    animation: fall linear infinite;
}

@keyframes fall {
    to {
        transform: translateY(100vh) rotate(720deg);
    }
}

#failure-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 0, 0, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 1000;
}

#failure-message {
    font-size: 48px;
    color: var(--error-color);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%,
    100% {
        transform: translateX(0);
    }

    10%,
    30%,
    50%,
    70%,
    90% {
        transform: translateX(-10px);
    }

    20%,
    40%,
    60%,
    80% {
        transform: translateX(10px);
    }
}

#success-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 255, 0, 0.3);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
    z-index: 1000;
}

#success-message {
    font-size: 48px;
    color: var(--success-color);
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
    animation: bounce 0.5s ease-in-out;
}

@keyframes bounce {
    0%,
    20%,
    50%,
    80%,
    100% {
        transform: translateY(0);
    }

    40% {
        transform: translateY(-30px);
    }

    60% {
        transform: translateY(-15px);
    }
}
