/* CSS Variables for Theming & Responsiveness */
:root {
    --primary: #6200ea;
    --primary-light: #b085f5;
    --primary-dark: #303f9f;
    --secondary: #03dac6;
    --bg-color: #f5f5f6;
    --surface: #ffffff;
    --text-main: #212121;
    --text-muted: #757575;
    --error: #b00020;
    --success: #4caf50;
    --warning: #ff9800;
    --border: #e0e0e0;
    
    --font-base: 16px;
    --radius: 12px;
    --shadow: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-hover: 0 8px 12px rgba(0,0,0,0.15);
    --transition: 0.2s ease-in-out;
}

[data-theme="dark"] {
    --primary: #bb86fc;
    --primary-light: #d1b3ff;
    --primary-dark: #3700b3;
    --secondary: #03dac6;
    --bg-color: #121212;
    --surface: #1e1e1e;
    --text-main: #e0e0e0;
    --text-muted: #9e9e9e;
    --border: #333333;
    --shadow: 0 4px 6px rgba(0,0,0,0.5);
}

[data-fontsize="small"] { --font-base: 14px; }
[data-fontsize="large"] { --font-base: 20px; }

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

body {
    font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    font-size: var(--font-base);
    line-height: 1.6;
    transition: background-color var(--transition), color var(--transition);
}

/* Typography */
h1, h2, h3 { font-weight: 600; margin-bottom: 1rem; color: var(--text-main); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.3rem; }

/* Layout */
#app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background-color: var(--surface);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}

#app-main {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

.screen { display: none; animation: fadeIn 0.3s; }
.screen.active { display: block; }
.hidden { display: none !important; }

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    min-height: 44px; /* A11y minimum */
    width: 100%;
    margin-bottom: 0.8rem;
}
@media (min-width: 600px) {
    .btn { width: auto; margin-right: 0.5rem; }
}

.btn-primary { background-color: var(--primary); color: #fff; }
.btn-primary:hover { background-color: var(--primary-dark); }
.btn-primary:disabled { background-color: var(--text-muted); cursor: not-allowed; }
.btn-secondary { background-color: var(--surface); color: var(--primary); border: 2px solid var(--primary); }
.btn-outline { background-color: transparent; color: var(--text-main); border: 1px solid var(--border); }
.btn-danger { background-color: var(--error); color: #fff; }
.btn-large { padding: 1rem 2rem; font-size: 1.1rem; width: 100%; }

.icon-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-main);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition);
}
.icon-btn:hover { background-color: rgba(0,0,0,0.05); }
[data-theme="dark"] .icon-btn:hover { background-color: rgba(255,255,255,0.1); }
.star-btn.active { color: var(--warning); }

/* Inputs */
.input-element {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    background-color: var(--surface);
    color: var(--text-main);
    min-height: 44px;
    margin-bottom: 1rem;
}
.input-element:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(98,0,234,0.2); }

/* Forms & Cards */
.form-group { margin-bottom: 1.5rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: bold; color: var(--text-muted); }

.card {
    background-color: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}
.card-list .card { display: flex; align-items: center; cursor: pointer; transition: var(--transition); }
.card-list .card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.card-list .card input[type="checkbox"] { transform: scale(1.5); margin-right: 1rem; }

/* Dashboard & Stats */
.dashboard-stats, .stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.stat-box {
    background-color: var(--surface);
    padding: 1rem;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: var(--shadow);
}
.stat-box span { display: block; font-size: 0.85rem; color: var(--text-muted); }
.stat-box strong { display: block; font-size: 1.5rem; color: var(--primary); margin-top: 0.5rem; }

/* Learning View */
.learning-header { display: flex; flex-direction: column; margin-bottom: 1rem; }
.progress-bar-container { width: 100%; height: 8px; background-color: var(--border); border-radius: 4px; overflow: hidden; margin-bottom: 0.5rem; }
#progress-bar { height: 100%; background-color: var(--primary); width: 0%; transition: width 0.3s; }
.learning-stats { display: flex; justify-content: space-between; font-weight: bold; }
.timer { color: var(--warning); }
.timer.danger { color: var(--error); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }

.flashcard { text-align: center; position: relative; min-height: 60vh; display: flex; flex-direction: column; justify-content: center; }
.card-actions { position: absolute; top: 1rem; right: 1rem; display: flex; gap: 0.5rem; }
.question-text { font-size: 2.5rem; font-weight: bold; margin: 2rem 0 1rem; word-break: break-word; }
.example-text { font-size: 1.1rem; color: var(--text-muted); margin-bottom: 2rem; font-style: italic; }

.answer-area { margin-top: 2rem; width: 100%; }
.choice-grid { display: grid; grid-template-columns: 1fr; gap: 0.8rem; }
@media (min-width: 600px) { .choice-grid { grid-template-columns: 1fr 1fr; } }
.choice-btn { background-color: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); padding: 1rem; font-size: 1.1rem; cursor: pointer; transition: var(--transition); color: var(--text-main); }
.choice-btn:hover { border-color: var(--primary); background-color: rgba(98,0,234,0.05); }

.feedback-area { margin-top: 1.5rem; padding: 1.5rem; border-radius: var(--radius); }
.feedback-area.correct { background-color: rgba(76,175,80,0.1); border: 1px solid var(--success); }
.feedback-area.incorrect { background-color: rgba(176,0,32,0.1); border: 1px solid var(--error); }
.feedback-msg { font-size: 1.5rem; font-weight: bold; margin-bottom: 0.5rem; }
.feedback-area.correct .feedback-msg { color: var(--success); }
.feedback-area.incorrect .feedback-msg { color: var(--error); }
.correct-answer { font-size: 1.2rem; margin-bottom: 1rem; }

/* Result View */
.result-summary { text-align: center; margin: 2rem 0; padding: 2rem; background-color: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.result-score { font-size: 3rem; font-weight: bold; color: var(--primary); }
.result-accuracy { font-size: 1.2rem; color: var(--text-muted); }
.mistakes-list { list-style: none; margin-bottom: 2rem; }
.mistakes-list li { padding: 1rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }

/* Tabs & Tables */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 1.5rem; }
.tab-btn { flex: 1; padding: 1rem; background: none; border: none; font-size: 1rem; cursor: pointer; color: var(--text-muted); font-weight: bold; min-height: 44px;}
.tab-btn.active { color: var(--primary); border-bottom: 3px solid var(--primary); margin-bottom: -2px; }

.table-responsive { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 600px; }
.data-table th, .data-table td { padding: 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.data-table th { background-color: rgba(0,0,0,0.02); font-weight: bold; color: var(--text-muted); }
[data-theme="dark"] .data-table th { background-color: rgba(255,255,255,0.02); }

/* Settings */
.settings-list { background-color: var(--surface); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.setting-item { display: flex; justify-content: space-between; align-items: center; padding: 1rem 0; border-bottom: 1px solid var(--border); }
.setting-item:last-child { border-bottom: none; }
.toggle { width: 44px; height: 24px; appearance: none; background: var(--border); border-radius: 12px; position: relative; cursor: pointer; outline: none; transition: 0.3s; }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; background: #fff; border-radius: 50%; transition: 0.3s; }
.toggle:checked { background: var(--primary); }
.toggle:checked::after { left: 22px; }

/* Toast */
#toast-container { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 1000; display: flex; flex-direction: column; gap: 10px; }
.toast { background-color: #323232; color: #fff; padding: 12px 24px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.3); font-size: 0.9rem; opacity: 0; animation: toastIn 0.3s forwards, toastOut 0.3s 2.7s forwards; }
@keyframes toastIn { to { opacity: 1; transform: translateY(-10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }