/* ChemRise - mikan風デザイン */
@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700;900&display=swap');

:root {
    --primary: #4A7DFF;
    --primary-light: #6B9AFF;
    --primary-dark: #3360D4;
    --accent: #FF6B35;
    --success: #2DD4A0;
    --danger: #FF4757;
    --bg: #F5F7FA;
    --card: #FFFFFF;
    --text: #1A1A2E;
    --text-sub: #6B7280;
    --text-light: #9CA3AF;
    --border: #E5E7EB;
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 8px 32px rgba(74, 125, 255, 0.15);
    --radius: 16px;
    --radius-sm: 12px;
    --radius-xs: 8px;
    --max-w: 430px;
    --nav-h: 64px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* Dark Mode */
.dark-mode {
    --bg: #0F172A;
    --card: #1E293B;
    --text: #F1F5F9;
    --text-sub: #94A3B8;
    --text-light: #64748B;
    --border: #334155;
    --shadow: 0 2px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
    :root:not(.light-mode) {
        --bg: #0F172A;
        --card: #1E293B;
        --text: #F1F5F9;
        --text-sub: #94A3B8;
        --text-light: #64748B;
        --border: #334155;
        --shadow: 0 2px 16px rgba(0, 0, 0, 0.3);
        --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    }
}

/* ヘッダー背景のデフォルト（メディアクエリに依存しない安全な設定） */
.home-header,
.stats-header {
    background: linear-gradient(135deg, #4A7DFF, #6B9AFF);
}

.dark-mode .home-header,
.dark-mode .stats-header {
    background: linear-gradient(135deg, #1E3A5F, #0F172A);
}

@media (prefers-color-scheme: dark) {
    :root:not(.light-mode) .home-header,
    :root:not(.light-mode) .stats-header {
        background: linear-gradient(135deg, #1E3A5F, #0F172A);
    }
}

.stats-header {
    text-align: left;
    padding: 20px 24px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
    color: #FFFFFF;
}

.stats-header h2 {
    font-size: 22px;
    font-weight: 900;
    margin-bottom: 4px;
    color: #FFFFFF;
}

.stats-header p {
    font-size: 13px;
    opacity: 1;
    color: #FFFFFF !important;
}


/* Spinner Overlay */
.spinner-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}

.spinner-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Error Modal */
.error-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    padding: 24px;
}

.error-modal.show {
    display: flex;
}

.error-modal-content {
    background: var(--card);
    border-radius: var(--radius);
    padding: 32px 24px;
    max-width: 340px;
    width: 100%;
    text-align: center;
    box-shadow: var(--shadow-lg);
}

.error-modal-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.error-modal-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
}

.error-modal-msg {
    font-size: 14px;
    color: var(--text-sub);
    margin-bottom: 20px;
    line-height: 1.5;
}

.error-modal-actions {
    display: flex;
    gap: 12px;
}

.error-modal-actions button {
    flex: 1;
    padding: 12px;
    border: none;
    border-radius: var(--radius-xs);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}

.error-retry-btn {
    background: var(--primary);
    color: #fff;
}

.error-close-btn {
    background: var(--border);
    color: var(--text-sub);
}

/* Button disabled state */
button:disabled,
button.btn-loading {
    opacity: 0.55;
    pointer-events: none;
    cursor: not-allowed;
}

.btn-loading .btn-text {
    visibility: hidden;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, .3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}

.auth-btn {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Dark Mode Toggle */
.dark-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-top: 1px solid var(--border);
    margin-top: 4px;
}

.dark-toggle-label {
    font-size: 14px;
    color: var(--text-sub);
}

.toggle-switch {
    width: 48px;
    height: 26px;
    border-radius: 13px;
    background: var(--border);
    position: relative;
    cursor: pointer;
    transition: background .2s;
    border: none;
}

.toggle-switch.active {
    background: var(--primary);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
    transition: transform .2s;
}

.toggle-switch.active::after {
    transform: translateX(22px);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    font-size: 16px;
}

body {
    font-family: 'Noto Sans JP', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-overflow-scrolling: touch;
}

#app {
    max-width: var(--max-w);
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
    background: var(--bg);
}

/* ===== Screens ===== */
.screen {
    display: none;
    padding: 24px 20px;
    padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 24px);
    animation: fadeIn .3s ease;
}

.screen.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px)
    }

    to {
        opacity: 1;
        transform: translateY(0)
    }
}

