:root {
    color-scheme: light dark;
    font-family: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
    line-height: 1.6;
    --bg: #f7f7f8;
    --card-bg: #ffffff;
    --text: #222222;
    --muted: #666666;
    --border: #e5e7eb;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --accent-soft: rgba(79, 70, 229, 0.12);
    --accent-ring: rgba(79, 70, 229, 0.35);
    --card-shadow: rgba(15, 23, 42, 0.06);
    --modal-shadow: rgba(15, 23, 42, 0.25);
    --celebration-glow: rgba(79, 70, 229, 0.3);
    --celebration-bg: linear-gradient(135deg, rgba(22, 163, 74, 0.15), rgba(79, 70, 229, 0.1));
    --error: #dc2626;
    --success: #16a34a;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

body.darkmode--activated {
    --bg: #121212;
    --card-bg: #1f1f1f;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --border: #2d2d2d;
    --accent-soft: rgba(99, 102, 241, 0.22);
    --accent-ring: rgba(99, 102, 241, 0.45);
    --card-shadow: rgba(0, 0, 0, 0.4);
    --modal-shadow: rgba(0, 0, 0, 0.55);
    --celebration-glow: rgba(129, 140, 248, 0.45);
    --celebration-bg: linear-gradient(135deg, rgba(34, 197, 94, 0.18), rgba(129, 140, 248, 0.16));
}

body.theme-classic {
    color-scheme: light;
}

body.theme-sakura {
    color-scheme: light;
    --bg: linear-gradient(160deg, #fff7fb 0%, #ffe5f1 45%, #fff5f8 100%);
    --card-bg: rgba(255, 255, 255, 0.88);
    --text: #3d1d2a;
    --muted: #8f6074;
    --border: rgba(255, 182, 193, 0.6);
    --accent: #f472b6;
    --accent-hover: #ec4899;
    --accent-soft: rgba(244, 114, 182, 0.18);
    --accent-ring: rgba(244, 114, 182, 0.38);
    --card-shadow: rgba(244, 114, 182, 0.22);
    --modal-shadow: rgba(244, 114, 182, 0.26);
    --celebration-glow: rgba(244, 114, 182, 0.35);
    --celebration-bg: linear-gradient(135deg, rgba(34, 197, 94, 0.12), rgba(244, 114, 182, 0.18));
}

body.theme-sakura .app {
    backdrop-filter: saturate(120%) blur(6px);
}

body.theme-sakura .card,
body.theme-sakura .modal {
    border-color: rgba(244, 114, 182, 0.28);
}

body.theme-sakura .card {
    box-shadow: 0 20px 40px rgba(244, 114, 182, 0.18);
}

* {
    box-sizing: border-box;
}

a {
    color: inherit;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.app {
    max-width: 720px;
    margin: 0 auto;
    padding: 24px 20px 64px;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding: 8px 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.branding {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.4rem;
    font-weight: 600;
}

.branding-logo {
    display: inline-flex;
}

.branding-title {
    text-decoration: none;
}

.dictionary-name {
    font-size: 0.9rem;
    color: var(--muted);
}

.header-meta {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.9rem;
    color: var(--muted);
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ghost-button {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 999px;
    cursor: pointer;
    transition: background 0.2s ease;
}

.ghost-button:hover,
.ghost-button:focus-visible {
    background: var(--accent-soft);
}

.main {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.spinner {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 3px solid var(--accent-soft);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 32px 24px;
    border: 1px solid var(--border);
    box-shadow: 0 10px 30px var(--card-shadow);
    text-align: center;
}

.word {
    font-size: 2.4rem;
    margin: 0 0 12px;
    word-break: break-word;
    transition: font-size 0.3s ease;
}

/* 文本过长时的字体缩放 */
.word.long-text {
    font-size: 1.8rem;
}

.word.very-long-text {
    font-size: 2rem;
}

.word-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 12px;
    height: 100px;
}

.tts-button {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.2s ease;
    color: var(--muted);
}

.tts-button:hover {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
    transform: scale(1.05);
}

.tts-button:active {
    transform: scale(0.95);
}

.tts-icon {
    width: 22px;
    height: 22px;
    fill: currentColor;
    transition: transform 0.2s ease;
    pointer-events: none;
}

.tts-button:hover .tts-icon {
    transform: scale(1.1);
}

.tts-button:active .tts-icon {
    transform: scale(0.95);
}

.meaning {
    margin: 0 0 12px;
    font-size: 1rem;
}

.reading,
.romaji {
    margin: 0;
    color: var(--muted);
    font-size: 0.95rem;
}

ruby rt {
    font-size: 0.55em;
    color: var(--muted);
}

.answer-form {
    margin-top: 24px;
    display: grid;
    gap: 12px;
}

.answer-form input {
    padding: 10px 14px;
    font-size: 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: transparent;
    color: inherit;
}

.answer-form input:focus {
    outline: 2px solid var(--accent-ring);
    outline-offset: 2px;
}

.answer-form .actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.answer-form button {
    padding: 10px 16px;
    font-size: 1rem;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    background: var(--accent);
    color: #ffffff;
    transition: background 0.2s ease;
}

.answer-form button:disabled {
    opacity: 0.6;
    cursor: progress;
}

.answer-form button:hover:not(:disabled) {
    background: var(--accent-hover);
}

/* 让跳过按钮使用黄色主题，使用更高特异性覆盖通用按钮样式 */
.answer-form .skip-button {
    background: #f59e0b; /* amber-500 */
    color: #ffffff;
    border: 1px solid #f59e0b;
    min-width: 72px;
}

.answer-form .skip-button:hover:not(:disabled),
.answer-form .skip-button:focus-visible:not(:disabled) {
    background: #d97706; /* amber-600 */
    border-color: #d97706;
}

.alerts {
    display: grid;
    gap: 8px;
    min-height: 40px;
}

.alert {
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-size: 0.95rem;
    text-align: center;
}

.alert-success {
    border-color: rgba(22, 163, 74, 0.25);
    background: rgba(22, 163, 74, 0.08);
    color: var(--success);
}

.alert-error {
    border-color: rgba(220, 38, 38, 0.25);
    background: rgba(220, 38, 38, 0.08);
    color: var(--error);
}

.footer {
    margin-top: 32px;
    font-size: 0.85rem;
    color: var(--muted);
    text-align: center;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    z-index: 998;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--card-bg);
    color: inherit;
    border-radius: 16px;
    min-width: 280px;
    max-width: 360px;
    width: calc(100% - 48px);
    padding: 0;
    border: 1px solid var(--border);
    box-shadow: 0 20px 40px var(--modal-shadow);
    z-index: 999;
}

.modal-header,
.modal-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
    font-size: 1.2rem;
}
.modal-footer {
    border-top: 1px solid var(--border);
    border-bottom: none;
    gap: 12px;
    padding: 10px;
}

.modal-body {
    padding: 20px;
    display: grid;
    gap: 12px;
    font-size: 0.95rem;
}

.modal-body select,
.modal-body input[type="checkbox"] {
    font-size: 1rem;
}

.modal-body select {
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: inherit;
    width: 100%;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}

#dictionary-modal {
    max-width: 520px;
    width: min(calc(100% - 48px), 520px);
}

.dictionary-modal-body {
    display: grid;
    gap: 18px;
}

.dictionary-select-group,
.dictionary-modal-body .voice-selection,
.dictionary-modal-body .rate-control {
    display: grid;
    gap: 8px;
}

.dictionary-modal-body .voice-selection {
    gap: 10px;
}

.dictionary-modal-body .voice-selection select {
    width: 100%;
}

.dictionary-modal-body .voice-selection .ghost-button {
    justify-self: start;
    padding: 6px 14px;
}

.dictionary-modal-body .rate-control__track {
    display: flex;
    align-items: center;
    gap: 12px;
}

.dictionary-modal-body .rate-control input[type="range"] {
    flex: 1;
}

.dictionary-modal-body .rate-control span {
    min-width: 3.5ch;
    text-align: right;
    font-weight: 600;
}

#settings-modal {
    max-width: 620px;
    width: min(calc(100% - 48px), 620px);
}

#settings-modal .modal-body {
    gap: 16px;
}

.settings-checkbox-grid {
    display: grid;
    gap: 12px;
}

.settings-checkbox-grid .checkbox {
    width: 100%;
}

@media (min-width: 560px) {
    .settings-checkbox-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 14px 18px;
    }
}

.theme-options {
    margin-top: 6px;
    padding: 0;
    border: none;
    display: grid;
    gap: 14px;
}

.theme-options legend {
    font-weight: 600;
    margin-bottom: 6px;
}

.theme-option {
    position: relative;
    display: grid;
    grid-template-columns: auto auto 1fr;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 14px;
    cursor: pointer;
    background: var(--card-bg);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.theme-option input {
    position: absolute;
    inset: 0;
    opacity: 0;
    pointer-events: none;
}

.theme-option__indicator {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--border);
    transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.theme-option__preview {
    width: 48px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
}

.theme-option__preview--classic {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
}

.theme-option__preview--sakura {
    background: linear-gradient(135deg, #f472b6, #fb7185);
}

.theme-option__content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.theme-option__name {
    font-weight: 600;
}

.theme-option__description {
    font-size: 0.85rem;
    color: var(--muted);
}

.theme-option.is-active {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
    background: var(--card-bg);
}

.theme-option.is-active .theme-option__indicator {
    border-color: var(--accent);
    background: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-soft);
}

@media (min-width: 600px) {
    .theme-options {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
    .theme-option {
        height: 100%;
    }
}

.theme-option:focus-within {
    outline: 2px solid var(--accent-ring);
    outline-offset: 3px;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--muted);
}

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

@media (min-width: 640px) {
    /* Desktop styles already handled by main flexbox layout */
}

/* 庆祝效果样式 */
.celebration-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    overflow: hidden;
}

