:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --ok: #047857;
  --warn: #b45309;
  --danger: #b91c1c;
  --line: #d9e2f2;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: radial-gradient(circle at top left, #dbeafe 0, transparent 34rem), var(--bg);
  color: var(--ink);
}
button, input, select, textarea { font: inherit; }
button {
  border: 0;
  border-radius: 0.75rem;
  padding: 0.7rem 1rem;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-weight: 700;
  transition: transform .12s ease, background .12s ease, opacity .12s ease;
}
button:hover { background: var(--brand-dark); transform: translateY(-1px); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
button.secondary { background: #edf2ff; color: #1e40af; }
button.secondary:hover { background: #dbeafe; }
button.ghost { background: transparent; color: var(--brand); }
button.danger { background: #fee2e2; color: var(--danger); }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: .75rem;
  padding: .7rem .8rem;
  background: white;
  color: var(--ink);
}
select[multiple] { min-height: 8rem; }
textarea { min-height: 7rem; resize: vertical; }
label { display: grid; gap: .35rem; color: #344054; font-weight: 650; }
small { color: var(--muted); }

.app-shell { min-height: 100vh; display: grid; grid-template-rows: auto 1fr; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem clamp(1rem, 3vw, 2rem);
  background: rgba(255,255,255,.78);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(217,226,242,.75);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: .75rem; font-weight: 900; font-size: 1.1rem; }
.brand-mark {
  width: 2.35rem; height: 2.35rem; border-radius: .85rem;
  display: grid; place-items: center; color: white; background: linear-gradient(135deg, #2563eb, #7c3aed);
  box-shadow: 0 8px 20px rgba(37,99,235,.25);
}
.user-chip { display: flex; align-items: center; gap: .7rem; color: var(--muted); }
.layout { display: grid; grid-template-columns: 16rem minmax(0,1fr); gap: 1.2rem; padding: 1.2rem clamp(1rem,3vw,2rem) 2rem; }
.sidebar {
  align-self: start;
  position: sticky;
  top: 5rem;
  background: rgba(255,255,255,.9);
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  padding: .75rem;
  box-shadow: var(--shadow);
}
.nav-link {
  display: flex;
  gap: .65rem;
  align-items: center;
  width: 100%;
  padding: .8rem .9rem;
  border-radius: .85rem;
  color: #344054;
  text-decoration: none;
  font-weight: 750;
}
.nav-link:hover, .nav-link.active { background: #eff6ff; color: #1d4ed8; }
.main { min-width: 0; }

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 2rem; }
.auth-card {
  width: min(100%, 28rem);
  background: rgba(255,255,255,.92);
  border: 1px solid var(--line);
  border-radius: 1.4rem;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: .2rem 0 .5rem; font-size: 1.75rem; }
.stack { display: grid; gap: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.six { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.card {
  background: rgba(255,255,255,.92);
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.card h2, .card h3 { margin-top: 0; }
.kpi {
  display: grid;
  gap: .3rem;
  padding: 1rem;
  border-radius: 1rem;
  background: linear-gradient(135deg, #eff6ff, #f5f3ff);
  border: 1px solid #dbeafe;
}
.kpi strong { font-size: 1.7rem; }
.toolbar { display: flex; flex-wrap: wrap; gap: .7rem; align-items: end; }
.inline-toggle { display: inline-flex; grid-template-columns: none; align-items: center; gap: .45rem; width: auto; font-weight: 700; color: var(--muted); }
.inline-toggle input { width: auto; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 1rem; }
table { width: 100%; border-collapse: collapse; background: white; }
th, td { padding: .75rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #f8fafc; color: #475467; font-size: .9rem; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .28rem .55rem; border-radius: 999px; background: #eef2ff; color: #3730a3; font-size: .8rem; font-weight: 800; }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.danger { background: #fee2e2; color: var(--danger); }
.notice { padding: .8rem 1rem; border-radius: .9rem; background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.notice.error { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.notice.ok { background: #ecfdf5; color: var(--ok); border-color: #bbf7d0; }
.flash-card {
  min-height: 16rem;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px dashed #93c5fd;
  border-radius: 1.2rem;
  background: linear-gradient(135deg, #eff6ff, #fff);
  padding: 2rem;
}
.flash-card .front { font-size: clamp(2rem, 6vw, 4rem); font-weight: 900; }
.flash-card .back { margin-top: 1rem; color: var(--muted); font-size: 1.25rem; }
.word-list { display: flex; flex-wrap: wrap; gap: .5rem; }
.word-pill { padding: .45rem .65rem; background: #f8fafc; border: 1px solid var(--line); border-radius: 999px; }
.dictation-prep-summary { margin-top: .25rem; }
.dictation-stat-kpi { cursor: pointer; text-align: left; transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease; }
.dictation-stat-kpi:hover, .dictation-stat-kpi:focus { border-color: var(--brand); box-shadow: 0 12px 30px rgba(37,99,235,.15); transform: translateY(-1px); outline: none; }
.dictation-stat-action { color: var(--brand); font-weight: 800; }
.dictation-history-card { border-top: 1px solid var(--line); padding-top: 1rem; }
.dictation-history-detail { display: grid; gap: .75rem; }
.dictation-history-row.incorrect .history-word-text,
.dictation-history-row.incorrect .history-word-translation { color: var(--danger); }
.dictation-history-list { display: grid; overflow: hidden; border: 1px solid var(--line); border-radius: 1rem; background: white; }
.dictation-history-list-head,
.dictation-history-row { display: grid; grid-template-columns: 3.2rem minmax(0, 1fr) minmax(9rem, 11rem); gap: .75rem; align-items: center; padding: .75rem; border-bottom: 1px solid var(--line); }
.dictation-history-list-head { background: #f8fafc; color: #475467; font-size: .9rem; font-weight: 850; }
.dictation-history-row:last-child { border-bottom: 0; }
.history-word-index { color: #475467; font-weight: 850; }
.history-word-main { min-width: 0; }
.history-word-line { display: flex; align-items: center; gap: .35rem; min-width: 0; }
.history-word-text { overflow-wrap: anywhere; font-size: 1.02rem; }
.history-word-translation { margin-top: .35rem; color: var(--muted); line-height: 1.45; overflow-wrap: anywhere; }
.history-judgment-controls { display: grid; gap: .45rem; }
.dictation-history-empty { padding: 1rem; color: var(--muted); }
.tri-judge { --tri-color: #64748b; display: grid; grid-template-columns: auto 1fr; align-items: center; gap: .18rem .45rem; min-width: 0; padding: .38rem .48rem; border: 1px solid #dbeafe; border-radius: .85rem; background: #f8fafc; color: #344054; font-size: .78rem; font-weight: 800; }
.tri-judge-label { white-space: nowrap; }
.tri-judge-status { justify-self: end; color: var(--tri-color); }
.tri-judge input[type="range"] { grid-column: 1 / -1; width: 100%; height: .55rem; margin: .12rem 0 0; padding: 0; border: 0; border-radius: 999px; background: transparent; cursor: pointer; accent-color: var(--tri-color); -webkit-appearance: none; appearance: none; }
.tri-judge input[type="range"]::-webkit-slider-runnable-track { height: .42rem; border-radius: 999px; background: linear-gradient(90deg, #bbf7d0 0 32%, #e2e8f0 32% 68%, #fecaca 68% 100%); }
.tri-judge input[type="range"]::-webkit-slider-thumb { width: 1.05rem; height: 1.05rem; margin-top: -.32rem; border: 2px solid white; border-radius: 999px; background: var(--tri-color); box-shadow: 0 2px 7px rgba(15,23,42,.25); -webkit-appearance: none; appearance: none; }
.tri-judge input[type="range"]::-moz-range-track { height: .42rem; border-radius: 999px; background: linear-gradient(90deg, #bbf7d0 0 32%, #e2e8f0 32% 68%, #fecaca 68% 100%); }
.tri-judge input[type="range"]::-moz-range-thumb { width: 1.05rem; height: 1.05rem; border: 2px solid white; border-radius: 999px; background: var(--tri-color); box-shadow: 0 2px 7px rgba(15,23,42,.25); }
.tri-judge-hints { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: .25rem; color: var(--muted); font-size: .65rem; font-weight: 750; }
.tri-judge.is-correct { --tri-color: var(--ok); border-color: #bbf7d0; background: #f0fdf4; }
.tri-judge.is-incorrect { --tri-color: var(--danger); border-color: #fecaca; background: #fff7f7; }
.tri-judge.is-pending { --tri-color: #64748b; }
.tri-judge-bulk { width: 10.5rem; max-width: 100%; background: #f8fafc; }
.speaker-button { margin-left: .45rem; padding: .15rem .4rem; border-radius: 999px; font-size: .95rem; vertical-align: middle; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(15, 23, 42, .42);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.modal-card {
  width: min(100%, 62rem);
  max-height: min(90vh, 54rem);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  background: rgba(255,255,255,.98);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  box-shadow: 0 28px 70px rgba(15, 23, 42, .22);
}
.modal-header { display: flex; align-items: start; justify-content: space-between; gap: 1rem; padding: 1rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal-header h3 { margin: 0 0 .25rem; }
.modal-body { min-height: 0; overflow: auto; padding: 1rem 1.1rem 1.1rem; }
.dictation-modal-player .toolbar { align-items: center; }
.inline-field { display: inline-grid; gap: .25rem; width: 10rem; font-size: .9rem; }
.dictation-modal-word { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .35rem; text-align: left; }
.progress-bar-container { height: .65rem; overflow: hidden; border-radius: 999px; background: #e5e7eb; }
.progress-bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand), #7c3aed); transition: width .2s ease; }
.activity-calendar-toolbar { align-items: center; }
.activity-calendar-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(20rem, 27rem); gap: 1rem; align-items: start; }
.activity-month-summary .kpi strong { font-size: 1.55rem; }
.activity-calendar-grid { display: grid; gap: .7rem; }
.activity-weekdays, .activity-days-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .55rem; }
.activity-weekdays span { text-align: center; color: var(--muted); font-size: .82rem; font-weight: 850; }
.activity-day {
  min-height: 7.7rem;
  display: grid;
  align-content: start;
  gap: .35rem;
  width: 100%;
  padding: .7rem;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(255,255,255,.9);
  color: var(--ink);
  text-align: left;
  box-shadow: none;
}
.activity-day:hover { background: #eff6ff; border-color: #93c5fd; color: var(--ink); }
.activity-day.empty { min-height: 0; padding: 0; border: 0; background: transparent; pointer-events: none; }
.activity-day.active { border-color: #bfdbfe; background: linear-gradient(135deg, #eff6ff, #ffffff); }
.activity-day.today { box-shadow: inset 0 0 0 2px rgba(37,99,235,.22); }
.activity-day.selected { border-color: var(--brand); background: linear-gradient(135deg, #dbeafe, #f5f3ff); }
.activity-day-number { width: 1.85rem; height: 1.85rem; display: grid; place-items: center; border-radius: .65rem; background: #f8fafc; font-weight: 900; }
.activity-day.today .activity-day-number { background: var(--brand); color: #fff; }
.activity-day-total { color: #344054; font-size: .82rem; font-weight: 850; }
.activity-day-total.muted { color: var(--muted); font-weight: 700; }
.activity-day-chips { display: flex; flex-wrap: wrap; gap: .25rem; }
.activity-day-chips span { display: inline-flex; padding: .18rem .4rem; border-radius: 999px; background: #eef2ff; color: #3730a3; font-size: .72rem; font-weight: 850; }
.activity-day small { font-size: .72rem; }
.activity-day-details { position: sticky; top: 5rem; }
.activity-day-summary .kpi { padding: .8rem; }
.activity-day-summary .kpi strong { font-size: 1.35rem; }
.activity-list { display: grid; gap: .75rem; }
.activity-item { display: grid; grid-template-columns: 2.4rem minmax(0, 1fr); gap: .75rem; padding: .8rem; border: 1px solid var(--line); border-radius: 1rem; background: #fff; }
.activity-item-icon { width: 2.2rem; height: 2.2rem; display: grid; place-items: center; border-radius: .85rem; background: #eff6ff; font-size: 1.2rem; }
.activity-item-body { display: grid; gap: .28rem; min-width: 0; }
.activity-item-head { align-items: center; gap: .45rem; }
.activity-samples { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .25rem; }
.activity-samples span { display: inline-flex; gap: .35rem; align-items: center; padding: .3rem .5rem; border: 1px solid #dbeafe; border-radius: 999px; background: #f8fafc; max-width: 100%; overflow-wrap: anywhere; }
.activity-samples small { color: var(--brand); font-weight: 850; }
.hidden { display: none !important; }
.loading { opacity: .7; pointer-events: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; display: flex; overflow-x: auto; }
  .nav-link { white-space: nowrap; }
  .grid.two, .grid.three, .grid.four, .grid.six { grid-template-columns: 1fr; }
  .topbar { align-items: start; flex-direction: column; }
  .activity-calendar-layout { grid-template-columns: 1fr; }
  .activity-day-details { position: static; }
  .activity-weekdays, .activity-days-grid { gap: .35rem; }
  .activity-day { min-height: 6.4rem; padding: .55rem; }
  .dictation-history-list-head { display: none; }
  .dictation-history-row { grid-template-columns: 2.4rem minmax(0, 1fr); align-items: start; }
  .history-judgment-controls { grid-column: 2; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tri-judge-bulk { width: min(100%, 11.5rem); }
}
