:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #0f172a;
    --accent: #14b8a6;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 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);
    --sidebar-width: 300px;
    --header-height: 70px;
    --glass: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.3);
}

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

body {
    font-family: 'Inter', 'Noto Sans JP', sans-serif;
    background-color: var(--background);
    color: var(--text-main);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--secondary);
    color: white;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.sidebar.collapsed {
    width: 80px;
}

.sidebar.collapsed .logo span,
.sidebar.collapsed .category-title,
.sidebar.collapsed .exam-item span {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    padding: 1.5rem;
}

.sidebar.collapsed .exam-item {
    padding: 1rem;
    justify-content: center;
}

.sidebar-toggle {
    position: absolute;
    top: 20px;
    right: -15px;
    width: 30px;
    height: 30px;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 110;
    box-shadow: var(--shadow);
    border: none;
}

.sidebar-header {
    padding: 2rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: 0.05em;
    color: var(--accent);
}

.category-list {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem 0;
}

.category-list::-webkit-scrollbar {
    width: 5px;
}

.category-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.category-group {
    margin-bottom: 0.5rem;
}

.category-title {
    padding: 0.75rem 2rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.1em;
}

.exam-item {
    padding: 0.75rem 2rem;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
    color: #cbd5e1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.exam-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: white;
}

.exam-item.active {
    background-color: var(--primary);
    color: white;
    border-right: 4px solid var(--accent);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    transition: all 0.3s ease;
}

.layout-with-right-sidebar {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.top-header {
    height: var(--header-height);
    background: var(--glass);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2.5rem;
    z-index: 90;
}

.menu-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-main);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: background 0.2s;
}

.menu-btn:hover {
    background: rgba(0,0,0,0.05);
}

#header-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-main);
}

.timer-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: var(--primary);
    background: #eef2ff;
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-variant-numeric: tabular-nums;
}

.timer-display.hidden {
    display: none;
}

.view-container {
    flex: 1;
    overflow-y: auto;
    padding: 2.5rem;
    scroll-behavior: smooth;
}

.view {
    display: none;
    max-width: 900px;
    margin: 0 auto;
    animation: fadeIn 0.4s ease;
}

.view.active {
    display: block;
}

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

/* Welcome Card */
.welcome-card {
    text-align: center;
    padding: 4rem 2rem;
    background: white;
    border-radius: 1.5rem;
    box-shadow: var(--shadow);
}

.welcome-card h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.accent {
    color: var(--primary);
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 2rem;
    margin-top: 4rem;
}

.feature {
    padding: 2rem;
    border-radius: 1rem;
    background: var(--background);
    transition: transform 0.2s;
}

.feature:hover {
    transform: translateY(-5px);
}

.feature i {
    color: var(--accent);
    margin-bottom: 1rem;
}

/* Exam Detail */
.exam-header {
    background: white;
    padding: 2rem;
    border-radius: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.exam-meta {
    display: flex;
    gap: 2rem;
    margin-top: 1.5rem;
}

.meta-item {
    display: flex;
    flex-direction: column;
}

.meta-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.meta-value {
    font-weight: 600;
    font-size: 1.1rem;
}

.parts-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-top: 2rem;
}

.part-card {
    background: white;
    padding: 1.5rem;
    border-radius: 1rem;
    border-left: 4px solid var(--accent);
    box-shadow: var(--shadow);
}

.part-card h3 {
    margin-bottom: 0.5rem;
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.4);
}

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

/* Test Area */
.test-container {
    padding-bottom: 100px;
}

.question-block {
    background: white;
    padding: 2rem;
    border-radius: 1rem;
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
}

.question-title {
    font-weight: 700;
    margin-bottom: 1.5rem;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 1rem;
}

.question-item {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: #fafafa;
    border-radius: 0.75rem;
}

.question-text {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    font-weight: 500;
}