/* ===== Bottom Nav (mikan style) ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: var(--max-w);
    background: var(--card);
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: var(--nav-h);
    padding-bottom: var(--safe-bottom);
    border-top: 1px solid var(--border);
    z-index: 100;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.04);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    cursor: pointer;
    transition: .2s;
    color: var(--text-light);
    text-decoration: none;
    border: none;
    background: none;
    font-family: inherit;
}

.nav-item.active {
    color: var(--primary);
}

.nav-item svg {
    width: 24px;
    height: 24px;
}

.nav-item span {
    font-size: 10px;
    font-weight: 500;
}

/* ===== Home Screen ===== */
.home-header {
    text-align: left;
    padding: 24px 20px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    box-shadow: var(--shadow-lg);
    color: #FFFFFF;
}

.home-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.home-header h1,
.home-top-bar h1 {
    font-size: 26px;
    font-weight: 900;
    color: #FFFFFF !important;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    margin: 0;
}

.home-header p {
    font-size: 13px;
    color: #FFFFFF !important;
    opacity: 0.9;
    margin: 0;
}

.stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
    margin: 16px 0;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 16px 10px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 900;
    color: var(--primary);
    line-height: 1.2;
}

.stat-card .stat-label {
    font-size: 11px;
    color: var(--text-sub);
    margin-top: 4px;
}

.category-section {
    margin-top: 24px;
}

.category-section h2 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 12px;
}

.category-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform .15s, box-shadow .15s;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.category-card:active {
    transform: scale(0.97);
}

.category-card:hover {
    box-shadow: var(--shadow-lg);
}

.cat-icon {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
    color: #FFFFFF;
}

.cat-icon.theory {
    background: linear-gradient(135deg, #4A7DFF, #6B9AFF);
}

.cat-icon.inorganic {
    background: linear-gradient(135deg, #2DD4A0, #5EFFC2);
}

.cat-icon.organic {
    background: linear-gradient(135deg, #FF6B35, #FF9F6B);
}

.cat-icon.all {
    background: linear-gradient(135deg, #8B5CF6, #A78BFA);
}

.cat-icon.reaction {
    background: linear-gradient(135deg, #F472B6, #FB923C);
}

.cat-info {
    flex: 1;
}

.cat-info h3 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.cat-info p {
    font-size: 12px;
    color: var(--text-sub);
    margin-top: 2px;
}

.cat-progress {
    width: 48px;
    height: 48px;
    position: relative;
}

.cat-progress svg {
    transform: rotate(-90deg);
}

.cat-progress .progress-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--text);
}

/* Start Button (mikan-like big CTA) */
.start-btn-wrap {
    margin-top: 24px;
}

.start-btn {
    width: 100%;
    padding: 18px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 17px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: transform .15s, box-shadow .15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.start-btn:active {
    transform: scale(0.97);
}

/* ===== Quiz Screen ===== */
.quiz-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.quiz-back {
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--text-sub);
    font-size: 20px;
}

.quiz-counter {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.quiz-category-badge {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--primary);
    color: #fff;
    font-weight: 500;
}

.quiz-progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    margin-bottom: 28px;
    overflow: hidden;
}

.quiz-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 3px;
    transition: width .4s ease;
}

.quiz-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 28px 24px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    min-height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.quiz-card .question-text {
    font-size: 18px;
    font-weight: 700;
    line-height: 1.6;
    color: var(--text);
}

.choices {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.choice-btn {
    width: 100%;
    padding: 16px 20px;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    transition: all .15s;
    position: relative;
}

.choice-btn:active {
    transform: scale(0.98);
}

.choice-btn:hover {
    border-color: var(--primary-light);
    background: #F0F4FF;
}

.choice-btn.correct {
    border-color: var(--success);
    background: #ECFDF5;
    color: #065F46;
    animation: correctPulse .4s ease;
}

.choice-btn.wrong {
    border-color: var(--danger);
    background: #FEF2F2;
    color: #991B1B;
    animation: shake .4s ease;
}

.choice-btn.show-correct {
    border-color: var(--success);
    background: #ECFDF5;
    color: #065F46;
}

.choice-btn.disabled {
    pointer-events: none;
    opacity: 0.7;
}

@keyframes correctPulse {
    0% {
        transform: scale(1)
    }

    50% {
        transform: scale(1.03)
    }

    100% {
        transform: scale(1)
    }
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0)
    }

    20% {
        transform: translateX(-8px)
    }

    40% {
        transform: translateX(8px)
    }

    60% {
        transform: translateX(-4px)
    }

    80% {
        transform: translateX(4px)
    }
}

