:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --success: #16a34a;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

#app { max-width: 720px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  background: var(--primary);
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 10px 16px 0;
}
.app-header h1 { margin: 0 0 8px; font-size: 1.2rem; cursor: pointer; }

.tabbar { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 8px; }
.tabbar button {
  flex: 1 0 auto;
  background: rgba(255,255,255,0.15);
  color: white;
  border: none;
  border-radius: 8px 8px 0 0;
  padding: 8px 10px;
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
}
.tabbar button.active { background: var(--bg); color: var(--primary); font-weight: bold; }

#view-root { flex: 1; padding: 16px; padding-bottom: 48px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 14px;
}

h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 0 0 8px; }

label { display: block; font-size: 0.85rem; color: var(--text-muted); margin: 10px 0 4px; }

input[type=text], input[type=number], textarea, select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  background: white;
  color: var(--text);
  font-family: inherit;
}
textarea { min-height: 70px; resize: vertical; }

.btn {
  display: inline-block;
  padding: 10px 16px;
  border-radius: 8px;
  border: none;
  background: var(--primary);
  color: white;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: center;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: white; color: var(--primary); border: 1px solid var(--primary); }
.btn.danger { background: var(--danger); }
.btn.success { background: var(--success); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.q-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--card);
}
.q-item .meta { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; }
.q-item .q-text { font-weight: 600; margin-bottom: 6px; white-space: pre-wrap; }
.q-item .q-actions { display: flex; gap: 8px; margin-top: 8px; }
.q-item .q-actions button { font-size: 0.78rem; padding: 5px 10px; }

.tag { display: inline-block; background: #eef2ff; color: var(--primary); border-radius: 999px; padding: 2px 9px; font-size: 0.72rem; margin-right: 4px; }

.choice-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.choice-btn {
  text-align: left;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: white;
  cursor: pointer;
  font-size: 0.95rem;
  white-space: pre-wrap;
}
.choice-btn.selected { border-color: var(--primary); background: #eff6ff; }
.choice-btn.correct { border-color: var(--success); background: #f0fdf4; }
.choice-btn.incorrect { border-color: var(--danger); background: #fef2f2; }
.choice-btn:disabled { cursor: default; }

.progress-bar { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; margin-bottom: 10px; }
.progress-bar > div { height: 100%; background: var(--primary); transition: width .2s; }

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: bold;
  font-size: 1.1rem;
}
.timer.warn { color: var(--danger); }

.explanation-box {
  background: #f1f5f9;
  border-left: 4px solid var(--primary);
  padding: 10px 12px;
  border-radius: 6px;
  margin-top: 12px;
  font-size: 0.9rem;
  white-space: pre-wrap;
}
.explanation-box.wrong { border-left-color: var(--danger); }
.explanation-box.right { border-left-color: var(--success); }

.result-score { font-size: 2.2rem; font-weight: bold; text-align: center; margin: 10px 0; }
.result-score.pass { color: var(--success); }
.result-score.fail { color: var(--danger); }

.self-grade-row { display: flex; gap: 10px; margin-top: 12px; }
.self-grade-row button { flex: 1; padding: 12px; font-size: 1rem; }

.empty-state { text-align: center; color: var(--text-muted); padding: 40px 10px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 100;
}
.toast.hidden { display: none; }

.hidden { display: none !important; }

.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.small-note { font-size: 0.78rem; color: var(--text-muted); }

table.import-preview { width: 100%; border-collapse: collapse; font-size: 0.8rem; margin-top: 10px; }
table.import-preview th, table.import-preview td { border: 1px solid var(--border); padding: 6px; text-align: left; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge-sync { font-size: 0.75rem; padding: 2px 8px; border-radius: 999px; }
.badge-sync.ok { background: #dcfce7; color: var(--success); }
.badge-sync.pending { background: #fef9c3; color: #a16207; }
