:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --success-color: #22c55e;
    --error-color: #ef4444;
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-jp: 'Noto Sans JP', sans-serif;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius-md: 0.5rem;
    --radius-lg: 1rem;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.5;
    height: 100vh;
    height: 100dvh;
    /* Fixed height */
    overflow: hidden;
    /* Prevent window scroll */
    display: flex;
    justify-content: center;
}

#app {
    width: 100%;
    max-width: 600px;
    background: var(--surface-color);
    height: 100vh;
    height: 100dvh;
    /* Fixed height with dynamic viewport support */
    /* Fixed height */
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    /* Ensure children scroll, not app */
}

/* Header */
.app-header {
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.logo {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary-color);
}

.stats {
    font-size: 0.875rem;
    color: var(--text-secondary);
    display: flex;
    gap: 1rem;
}

.stats span span {
    font-weight: 600;
    color: var(--text-primary);
}

/* Main Content */
main {
    flex: 1;
    position: relative;
    padding: 1.5rem;
    margin-top: 1rem;
    overflow-y: auto;
}

.feedback-result {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 1rem;
}

.feedback-details {
    text-align: left;
    background: rgba(255, 255, 255, 0.05);
    /* Dark mode subtle background */
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

/* Light mode adjustments if needed, but assuming dark/glassmorphism */
@media (prefers-color-scheme: light) {
    .feedback-details {
        background: rgba(0, 0, 0, 0.05);
    }
}

.fb-row {
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.fb-label {
    font-weight: bold;
    color: var(--text-secondary);
    margin-right: 0.5rem;
}

.fb-val {
    color: var(--text-primary);
}

.fb-divider {
    border: 0;
    height: 1px;
    background: var(--border-color);
    margin: 0.8rem 0;
}

.hidden {
    display: none;
}

.view {
    display: none;
    flex-direction: column;
    height: 100%;
    animation: fadeIn 0.3s ease-out;
}

.view.active {
    display: flex;
}

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

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

/* Typography */
h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    letter-spacing: -0.025em;
}

h2 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

p {
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

/* Buttons */
.primary-btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    box-shadow: var(--shadow-md);
}

.primary-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.primary-btn:active {
    transform: translateY(0);
}

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 50%;
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--background-color);
    color: var(--text-primary);
}

.tiny-btn {
    font-size: 1rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-left: 0.5rem;
    background: var(--surface-color);
}

.tiny-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* Cards */
.mode-cards {
    display: grid;
    gap: 1rem;
}

.mode-card {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    cursor: pointer;
    transition: all 0.2s;
}

.mode-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.mode-card h3 {
    margin-bottom: 0.25rem;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.mode-card p {
    margin-bottom: 0;
    font-size: 0.9rem;
}

/* Activity View */
.activity-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.progress-bar {
    flex: 1;
    height: 6px;
    background: var(--border-color);
    border-radius: 999px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    width: 0%;
    transition: width 0.3s ease;
}

.card-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    text-align: center;
}

.jp-word {
    font-family: var(--font-jp);
    font-size: 3.5rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.jp-sentence {
    font-family: var(--font-jp);
    font-size: 1.25rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
}

.jp-meaning {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 2rem;
    font-weight: 500;
}

.input-area {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.input-field {
    width: 100%;
    padding: 1rem;
    font-size: 1.25rem;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color 0.2s;
    text-align: center;
    font-family: var(--font-jp);
}

.input-field:focus {
    border-color: var(--primary-color);
}

.input-field.correct {
    border-color: var(--success-color);
    background-color: #f0fdf4;
}

.input-field.wrong {
    border-color: var(--error-color);
    background-color: #fef2f2;
}

/* Choice Buttons */
.choices-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    width: 100%;
}

.choice-btn {
    background: white;
    border: 1px solid var(--border-color);
    padding: 1rem;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1.1rem;
    font-family: var(--font-jp);
    transition: all 0.2s;
}

.choice-btn:hover {
    border-color: var(--primary-color);
    background: #eef2ff;
}

.choice-btn.correct {
    background: var(--success-color);
    color: white;
    border-color: var(--success-color);
}

.choice-btn.wrong {
    background: var(--error-color);
    color: white;
    border-color: var(--error-color);
}

/* Feedback Area */
.feedback-area {
    margin-top: auto;
    width: 100%;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 1rem;
    animation: slideUp 0.3s ease-out;
}

.feedback-area.hidden {
    display: none;
}

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

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

#feedback-message {
    font-weight: 600;
    text-align: center;
    font-size: 1.1rem;
}

.text-success {
    color: var(--success-color);
}

.text-error {
    color: var(--error-color);
}

/* Play Audio Button */
.play-audio-btn {
    background: var(--primary-color);
    color: white;
    border: none;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: transform 0.2s;
    margin: 0 auto 2rem;
}

.play-audio-btn:hover {
    transform: scale(1.05);
}

.replay-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 0.8rem;
    cursor: pointer;
    margin-left: 0.5rem;
    vertical-align: middle;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    background: var(--surface-color);
    color: var(--text-primary);
}

.replay-btn:hover {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
    transform: scale(1.1);
}

/* Summary View */
.summary-stats {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
}

.stat-item {
    flex: 1;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Loader */
.loader {
    width: 48px;
    height: 48px;
    border: 5px solid var(--border-color);
    border-bottom-color: var(--primary-color);
    border-radius: 50%;
    display: inline-block;
    box-sizing: border-box;
    animation: rotation 1s linear infinite;
    margin: 0 auto 1.5rem;
}

@keyframes rotation {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

#loading-view {
    justify-content: center;
    align-items: center;
    text-align: center;
}

/* Vocabulary List View */
.list-header {
    position: sticky;
    top: -1.5rem;
    /* Offset for main padding */
    background: var(--surface-color);
    z-index: 5;
    padding: 1rem 0;
    margin-top: -1rem;
    display: flex;
    gap: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

#vocab-search {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#vocab-search:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.vocab-list-container {
    margin-top: 1rem;
}

.vocab-item {
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.vocab-item:hover {
    border-color: var(--primary-color);
    transform: translateX(4px);
    box-shadow: var(--shadow-sm);
}

/* Status Colors */
.vocab-item.status-correct {
    background-color: #dcfce7;
    /* Pastel Green */
    border-color: #86efac;
}

.vocab-item.status-wrong {
    background-color: #fee2e2;
    /* Pastel Red */
    border-color: #fca5a5;
}

.v-word {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.v-meaning {
    color: var(--text-secondary);
    font-size: 0.9rem;
    max-width: 50%;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Detail View */
.detail-header {
    margin-bottom: 1rem;
}

/* Secondary Button (if not defined) */
.secondary-btn {
    background: white;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.secondary-btn:hover {
    background: var(--background-color);
    border-color: var(--text-secondary);
}

.home-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#home-view {
    height: auto;
    min-height: 100%;
}

/* Footer Link */
.home-footer {
    margin-top: 3rem;
    padding: 1rem;
    text-align: center;
    width: 100%;
}

.home-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.85rem;
    transition: all 0.2s;
    opacity: 0.7;
}

.home-footer a:hover {
    color: var(--primary-color);
    opacity: 1;
    text-decoration: underline;
}