:root {
  color-scheme: light;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --text: #17212b;
  --muted: #66727f;
  --border: #dce2e7;
  --border-strong: #c7d0d8;
  --primary: #176b4d;
  --primary-hover: #10583e;
  --primary-soft: #e5f2ec;
  --danger: #b5413b;
  --danger-soft: #fae9e7;
  --warning: #8a5a13;
  --shadow: 0 10px 28px rgba(28, 39, 49, 0.08);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

[hidden] {
  display: none !important;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(100%, 420px);
  padding: 36px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 22px;
  font-weight: 750;
}

.brand-mark.small {
  width: 30px;
  height: 30px;
  font-size: 16px;
}

.login-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.language-toggle {
  min-width: 50px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: #43515d;
  font-size: 13px;
  font-weight: 700;
}

.language-toggle:hover {
  background: var(--surface-soft);
}

.language-toggle.compact {
  min-width: 42px;
  height: 30px;
  padding: 0 8px;
}

.login-panel h1 {
  margin: 24px 0 8px;
  font-size: 26px;
  line-height: 1.3;
  letter-spacing: 0;
}

.login-subtitle {
  margin: 0 0 28px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form label,
.date-filter label,
.typing-label {
  color: #394652;
  font-size: 14px;
  font-weight: 650;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

input {
  height: 44px;
  padding: 0 12px;
}

textarea {
  padding: 14px;
}

input:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(23, 107, 77, 0.13);
}

.form-error {
  min-height: 20px;
  margin: 2px 0 0;
  color: var(--danger);
  font-size: 14px;
}

.button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 5px;
  font-weight: 650;
  letter-spacing: 0;
}

.button.primary {
  background: var(--primary);
  color: #fff;
}

.button.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.button.secondary {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.button.secondary:hover:not(:disabled) {
  background: var(--surface-soft);
}

.button.text {
  min-height: 34px;
  padding: 0 6px;
  background: transparent;
  color: var(--muted);
}

.button.wide {
  width: 100%;
  margin-top: 2px;
}

.demo-accounts {
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.demo-accounts p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.demo-accounts button {
  display: block;
  padding: 4px 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 13px;
}

.topbar {
  height: 62px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.topbar-inner {
  display: flex;
  width: min(1180px, calc(100% - 40px));
  height: 100%;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
}

.brand-inline,
.account-area {
  display: flex;
  align-items: center;
}

.brand-inline {
  gap: 10px;
  font-weight: 750;
}

.account-area {
  gap: 10px;
  color: #3c4853;
  font-size: 14px;
}

.role-badge,
.completion-badge,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef1f4;
  color: #4f5c68;
  font-size: 12px;
  font-weight: 700;
}

.workspace {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 36px 0 56px;
}

.page-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

.page-heading h1 {
  margin: 3px 0 0;
  font-size: 27px;
  line-height: 1.25;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.completion-badge.complete,
.status-badge.complete {
  background: var(--primary-soft);
  color: var(--primary);
}

.progress-section,
.practice-section,
.table-section {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

.progress-section {
  margin-bottom: 20px;
  padding: 22px 24px;
}

.progress-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  font-size: 14px;
}

.progress-heading span {
  color: var(--muted);
}

.progress-heading strong span {
  color: inherit;
}

.progress-track {
  height: 9px;
  margin: 12px 0 20px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7ecef;
}

.progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 240ms ease;
}

.metric-grid,
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.metric {
  display: grid;
  gap: 6px;
  padding: 0 18px;
  border-right: 1px solid var(--border);
}

.metric:first-child {
  padding-left: 0;
}

.metric:last-child {
  border-right: 0;
}

.metric span,
.summary-item span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  font-size: 20px;
}

.practice-section {
  padding: 26px;
}

.passage-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.exercise-progress {
  margin-bottom: 18px;
}

.exercise-progress-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--muted);
  font-size: 13px;
}

.exercise-progress-heading strong {
  color: var(--text);
}

.progress-track.compact {
  height: 6px;
  margin: 8px 0 0;
}