.options {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.option {
    background: white;
    border: 1px solid var(--border);
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.option:hover {
    border-color: var(--primary);
    background: #f5f3ff;
}

.option.selected {
    border-color: var(--primary);
    background: #eef2ff;
    box-shadow: inset 0 0 0 1px var(--primary);
}

.option-circle {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.option.selected .option-circle {
    border-color: var(--primary);
    background: var(--primary);
}

.option.selected .option-circle::after {
    content: '';
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
}

.test-footer {
    display: none; /* Hidden because we use right sidebar */
}

/* Right Sidebar */
.right-sidebar {
    width: 320px;
    background: white;
    border-left: 1px solid var(--border);
    display: none;
    flex-direction: column;
    overflow-y: auto;
    padding: 1.5rem;
}

.right-sidebar.active {
    display: flex;
}

.right-sidebar-header {
    margin-bottom: 1.5rem;
}

.timer-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.timer-label {
    font-weight: 500;
    color: var(--text-main);
}

.timer-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ef4444;
}

.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.btn-submit-large {
    background: #ef4444;
    color: white;
    padding: 1rem;
    font-size: 1.1rem;
    justify-content: center;
}

.btn-save-large {
    background: white;
    border: 1px solid var(--border);
    color: var(--text-main);
    padding: 1rem;
    font-size: 1.1rem;
    justify-content: center;
}

.nav-section {
    margin-bottom: 1.5rem;
}

.nav-section-title {
    font-weight: 700;
    margin-bottom: 1rem;
    font-size: 1rem;
}

.question-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
}

.nav-item {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f8fafc;
    border-radius: 0.5rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.nav-item:hover {
    background: #e2e8f0;
}

.nav-item.answered {
    background: #eef2ff;
    color: var(--primary);
    border-color: var(--primary);
}

.nav-item.active {
    background: var(--primary);
    color: white;
}

/* Question Audio & Image */
.question-audio {
    margin-bottom: 1rem;
    width: 100%;
}

.question-image {
    max-width: 100%;
    height: auto;
    border-radius: 0.5rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow);
}

/* Results */
.result-card {
    background: white;
    padding: 3rem;
    border-radius: 1.5rem;
    box-shadow: var(--shadow-lg);
    text-align: center;
}

.result-score {
    font-size: 4rem;
    font-weight: 800;
    color: var(--primary);
    margin: 1rem 0;
}

.result-stats {
    display: flex;
    justify-content: center;
    gap: 3rem;
    margin: 2rem 0;
}

/* Review Mode */
.option.correct {
    border-color: #22c55e;
    background: #f0fdf4;
}

.option.wrong {
    border-color: #ef4444;
    background: #fef2f2;
}

.explain-btn {
    margin-top: 1rem;
    font-size: 0.85rem;
    color: var(--primary);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: underline;
}

.explanation {
    margin-top: 1rem;
    padding: 1.5rem;
    background: #f8fafc;
    border-radius: 0.5rem;
    display: none;
    text-align: left;
    font-size: 0.9rem;
    border-left: 4px solid var(--accent);
}

.explanation.show {
    display: block;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    padding: 2.5rem;
    border-radius: 1rem;
    max-width: 450px;
    width: 90%;
    text-align: center;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
    justify-content: center;
}

/* Responsive */
@media (max-width: 1024px) {
    :root {
        --sidebar-width: 260px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .test-footer {
        width: 100%;
    }
}

/* Paragraph Reading Box */
.txt-read-box {
    background: #fdfdfd;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--text-main);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.txt-read-box p {
    margin-bottom: 1rem;
}

/* Sidebar Accordion */
.category-group {
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.category-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    letter-spacing: 0.05em;
    color: rgba(255,255,255,0.7);
    transition: all 0.2s;
}

.category-title:hover {
    background: rgba(255,255,255,0.05);
    color: white;
}

.category-group.active .category-title {
    color: var(--primary);
    background: rgba(79, 70, 229, 0.1);
}

.chevron-icon {
    width: 16px;
    height: 16px;
    transition: transform 0.3s;
}

.category-group.active .chevron-icon {
    transform: rotate(180deg);
}

.exam-items-container {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    background: rgba(0,0,0,0.1);
}

.category-group.active .exam-items-container {
    max-height: 1000px; /* Large enough for many tests */
}

.exam-item {
    padding: 0.8rem 2.5rem;
    font-size: 0.85rem;
}

/* Language Modal */
.lang-select-content {
    max-width: 400px;
    text-align: center;
}

.lang-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    margin-top: 2rem;
}

.lang-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem;
    background: var(--bg-light);
    border: 2px solid transparent;
    border-radius: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
    color: var(--text-main);
}

