:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-alt: #f4f4f6;
  --ink: #141416;
  --muted: #71717a;
  --rose: #e6004c;
  --rose-dark: #c40040;
  --indigo: #4f46e5;
  --amber: #d97706;
  --emerald: #10b981;
  --purple: #9333ea;
  --sky: #0ea5e9;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --err: #be123c;
  --err-bg: #ffe4e6;
  --info-bg: #eff6ff;
  --border: #e5e7eb;
  --radius: 20px;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.container {
  width: min(1080px, 92%);
  margin-inline: auto;
}

/* Color Helpers */
.text-rose { color: var(--rose); }
.text-amber { color: var(--amber); }
.text-emerald { color: var(--emerald); }
.text-indigo { color: var(--indigo); }
.text-purple { color: var(--purple); }
.text-sky { color: var(--sky); }
.text-ink { color: var(--ink); }
.text-muted { color: var(--muted); }

.ui-icon { width: 18px; height: 18px; flex-shrink: 0; }
.ui-icon-lg { width: 26px; height: 26px; }
.ui-icon-watermark { width: 88px; height: 88px; }

/* =========================================================
   TOPBAR (Screenshot 2)
   ========================================================= */
.topbar {
  background: transparent;
  padding-block: 1rem;
}

.topbar-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.student-badge-link {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: inherit;
}