/* Result overlay (mikan-style ○/×) */
.result-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.result-overlay.show {
    display: flex;
}

.result-circle {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 60px;
    font-weight: 900;
    color: #fff;
    animation: resultPop .5s ease forwards;
    opacity: 0;
}

.result-circle.correct {
    background: var(--success);
}

.result-circle.wrong {
    background: var(--danger);
}

@keyframes resultPop {
    0% {
        transform: scale(0);
        opacity: 0
    }

    50% {
        transform: scale(1.2);
        opacity: 1
    }

    100% {
        transform: scale(1);
        opacity: 1
    }
}

/* Explanation panel */
.explanation-panel {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    border-left: 4px solid var(--primary);
    margin-top: 16px;
    display: none;
    animation: slideUp .3s ease;
}

.explanation-panel.show {
    display: block;
}

.explanation-panel h4 {
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.explanation-panel p {
    font-size: 14px;
    line-height: 1.7;
    color: var(--text-sub);
}

.next-btn {
    width: 100%;
    padding: 16px;
    margin-top: 16px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    display: none;
    transition: transform .15s;
}

.next-btn:active {
    transform: scale(0.97);
}

.next-btn.show {
    display: block;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(12px)
    }

    to {
        opacity: 1;
        transform: translateY(0)
    }
}

/* ===== Summary Screen (after 10 questions) ===== */
.summary-screen {
    text-align: center;
}

.summary-circle-wrap {
    width: 160px;
    height: 160px;
    margin: 20px auto;
    position: relative;
}

.summary-circle-wrap svg {
    transform: rotate(-90deg);
}

.summary-score {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.summary-score .score-num {
    font-size: 48px;
    font-weight: 900;
    color: var(--primary);
}

.summary-score .score-label {
    font-size: 13px;
    color: var(--text-sub);
}

.summary-message {
    font-size: 20px;
    font-weight: 700;
    margin: 16px 0 8px;
}

.summary-sub {
    font-size: 14px;
    color: var(--text-sub);
    margin-bottom: 24px;
}

.summary-details {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    text-align: left;
}

.summary-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.summary-detail-row:last-child {
    border-bottom: none;
}

.summary-detail-row .label {
    font-size: 14px;
    color: var(--text-sub);
}

.summary-detail-row .value {
    font-size: 14px;
    font-weight: 700;
}

.summary-detail-row .value.correct-val {
    color: var(--success);
}

.summary-detail-row .value.wrong-val {
    color: var(--danger);
}

.summary-actions {
    display: flex;
    gap: 10px;
}

.summary-actions button {
    flex: 1;
    padding: 16px;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    border: none;
    transition: transform .15s;
}

.summary-actions button:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-secondary {
    background: var(--card);
    color: var(--text);
    border: 2px solid var(--border) !important;
}

/* ===== Stats Screen ===== */
.stats-header {
    margin-bottom: 20px;
}

.stats-header h2 {
    font-size: 22px;
    font-weight: 900;
}

.stats-header p {
    font-size: 13px;
    color: var(--text-sub);
    margin-top: 4px;
}

.streak-card {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: var(--radius);
    padding: 24px;
    color: #fff;
    text-align: center;
    margin-bottom: 20px;
    box-shadow: var(--shadow-lg);
}

.streak-card .streak-fire {
    font-size: 36px;
}

.streak-card .streak-num {
    font-size: 42px;
    font-weight: 900;
}

.streak-card .streak-label {
    font-size: 13px;
    opacity: 0.9;
}

.graph-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.graph-card h3 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 16px;
}

.graph-card canvas {
    width: 100% !important;
    height: 180px !important;
}

.weak-section {
    margin-top: 20px;
}

.weak-section h3 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 12px;
}

