:root {
  --navy: #0f2c59;
  --red: #b22234;
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #dce2ec;
  --green: #1e7e34;
}

* {
  box-sizing: border-box;
  font-family: system-ui, -apple-system, sans-serif;
}

body {
  margin: 0;
  background: var(--bg);
  color: #1d2433;
}

.topbar {
  background: var(--navy);
  color: #fff;
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
}

nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--navy);
  font-weight: 600;
  cursor: pointer;
}

button:hover {
  opacity: 0.92;
}

.btn-primary {
  background: var(--red);
  color: #fff;
  border-color: var(--red);
}

.btn-navy {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.container {
  max-width: 960px;
  margin: 24px auto;
  padding: 0 16px 48px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 99px;
  font-size: 0.78rem;
  font-weight: 600;
  background: #e8eef8;
  color: var(--navy);
}

.badge.done {
  background: #e3f5e8;
  color: var(--green);
}

.badge.fail {
  background: #fdeaea;
  color: var(--red);
}

.muted {
  color: #5b657a;
  font-size: 0.9rem;
}

dialog {
  border: none;
  border-radius: 10px;
  padding: 24px;
  max-width: 480px;
  width: 92%;
}

dialog label {
  display: block;
  margin: 10px 0;
  font-size: 0.9rem;
  font-weight: 600;
}

dialog input {
  width: 100%;
  padding: 8px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.auth-card {
  max-width: 420px;
  margin: 48px auto;
}

.auth-card label {
  display: block;
  margin: 12px 0;
  font-weight: 600;
  font-size: 0.9rem;
}

.auth-card input {
  width: 100%;
  padding: 10px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.error-msg {
  color: var(--red);
  font-size: 0.9rem;
  margin-top: 8px;
}

.oral-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.recording {
  background: var(--red) !important;
  border-color: var(--red) !important;
  color: #fff !important;
}

.oral-feedback {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
}

.oral-feedback.ok {
  background: #e3f5e8;
  border: 1px solid #a6dfb6;
}

.oral-feedback.bad {
  background: #fdeaea;
  border: 1px solid #f3b5b5;
}

/* --- Interactive Textbook Layout --- */

.tb-hero {
  background: linear-gradient(135deg, #0f2c59 0%, #1d4685 65%, #8f1d2c 100%);
  color: #fff;
  border-radius: 12px;
  padding: 26px 28px;
  margin-bottom: 20px;
  box-shadow: 0 6px 18px rgba(15, 44, 89, 0.16);
}

.tb-hero-kicker {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  opacity: 0.85;
  margin-bottom: 6px;
}

.tb-hero h1 {
  margin: 0 0 10px 0;
  font-size: 1.75rem;
}

.tb-hero-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 0.9rem;
  opacity: 0.92;
}

.tb-objectives {
  background: #f0f5fc;
  border-left: 4px solid var(--navy);
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 22px;
}

.tb-objectives-title {
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 8px;
}

.tb-objectives ul {
  margin: 0;
  padding-left: 20px;
  line-height: 1.6;
}

.tb-diagram-card {
  background: #fafbfd;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin: 20px 0;
}

.tb-diagram-title {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--navy);
  margin-bottom: 6px;
}

.tb-branches-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.tb-branch {
  background: #fff;
  border: 1px solid var(--border);
  border-top: 4px solid var(--navy);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}

.tb-branch:nth-child(2) {
  border-top-color: var(--red);
}

.tb-branch-icon {
  font-size: 1.7rem;
  margin-bottom: 4px;
}

.tb-branch-name {
  font-weight: 700;
  color: var(--navy);
  font-size: 1rem;
}

.tb-branch-sub {
  font-size: 0.85rem;
  color: #5b657a;
  margin-bottom: 8px;
}

.tb-branch-power {
  display: inline-block;
  background: #e8eef8;
  color: var(--navy);
  font-weight: 600;
  font-size: 0.82rem;
  padding: 4px 10px;
  border-radius: 99px;
  margin-bottom: 10px;
}

.tb-branch-parts {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.84rem;
  color: #334155;
  border-top: 1px dashed var(--border);
  padding-top: 8px;
}

.tb-two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin: 20px 0;
}

.tb-info-box {
  border-radius: 10px;
  padding: 16px 18px;
  border: 1px solid var(--border);
}

.tb-info-box.federal {
  background: #f4f7fc;
  border-top: 4px solid var(--navy);
}

.tb-info-box.state {
  background: #fdf6f6;
  border-top: 4px solid var(--red);
}

.tb-info-box h4 {
  margin: 0 0 10px 0;
  color: var(--navy);
}

.tb-info-box ul {
  margin: 0;
  padding-left: 18px;
  line-height: 1.6;
}

.tb-callout-note {
  margin-top: 12px;
  padding: 10px 12px;
  background: #fff;
  border-left: 3px solid var(--red);
  border-radius: 6px;
  font-size: 0.86rem;
}

.tb-states-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tb-state-pill {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 0.84rem;
  font-weight: 600;
}

.tb-state-pill small {
  display: block;
  font-weight: 400;
  color: #5b657a;
  font-size: 0.75rem;
}

.tb-state-pill.highlight {
  background: #e3f5e8;
  border-color: #86cf9b;
  color: #14532d;
}

.tb-reading-body {
  margin-top: 22px;
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

.tb-section-heading {
  color: var(--navy);
  font-size: 1.15rem;
  letter-spacing: 0.03em;
  border-bottom: 2px solid #e8eef8;
  padding-bottom: 6px;
  margin: 26px 0 12px 0;
}

.tb-sub-heading {
  color: var(--red);
  font-size: 1rem;
  margin: 18px 0 8px 0;
}

.tb-paragraph {
  line-height: 1.72;
  font-size: 1.01rem;
  color: #1e293b;
  margin: 0 0 14px 0;
}

.tb-list {
  background: #f8fafc;
  border-radius: 8px;
  padding: 14px 18px 14px 34px;
  margin: 12px 0 16px 0;
  line-height: 1.65;
}

.tb-term {
  background: #fef3c7;
  color: #78350f;
  padding: 1px 5px;
  border-radius: 4px;
  font-weight: 600;
}

.narrator-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
  background: #f8fafc;
}

.narrator-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.narrator-inline-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--navy);
}

.narrator-inline-label select {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: #1d2433;
  font-size: 0.88rem;
}