.avatar-circle {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 0.82rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.student-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.student-meta small {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.student-meta strong {
  font-size: 0.85rem;
  font-weight: 700;
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.85rem;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  text-decoration: none;
  color: #4b5563;
  font-size: 0.84rem;
  font-weight: 600;
}

.topbar-link:hover,
.topbar-link.is-active {
  color: var(--ink);
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.38rem;
  padding: 0.42rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
}

.pill-btn:hover {
  border-color: #cbd5e1;
}

.inline-form {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.mini-select {
  padding: 0.35rem 0.55rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.82rem;
}

/* Main & Footer */
.main-content {
  flex: 1;
  padding-block: 0.75rem 3rem;
}

.site-footer {
  padding-block: 1.25rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

/* =========================================================
   AUTH CARD (Screenshot 1)
   ========================================================= */
.auth-body {
  background: #fafafa;
}

.auth-main {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.auth-card {
  width: min(430px, 100%);
  background: var(--surface);
  border-radius: 28px;
  padding: 2.4rem 2.1rem;
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  border: 1px solid #f1f2f6;
  text-align: center;
}

.auth-logo {
  margin-bottom: 1rem;
}

.auth-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.02em;
  text-transform: uppercase;
}

.auth-subtitle {
  margin: 0.35rem 0 1.65rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: left;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 0.38rem;
}

.auth-field label {
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  color: #9ca3af;
  text-transform: uppercase;
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 0.9rem;
  width: 17px;
  height: 17px;
  color: #9ca3af;
  pointer-events: none;
}

.input-with-icon input {
  width: 100%;
  padding: 0.85rem 1rem 0.85rem 2.65rem;
  border-radius: 14px;
  border: 1px solid #eceef2;
  background: #f7f7f9;
  color: var(--ink);
  font-size: 0.94rem;
}

.input-with-icon input:focus {
  outline: none;
  border-color: var(--ink);
  background: #fff;
}

.auth-links {
  margin-top: 1.4rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  align-items: center;
}

.auth-register-link {
  color: var(--rose);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-decoration: none;
  text-transform: uppercase;
}

.auth-muted-link {
  color: #9ca3af;
  font-size: 0.82rem;
  font-weight: 600;
  text-decoration: none;
}

/* =========================================================
   HOME HERO & MENU GRID (Screenshots 2 & 3)
   ========================================================= */
.dojo-hero {
  text-align: center;
  margin-bottom: 2rem;
}

.dojo-hero-logo {
  margin-bottom: 0.55rem;
}

.dojo-brand-title {
  margin: 0;
  font-size: clamp(2.1rem, 4vw, 2.85rem);
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.03em;
  text-transform: uppercase;
}

.dojo-brand-sub {
  margin: 0.15rem 0 0;
  color: var(--rose);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.25rem;
}

@media (max-width: 860px) {
  .menu-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .menu-grid { grid-template-columns: 1fr; }
}

.menu-card {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1.5px solid #eef0f4;
  border-radius: 22px;
  padding: 1.45rem 1.5rem;
  min-height: 152px;
  text-decoration: none;
  color: var(--ink);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.menu-card:hover {
  transform: translateY(-2px);
  border-color: var(--rose);
  box-shadow: 0 14px 32px rgba(230, 0, 76, 0.1);
}

.menu-card.is-dark {
  background: var(--ink);
  border-color: var(--ink);
  color: #ffffff;
}

.menu-card.is-dark p {
  color: #a1a1aa;
}

.menu-card-watermark {
  position: absolute;
  right: 1rem;
  top: 1rem;
  color: #e5e7eb;
  opacity: 0.55;
  pointer-events: none;
}

.menu-card.is-dark .menu-card-watermark {
  color: #ffffff;
  opacity: 0.08;
}

.menu-card-body h2,
.menu-card-body h3 {
  margin: 0.65rem 0 0.2rem;
  font-size: 1.15rem;
  font-weight: 900;
  font-style: italic;
  letter-spacing: -0.01em;
}

.menu-card-body p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

/* Subpage Header */
.subpage-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.back-link:hover {
  color: var(--ink);
}

.page-heading-italic {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
}

.pill-tag {
  display: inline-flex;
  align-items: center;
  padding: 0.35rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--ink);
}

/* =========================================================
   SETTINGS CARD (Screenshot 4)
   ========================================================= */
.settings-card {
  width: min(440px, 100%);
  margin: 1.5rem auto;
  background: var(--surface);
  border: 1px solid #eef0f4;
  border-radius: 26px;
  padding: 2rem;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.08);
}

.settings-card-title {
  margin: 0 0 1.4rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.25rem;
  font-weight: 800;
}

.clean-select {
  width: 100%;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #f8f8fa;
  font-size: 0.92rem;
  font-weight: 600;
}

.digit-pill-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(56px, 1fr));
  gap: 0.55rem;
}

.digit-pill {
  display: grid;
  place-items: center;
  padding: 0.65rem 0.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.digit-radio:checked + .digit-pill {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* =========================================================
   BUTTONS, PANELS & TABLES
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1.15rem;
  border-radius: 14px;
  border: 1px solid transparent;
  font-size: 0.88rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  cursor: pointer;
  text-decoration: none;
}

.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover { background: #27272a; }
.btn-rose,
.btn-primary { background: var(--rose); color: #fff; }
.btn-rose:hover,
.btn-primary:hover { background: var(--rose-dark); }
.btn-secondary,
.btn-outline { background: var(--surface); color: var(--muted); border-color: var(--border); }
.btn-outline:hover,
.btn-secondary:hover { color: var(--ink); border-color: #cbd5e1; }
.btn-block { width: 100%; }
.btn-lg { padding: 0.88rem 1.25rem; font-size: 0.92rem; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.78rem; border-radius: 10px; }

.panel {
  background: var(--surface);
  border: 1px solid #eef0f4;
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.35rem;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.panel-header h1,
.panel-header h2 { margin: 0; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 1.1rem;
}

.card {
  background: var(--surface);
  border: 1px solid #eef0f4;
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.card h3 { margin: 0; }
.card p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.9rem;
}

.settings-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 0.85rem;
}

.field { display: flex; flex-direction: column; gap: 0.28rem; }
.field label { font-size: 0.74rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.field input,
.field select,
.field textarea {
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f9fafb;
  font-family: inherit;
  font-size: 0.92rem;
}

.stat-row { display: flex; flex-wrap: wrap; gap: 0.55rem; }
.stat-pill {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 700;
}

.feedback {
  padding: 0.95rem 1.2rem;
  border-radius: 14px;
  margin-bottom: 1.2rem;
  border: 1px solid transparent;
}
.feedback.is-ok { background: var(--ok-bg); color: var(--ok); border-color: #86efac; }
.feedback.is-err { background: var(--err-bg); color: var(--err); border-color: #fda4af; }
.feedback.is-info { background: var(--info-bg); color: #1d4ed8; border-color: #bfdbfe; }
.feedback h3, .feedback p { margin: 0.15rem 0; }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table th, .data-table td { padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { font-size: 0.74rem; text-transform: uppercase; color: var(--muted); }

.badge { display: inline-block; padding: 0.18rem 0.58rem; border-radius: 999px; font-size: 0.76rem; font-weight: 700; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-err { background: var(--err-bg); color: var(--err); }
.badge-belt-None { background: #f3f4f6; color: #6b7280; }
.badge-belt-White { background: #fff; color: #111; border: 1px solid #d1d5db; }
.badge-belt-Yellow { background: #fef08a; color: #713f12; }
.badge-belt-Green { background: #bbf7d0; color: #14532d; }
.badge-belt-Red { background: #fecaca; color: #7f1d1d; }
.badge-belt-Black { background: #141416; color: #fff; }

/* =========================================================
   SOROBAN (Screenshot 5 & Soroban.tsx)
   ========================================================= */
.exercise-stage-wrap {
  padding-block: 1rem;
  text-align: center;
}

.exercise-prompt-italic {
  margin: 0 auto 1.75rem;
  max-width: 680px;
  font-size: clamp(1.25rem, 2.5vw, 1.65rem);
  font-weight: 900;
  font-style: italic;
  text-transform: uppercase;
  line-height: 1.25;
}

.big-prompt {
  font-size: clamp(2.8rem, 7vw, 4.2rem);
  font-weight: 900;
  margin: 0.75rem 0 1.25rem;
  font-variant-numeric: tabular-nums;
}

.soroban-wrap { margin: 0.4rem auto; text-align: center; }
.soroban-caption { font-size: 0.86rem; font-weight: 700; color: var(--muted); margin-bottom: 0.4rem; }

.soroban {
  display: inline-flex;
  gap: 0.55rem;
  padding: 0.9rem;
  background: #fafaf9;
  border: 2px solid #d6d3d1;
  border-radius: 16px;
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.05);
  user-select: none;
}

.soroban-rod {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.55rem 0.5rem;
  background: rgba(245, 245, 244, 0.65);
  border: 1px solid #e7e5e4;
  border-radius: 10px;
  min-width: 56px;
}

.deck-upper {
  margin-bottom: 0.45rem;
}

.reckoning-bar {
  width: 44px;
  height: 4px;
  border-radius: 999px;
  background: #292524;
  margin-bottom: 0.5rem;
  display: grid;
  place-items: center;
}

.unit-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
}

.deck-lower,
.lower-beads {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.28rem;
}

.bead {
  display: block;
  width: 36px;
  height: 18px;
  border-radius: 999px;
  background: #e7e5e4;
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  transition: background-color 0.16s ease, transform 0.16s ease;
}

.soroban-interactive .bead { cursor: pointer; }

.upper-bead.is-active,
.upper-check:checked ~ .upper-bead {
  background: #d97706;
}

.lower-bead.is-active,
.l-in-1:checked ~ .lower-beads .b1,
.l-in-2:checked ~ .lower-beads .b1,
.l-in-2:checked ~ .lower-beads .b2,
.l-in-3:checked ~ .lower-beads .b1,
.l-in-3:checked ~ .lower-beads .b2,
.l-in-3:checked ~ .lower-beads .b3,
.l-in-4:checked ~ .lower-beads .b1,
.l-in-4:checked ~ .lower-beads .b2,
.l-in-4:checked ~ .lower-beads .b3,
.l-in-4:checked ~ .lower-beads .b4 {
  background: #f43f5e;
}

.rod-clear {
  margin-top: 0.35rem;
  width: 22px;
  height: 20px;
  border-radius: 6px;
  background: #f4f4f5;
  border: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 800;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.l-in-0:checked ~ .rod-clear { opacity: 0.4; }

/* Choice Cards (Screenshot 5) */
.choice-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(195px, 1fr));
  gap: 1.25rem;
  max-width: 880px;
  margin: 1rem auto 0;
}

.choice-card {
  background: var(--surface);
  border: 2px solid #eef0f4;
  border-radius: 22px;
  padding: 1.25rem 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.choice-card:hover,
.choice-card:focus-visible {
  border-color: var(--indigo);
  transform: translateY(-2px);
  outline: none;
}

.choice-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #f4f4f5;
  color: #71717a;
  font-size: 0.8rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.answer-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.answer-input {
  width: 190px;
  padding: 0.7rem 1rem;
  font-size: 1.25rem;
  font-weight: 800;
  text-align: center;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: #fff;
}

/* Anzan Stage */
.anzan-stage {
  background: var(--ink);
  color: #fff;
  border-radius: 22px;
  height: 185px;
  max-width: 600px;
  margin: 1rem auto;
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
}

.anzan-term {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(2.8rem, 7vw, 4.4rem);
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  animation: anzan-flash var(--dur) ease-in-out var(--delay) 1 both;
}

.anzan-term.is-negative { color: #fb7185; }

.anzan-ready {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  font-weight: 800;
  color: #e4e4e7;
  opacity: 0;
  animation: anzan-ready-in 0.35s ease var(--total-delay) 1 forwards;
}

@keyframes anzan-flash {
  0% { opacity: 0; transform: scale(0.9); }
  12% { opacity: 1; transform: scale(1); }
  84% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.05); }
}

@keyframes anzan-ready-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.projector-screen {
  background: var(--ink);
  color: #fff;
  border-radius: 24px;
  padding: 2.5rem;
  text-align: center;
}