.weak-item {
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.weak-item .weak-q {
    font-size: 13px;
    color: var(--text);
    flex: 1;
    margin-right: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.weak-item .weak-rate {
    font-size: 13px;
    font-weight: 700;
    color: var(--danger);
}

.cat-stats-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 20px;
}

.cat-stat-bar {
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 16px;
    box-shadow: var(--shadow);
}

.cat-stat-bar .cat-stat-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.cat-stat-bar .cat-stat-name {
    font-size: 14px;
    font-weight: 600;
}

.cat-stat-bar .cat-stat-rate {
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
}

.cat-stat-bar .bar-bg {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.cat-stat-bar .bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width .6s ease;
}

.bar-fill.theory {
    background: linear-gradient(90deg, #4A7DFF, #6B9AFF);
}

.bar-fill.inorganic {
    background: linear-gradient(90deg, #2DD4A0, #5EFFC2);
}

.bar-fill.organic {
    background: linear-gradient(90deg, #FF6B35, #FF9F6B);
}

/* ===== Responsive ===== */
@media(max-width:430px) {
    .screen {
        padding: 20px 16px;
        padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 20px);
    }

    .quiz-card {
        padding: 24px 18px;
        min-height: 120px;
    }

    .quiz-card .question-text {
        font-size: 16px;
    }
}

/* ===== Auth Screen ===== */
.auth-container {
    max-width: 360px;
    margin: 0 auto;
    padding: 40px 0 24px;
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-logo {
    font-size: 32px;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-header p {
    font-size: 14px;
    color: var(--text-sub);
    margin-top: 8px;
}

.auth-form {
    background: var(--card);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.auth-form h2 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 20px;
    text-align: center;
}

.auth-desc {
    font-size: 13px;
    color: var(--text-sub);
    margin-bottom: 16px;
    text-align: center;
}

.input-group {
    margin-bottom: 16px;
}

.input-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-sub);
    margin-bottom: 6px;
}

.input-group input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-xs);
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    background: var(--bg);
    transition: border-color .2s;
    outline: none;
}

.input-group input:focus {
    border-color: var(--primary);
}

.auth-error {
    color: var(--danger);
    font-size: 13px;
    margin-bottom: 12px;
    min-height: 18px;
}

.auth-success {
    color: var(--success);
    font-size: 13px;
    margin-bottom: 12px;
    min-height: 18px;
}

.auth-btn {
    width: 100%;
    padding: 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    transition: transform .15s;
}

.auth-btn:active {
    transform: scale(0.97);
}

.auth-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.auth-links {
    display: flex;
    justify-content: space-between;
    margin-top: 16px;
}

.auth-links a {
    font-size: 13px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-divider {
    text-align: center;
    margin: 24px 0;
    position: relative;
    color: var(--text-light);
    font-size: 12px;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 40%;
    height: 1px;
    background: var(--border);
}

.auth-divider::before {
    left: 0;
}

.auth-divider::after {
    right: 0;
}

.guest-btn {
    width: 100%;
    padding: 16px;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    font-family: inherit;
    cursor: pointer;
    transition: all .15s;
}

.guest-btn:active {
    transform: scale(0.97);
}

.guest-btn:hover {
    border-color: var(--primary-light);
}

.guest-note {
    font-size: 11px;
    color: var(--text-light);
    text-align: center;
    margin-top: 12px;
}

/* ===== Home Top Bar ===== */
.home-top-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.home-top-bar h1 {
    font-size: 28px;
    font-weight: 900;
    color: #FFFFFF !important;
}

.user-btn {
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--card);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: all .2s;
}

.user-btn:hover {
    border-color: var(--primary);
}

/* ===== User Menu ===== */
.user-menu {
    position: absolute;
    top: 80px;
    right: 20px;
    width: 240px;
    z-index: 200;
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 16px;
    animation: fadeIn .2s ease;
}

.user-menu-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
    font-size: 14px;
    font-weight: 600;
}

.premium-badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 12px;
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #fff;
    font-weight: 700;
}

.user-menu-item {
    width: 100%;
    padding: 12px;
    border: none;
    background: none;
    text-align: left;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: background .15s;
    color: var(--text);
}

.user-menu-item:hover {
    background: var(--bg);
}

.user-menu-close {
    text-align: center;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-light);
    cursor: pointer;
}

/* ===== Premium Screen ===== */
.premium-hero {
    text-align: center;
    padding: 24px 0;
}

.premium-icon {
    font-size: 56px;
    margin-bottom: 12px;
}

.premium-hero h2 {
    font-size: 24px;
    font-weight: 900;
    color: var(--text);
}

.premium-hero p {
    font-size: 14px;
    color: var(--text-sub);
    margin-top: 8px;
}