.passage-heading h2,
.table-title h2 {
  margin: 4px 0 0;
  font-size: 19px;
  line-height: 1.35;
  letter-spacing: 0;
}

.word-count {
  flex: none;
  color: var(--muted);
  font-size: 13px;
}

.passage-text {
  min-height: 170px;
  max-height: 340px;
  overflow-y: auto;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-soft);
  color: #46515c;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 18px;
  line-height: 1.85;
  white-space: pre-wrap;
}

.passage-text span.correct {
  color: var(--primary);
  background: var(--primary-soft);
}

.passage-text span.incorrect {
  color: var(--danger);
  background: var(--danger-soft);
  text-decoration: underline;
  text-decoration-color: var(--danger);
}

.passage-text span.current {
  border-left: 2px solid var(--primary);
}

.typing-label {
  display: block;
  margin: 22px 0 8px;
}

.typing-input {
  height: 220px;
  min-height: 160px;
  max-height: 340px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 16px;
  line-height: 1.65;
}

.practice-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 16px;
}

.session-stats,
.button-group {
  display: flex;
  align-items: center;
  gap: 16px;
}

.session-stats {
  color: var(--muted);
  font-size: 13px;
}

.session-stats strong {
  color: var(--text);
}

.last-result {
  margin-top: 18px;
  padding: 12px 14px;
  border-left: 3px solid var(--primary);
  background: var(--primary-soft);
  color: #285443;
  font-size: 14px;
}

.admin-heading {
  align-items: flex-end;
}

.date-filter {
  display: flex;
  align-items: center;
  gap: 10px;
}

.date-filter input {
  width: 150px;
}

.summary-grid {
  gap: 1px;
  margin-bottom: 20px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--border);
}

.summary-item {
  display: grid;
  gap: 8px;
  min-height: 104px;
  padding: 20px;
  align-content: center;
  background: var(--surface);
}

.summary-item strong {
  font-size: 25px;
}

.table-section {
  padding: 0;
  overflow: hidden;
}

.table-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
}

.table-title h2 {
  margin: 0;
}

.table-title span {
  color: var(--muted);
  font-size: 13px;
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 850px;
  border-collapse: collapse;
  text-align: left;
}

th,
td {
  padding: 15px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

th {
  background: var(--surface-soft);
  color: #53606c;
  font-size: 12px;
  font-weight: 750;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.user-cell {
  display: grid;
  gap: 3px;
}

.user-cell span {
  color: var(--muted);
  font-size: 12px;
}

.error-value {
  color: var(--danger);
}

.empty-state {
  margin: 0;
  padding: 50px 20px;
  text-align: center;
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(380px, calc(100vw - 44px));
  padding: 12px 16px;
  border-radius: 5px;
  background: #202b34;
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 150ms ease, transform 150ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 760px) {
  .workspace,
  .topbar-inner {
    width: min(100% - 24px, 1180px);
  }

  .workspace {
    padding-top: 24px;
  }

  .account-area #accountName,
  .role-badge {
    display: none;
  }

  .page-heading,
  .practice-footer,
  .admin-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid,
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric {
    padding: 12px 0;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .metric:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  .practice-section,
  .progress-section {
    padding: 20px;
  }

  .passage-text {
    padding: 16px;
    font-size: 17px;
  }

  .practice-footer,
  .session-stats {
    gap: 12px;
  }

  .button-group {
    width: 100%;
  }

  .button-group .button {
    flex: 1;
  }

  .date-filter {
    display: grid;
    grid-template-columns: 1fr auto;
  }

  .date-filter label {
    grid-column: 1 / -1;
  }

  .date-filter input {
    width: 100%;
  }
}

@media (max-width: 460px) {
  .login-panel {
    padding: 28px 22px;
  }

  .brand-inline > span:last-child {
    display: none;
  }

  .page-heading h1 {
    font-size: 24px;
  }

  .progress-heading,
  .passage-heading,
  .exercise-progress-heading,
  .button-group,
  .session-stats {
    align-items: stretch;
    flex-direction: column;
  }

  .word-count {
    align-self: flex-start;
  }
}