.celebration-confetti {
    position: absolute;
    width: 10px;
    height: 10px;
    background: var(--accent);
    animation: confetti-fall 3s ease-in-out forwards;
}

.celebration-confetti:nth-child(odd) {
    background: var(--success);
}

.celebration-confetti:nth-child(3n) {
    background: #f59e0b;
}

.celebration-confetti:nth-child(4n) {
    background: #ef4444;
}

.celebration-confetti:nth-child(5n) {
    background: #8b5cf6;
}

@keyframes confetti-fall {
    0% {
        transform: translateY(-100vh) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

.celebration-bounce {
    animation: celebration-bounce 0.6s ease-in-out;
}

@keyframes celebration-bounce {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

.celebration-glow {
    animation: celebration-glow 1.5s ease-in-out;
}

@keyframes celebration-glow {
    0%, 100% {
        box-shadow: 0 10px 30px var(--card-shadow);
    }
    50% {
        box-shadow: 0 10px 30px var(--card-shadow), 0 0 20px var(--celebration-glow);
    }
}

.alert-celebration {
    animation: alert-celebration 0.8s ease-out;
    background: var(--celebration-bg);
    border: 2px solid rgba(22, 163, 74, 0.4);
    font-weight: 600;
    font-size: 1.1rem;
}

@keyframes alert-celebration {
    0% {
        transform: scale(0.8) translateY(20px);
        opacity: 0;
    }
    50% {
        transform: scale(1.05) translateY(-5px);
        opacity: 1;
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@media (max-width: 639px) {
    .app-header {
        flex-direction: column;
        gap: 8px;
        text-align: center;
        padding: 4px 0;
        margin-bottom: 12px;
    }

    .header-left {
        flex-direction: column;
        gap: 8px;
    }

    .branding {
        justify-content: center;
        zoom: 0.8;
    }

    .header-meta {
        align-items: center;
        text-align: center;
        gap: 2px;
        font-size: 0.85rem;
    }

    .header-meta .score {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
        flex-wrap: wrap;
    }

    .header-actions {
        justify-content: center;
    }
}