.premium-price-card {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: var(--radius);
    padding: 24px;
    text-align: center;
    margin: 20px 0;
    box-shadow: var(--shadow-lg);
}

.price-tag {
    color: #fff;
}

.price-amount {
    font-size: 36px;
    font-weight: 900;
}

.price-period {
    font-size: 14px;
    opacity: 0.9;
}

.premium-features {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}

.premium-feature {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}

.premium-feature:last-child {
    border-bottom: none;
}

.feature-icon {
    font-size: 24px;
    flex-shrink: 0;
}

.premium-feature h4 {
    font-size: 14px;
    font-weight: 700;
}

.premium-feature p {
    font-size: 12px;
    color: var(--text-sub);
    margin-top: 2px;
}

.premium-cta {
    width: 100%;
    padding: 18px;
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    font-size: 17px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(255, 165, 0, 0.3);
    transition: transform .15s;
}

.premium-cta:active {
    transform: scale(0.97);
}

.premium-note {
    font-size: 11px;
    color: var(--text-light);
    text-align: center;
    margin-top: 12px;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    max-width: 360px;
    width: 90%;
    padding: 14px 20px;
    background: var(--text);
    color: #fff;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    z-index: 999;
    opacity: 0;
    transition: all .3s ease;
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* ===== Lock Badge ===== */
.lock-badge {
    font-size: 11px;
    background: var(--text-light);
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    margin-left: 8px;
}

/* ===== Reaction Category Color ===== */
.cat-icon.reaction {
    background: linear-gradient(135deg, #E040FB, #AB47BC);
}

.bar-fill.reaction {
    background: linear-gradient(90deg, #E040FB, #AB47BC);
}

/* ===== Quiz Size Selector ===== */
.quiz-size-section {
    margin-top: 24px;
}

.quiz-size-section h2 {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 12px;
}

.size-selector {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.size-btn {
    flex: 1;
    min-width: 56px;
    padding: 12px 8px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card);
    font-size: 14px;
    font-weight: 600;
    color: var(--text-sub);
    cursor: pointer;
    font-family: inherit;
    text-align: center;
    transition: all .15s;
}

.size-btn:active {
    transform: scale(0.95);
}

.size-btn.active {
    border-color: var(--primary);
    background: #EEF2FF;
    color: var(--primary);
}

.size-btn:hover:not(.active) {
    border-color: var(--primary-light);
}

/* ===== Ranking ===== */
.ranking-list {
    margin-top: 16px;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--card);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    box-shadow: var(--shadow);
    transition: transform .15s;
}

.ranking-item.is-me {
    border: 2px solid var(--primary);
    background: #EEF2FF;
}

.rank-pos {
    width: 32px;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-sub);
    flex-shrink: 0;
}

.rank-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
}

.rank-score {
    font-size: 14px;
    font-weight: 700;
    color: var(--primary);
}

.ranking-note {
    font-size: 11px;
    color: var(--text-light);
    text-align: center;
    margin-top: 16px;
    padding: 12px;
}

/* ===== Formula Reference ===== */
.formula-search {
    margin-bottom: 16px;
}

.formula-search input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    background: var(--card);
    outline: none;
    transition: border-color .2s;
}

.formula-search input:focus {
    border-color: var(--primary);
}

.formula-category {
    margin-bottom: 24px;
}

.formula-cat-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 12px;
    padding-left: 12px;
    border-left: 4px solid var(--primary);
    color: var(--text);
}

.formula-card {
    background: var(--card);
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 8px;
    box-shadow: var(--shadow);
}

.formula-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-sub);
    margin-bottom: 6px;
}

.formula-eq {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.5;
    font-family: 'Noto Sans JP', sans-serif;
}

.formula-note {
    font-size: 12px;
    color: var(--primary);
    margin-top: 6px;
    padding: 4px 8px;
    background: #EEF2FF;
    border-radius: 6px;
    display: inline-block;
}

/* ===== Ranking ===== */
.ranking-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-xs);
    margin-bottom: 6px;
    background: var(--bg);
    transition: background .15s;
}

.ranking-item.is-me {
    background: linear-gradient(135deg, rgba(74,125,255,0.12), rgba(107,154,255,0.08));
    border: 1px solid rgba(74,125,255,0.3);
}

.rank-pos {
    width: 28px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-sub);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.rank-name {
    flex: 1;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rank-score {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
}

.ranking-note {
    text-align: center;
    font-size: 11px;
    color: var(--text-light);
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}