.lang-btn:hover {
    border-color: var(--primary);
    transform: translateY(-5px);
    background: white;
}

.lang-btn .flag {
    font-size: 2.5rem;
}

/* Header Actions */
.header-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.icon-btn i {
    width: 20px;
    height: 20px;
}

/* Statistics Dashboard */
.stats-dashboard {
    margin-top: 3rem;
    padding: 2rem;
    background: white;
    border-radius: 1.5rem;
    box-shadow: 0 10px 25px rgba(0,0,0,0.05);
}

.stats-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.stats-header h2 {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.5rem;
    color: var(--text-main);
}

.last-update {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.stats-grid {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.stats-card {
    background: var(--bg-light);
    padding: 1.5rem;
    border-radius: 1.25rem;
    border: 1px solid rgba(0,0,0,0.05);
}

.main-stat {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    color: white;
}

.main-stat .stat-label { color: rgba(255,255,255,0.8); }
.main-stat .stat-value { font-size: 2.5rem; font-weight: 700; margin: 0.5rem 0; }

.stat-trend {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
}

.stat-trend.plus { color: #4ade80; }
.stat-trend.minus { color: #f87171; }

.stat-icon {
    width: 48px;
    height: 48px;
    background: rgba(255,255,255,0.2);
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chart-card {
    min-height: 300px;
    display: flex;
    flex-direction: column;
}

.chart-container {
    flex: 1;
    position: relative;
    margin-top: 1rem;
}

.level-quick-stats {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1rem;
}

.level-stat-item {
    padding: 1.25rem;
    background: white;
    border: 1px solid rgba(0,0,0,0.05);
    border-radius: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
}

.level-stat-item:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: 0 10px 20px rgba(0,0,0,0.05);
}

.level-stat-item .level-tag {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 2rem;
    font-weight: 700;
    font-size: 0.75rem;
    margin-bottom: 0.75rem;
}

.level-tag.n1 { background: #fee2e2; color: #ef4444; }
.level-tag.n2 { background: #ffedd5; color: #f97316; }
.level-tag.n3 { background: #fef9c3; color: #eab308; }
.level-tag.n4 { background: #dcfce7; color: #22c55e; }
.level-tag.n5 { background: #dbeafe; color: #3b82f6; }

.level-stat-val {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    display: block;
}

.level-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

@media (max-width: 1200px) {
    .stats-grid { grid-template-columns: 1fr; }
    .level-quick-stats { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
    .level-quick-stats { grid-template-columns: repeat(2, 1fr); }
}

/* Explain Button UI */
.explain-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    margin-top: 1rem;
    background: #f0f7ff;
    color: #0369a1;
    border: 1px solid #bae6fd;
    border-radius: 0.75rem;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.explain-btn:hover {
    background: #e0f2fe;
    color: #0284c7;
    border-color: #7dd3fc;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

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

.explain-btn i {
    width: 16px;
    height: 16px;
}

.explanation {
    margin-top: 1rem;
    padding: 1.25rem;
    background: #f8fafc;
    border-left: 4px solid #0ea5e9;
    border-radius: 0.5rem;
    font-size: 0.9375rem;
    line-height: 1.6;
    color: #334155;
    display: none;
    animation: slideDown 0.3s ease-out;
}

.explanation.show {
    display: block;
}

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