:root {
    --primary: #3b82f6;
    --primary-dark: #1d4ed8;
    --success: #16a34a;
    --success-bg: #dcfce7;
    --error: #dc2626;
    --error-bg: #fee2e2;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 16px;
    --radius-sm: 10px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Hiragino Kochi Pro', Meiryo, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
}

#app {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px 80px;
    min-height: 100dvh;
}

.screen {
    padding-top: 28px;
}

/* ===== LOADING ===== */

.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding-top: 0;
    gap: 16px;
}

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

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

.loading-text {
    font-size: 14px;
    color: var(--text-muted);
}

/* ===== AUTH ===== */

.auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding-top: 0;
}

.auth-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 36px 28px 32px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.auth-logo {
    font-size: 48px;
    text-align: center;
    margin-bottom: 4px;
}

.auth-title {
    font-size: 22px;
    font-weight: 800;
    color: var(--primary);
    text-align: center;
}

.auth-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    line-height: 1.6;
}

.auth-input {
    width: 100%;
    padding: 13px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: inherit;
    color: var(--text);
    outline: none;
    transition: border-color 0.15s;
    background: var(--bg);
}

.auth-input:focus {
    border-color: var(--primary);
    background: #fff;
}

.auth-btn { margin-top: 4px; }

.auth-error {
    background: var(--error-bg);
    color: var(--error);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
}

.auth-back {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    text-align: center;
    padding: 4px;
    text-decoration: underline;
}

/* ===== HOME ===== */

.cat-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.cat-chip {
    padding: 6px 14px;
    border-radius: 100px;
    border: 1.5px solid var(--border);
    background: var(--card);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    font-family: inherit;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    white-space: nowrap;
}

.cat-chip.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

.header {
    text-align: center;
    margin-bottom: 28px;
}

.app-title {
    font-size: 26px;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.app-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.user-badge {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg);
    border: 1.5px solid var(--border);
    padding: 4px 14px;
    border-radius: 100px;
    margin-top: 10px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
}

.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px 14px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.stat-value {
    font-size: 34px;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 4px;
    color: var(--text);
}

.stat-value.due { color: var(--error); }
.stat-value.new-val { color: var(--primary); }

.stat-label {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.3px;
}

.progress-section {
    margin-bottom: 24px;
}

.progress-bar-bg {
    background: var(--border);
    border-radius: 100px;
    height: 8px;
    overflow: hidden;
}

.progress-bar-bg.thin {
    height: 4px;
}

.progress-bar-fill {
    background: linear-gradient(90deg, var(--primary), #60a5fa);
    height: 100%;
    border-radius: 100px;
    transition: width 0.4s ease;
    min-width: 4px;
}

.progress-text {
    font-size: 12px;
    color: var(--text-muted);
    text-align: right;
    margin-top: 6px;
    font-weight: 500;
}

.action-section {
    margin-bottom: 20px;
}

.all-done {
    background: var(--card);
    border-radius: var(--radius);
    padding: 28px 20px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.all-done .icon {
    font-size: 40px;
    margin-bottom: 10px;
}

.all-done p {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 6px;
}

.all-done .sub {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 400;
}

.disclaimer {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 20px;
    line-height: 1.7;
    padding: 12px;
    border: 1px dashed var(--border);
    border-radius: var(--radius-sm);
}

.reset-link {
    display: block;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 16px;
    cursor: pointer;
    text-decoration: underline;
    background: none;
    border: none;
    font-family: inherit;
    padding: 4px;
}

/* ===== BUTTONS ===== */

.btn {
    display: block;
    width: 100%;
    padding: 15px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.15s, background 0.15s;
    font-family: inherit;
    text-align: center;
    margin-top: 12px;
    line-height: 1.4;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(59,130,246,0.35);
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
    background: var(--card);
    color: var(--primary);
    border: 2px solid var(--primary);
}

.btn-large {
    padding: 18px 24px;
    font-size: 16px;
    border-radius: var(--radius);
}

/* ===== STUDY ===== */

.study-header {
    margin-bottom: 16px;
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.progress-count {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-muted);
}

.category-badge {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    background: #eff6ff;
    padding: 3px 10px;
    border-radius: 100px;
    letter-spacing: 0.3px;
}

.question-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.question-text {
    font-size: 15px;
    line-height: 1.75;
    color: var(--text);
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* ===== CHOICES ===== */

.choices-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
    margin-bottom: 14px;
}

.choice-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--card);
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 13px 14px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s, transform 0.1s;
    text-align: left;
    font-size: 14px;
    font-family: inherit;
    color: var(--text);
    width: 100%;
    min-height: 52px;
}

.choice-btn:active:not(:disabled) { transform: scale(0.98); }

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

.choice-btn.correct {
    border-color: var(--success);
    background: var(--success-bg);
    color: var(--success);
    font-weight: 600;
}

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

.choice-btn.dimmed { opacity: 0.35; }
.choice-btn:disabled { cursor: default; }

.choice-label {
    font-weight: 800;
    font-size: 15px;
    min-width: 22px;
    text-align: center;
}

.choice-text {
    flex: 1;
    min-width: 0;
    line-height: 1.5;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* ===== FEEDBACK ===== */

.answer-feedback {
    text-align: center;
    font-size: 15px;
    font-weight: 700;
    padding: 11px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
}

.answer-feedback.correct {
    color: var(--success);
    background: var(--success-bg);
}

.answer-feedback.wrong {
    color: var(--error);
    background: var(--error-bg);
}

.explanation-card {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-top: 4px;
    margin-bottom: 4px;
}

.explanation-title {
    font-size: 12px;
    font-weight: 800;
    color: #92400e;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.explanation-text {
    font-size: 13px;
    line-height: 1.85;
    color: #78350f;
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* ===== COMPLETE ===== */

.complete-screen {
    text-align: center;
    padding-top: 50px;
}

.complete-icon {
    font-size: 60px;
    margin-bottom: 14px;
}

.complete-title {
    font-size: 22px;
    font-weight: 800;
    margin-bottom: 28px;
    color: var(--text);
}

.result-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 6px 20px;
    margin-bottom: 28px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.result-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
    font-size: 15px;
}

.result-row:last-child { border-bottom: none; }

.result-row.total-row {
    font-weight: 700;
    font-size: 16px;
}

.result-value {
    font-weight: 800;
    font-size: 20px;
}

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