:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #172033;
  --muted: #607086;
  --line: #d9e0ea;
  --primary: #126b61;
  --primary-dark: #0c4d45;
  --accent: #b23b5a;
  --warn: #9b5b00;
  --ok: #1f7a4d;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

a {
  color: inherit;
  text-decoration: none;
}

button,
input {
  font: inherit;
}

button,
.module-open-link {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  min-height: 42px;
  padding: 0 16px;
  font-weight: 650;
}

button:hover,
.module-open-link:hover {
  background: var(--primary-dark);
}

.module-open-link {
  display: grid;
  place-items: center;
  text-decoration: none;
}

button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
}

label {
  display: block;
  margin: 16px 0 6px;
  color: var(--muted);
  font-size: .92rem;
  font-weight: 650;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 clamp(16px, 4vw, 48px);
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: grid;
  gap: 1px;
  line-height: 1.05;
  font-weight: 800;
}

.brand small {
  color: var(--muted);
  font-size: .76rem;
  font-weight: 700;
}

.topbar nav a {
  color: var(--muted);
  font-weight: 650;
}

.shell {
  width: min(1100px, calc(100% - 32px));
  margin: 32px auto 56px;
}

.shell.narrow {
  width: min(760px, calc(100% - 32px));
}

.status-panel,
.load-panel,
.admin-login {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(20px, 4vw, 32px);
}

.status-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  align-items: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(2rem, 5vw, 3.25rem);
  line-height: 1.05;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.55rem;
}

h3 {
  margin-bottom: 8px;
  font-size: 1.1rem;
}

p {
  color: var(--muted);
  line-height: 1.55;
}

.code-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fafbfd;
}

.code-box span {
  display: block;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 700;
}

.code-box strong {
  display: block;
  margin: 4px 0 16px;
  font-size: 1.7rem;
}

.code-actions,
.inline-form {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ghost-button,
.code-actions button:nth-child(2) {
  background: #e8edf3;
  color: var(--text);
}

.ghost-button:hover,
.code-actions button:nth-child(2):hover {
  background: #dce4ee;
}

.load-panel {
  margin-top: 16px;
}
.module-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.compact-code {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff;
  color: var(--muted);
  font-weight: 700;
}

.compact-code span {
  font-size: .82rem;
}

.compact-code strong {
  color: var(--text);
  font-size: 1rem;
}

.inline-form input {
  flex: 1 1 220px;
}

.section-heading {
  margin: 34px 0 16px;
}

.admin-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr));
  gap: 16px;
}

.module-card,
.admin-row,
.trainer-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.module-card {
  display: flex;
  flex-direction: column;
  min-height: 210px;
}

.module-card p {
  flex: 1;
}

.module-card .module-progress {
  flex: 0 0 auto;
  border-top: 1px solid var(--line);
  margin: 0 0 14px;
  padding-top: 10px;
  color: var(--primary);
  font-weight: 750;
}

.module-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.module-subject {
  border: 1px solid rgba(18, 107, 97, .25);
  border-radius: 999px;
  padding: 3px 8px;
  background: #f2fbf8;
  color: var(--primary);
  font-size: .78rem;
  font-weight: 800;
}

.module-type {
  color: var(--primary);
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.hidden {
  display: none !important;
}

.message {
  min-height: 24px;
  margin: 10px 0 0;
  color: var(--warn);
}

.message.ok {
  color: var(--ok);
}

.trainer-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: start;
  margin: 20px 0 16px;
}

.trainer-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.progress-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--muted);
  background: #fff;
  font-weight: 700;
}

.module-overview-title {
  margin: 0;
  color: var(--muted);
  font-weight: 750;
}

.overview-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.module-intro {
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  padding-bottom: 18px;
}

.module-intro .resource-list {
  margin-top: 14px;
}

.overview-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.overview-stats div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fafbfd;
}

.overview-stats span {
  display: block;
  color: var(--primary);
  font-size: 2rem;
  font-weight: 850;
  line-height: 1;
}

.overview-stats strong {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: .9rem;
}

.overview-actions {
  align-items: center;
  margin-top: 16px;
}

.overview-hint {
  color: var(--muted);
  font-size: .92rem;
  font-weight: 650;
}

.overview-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.status-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.status-list ul {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.status-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.status-list li:last-child {
  border-bottom: 0;
}

.status-list small {
  flex: 0 0 auto;
  color: var(--muted);
}

.term-link {
  min-height: 0;
  padding: 0;
  border-radius: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 800;
  text-align: left;
}

.term-link:hover {
  background: transparent;
  color: var(--primary-dark);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.status-list .empty-status {
  color: var(--muted);
}

.trainer-card {
  min-height: 260px;
}

.term-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 18px;
  margin: 12px 0 18px;
}

.term-display {
  min-width: 0;
  margin: 0;
  font-size: clamp(2rem, 7vw, 4rem);
  line-height: 1;
}

.term-status {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: #fff;
  color: var(--muted);
  font-weight: 750;
}

.definition {
  margin: 0 0 18px;
  color: var(--text);
  font-size: 1.25rem;
}

.example-list {
  margin: 0 0 24px;
  padding-left: 20px;
  color: var(--muted);
}

.term-images {
  margin: 0 0 24px;
}

.term-image-row {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.term-image-row figure {
  flex: 0 0 auto;
  margin: 0;
}

.image-preview {
  display: block;
  width: auto;
  height: 200px;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: #fff;
  overflow: hidden;
}

.image-preview:hover {
  background: #fff;
  border-color: var(--primary);
}

.image-preview img {
  display: block;
  width: auto;
  height: 200px;
  max-width: min(420px, 80vw);
  object-fit: contain;
}

.term-image-row figcaption {
  max-width: min(420px, 80vw);
  margin-top: 6px;
  color: var(--muted);
  font-size: .86rem;
  line-height: 1.35;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 56px 20px 24px;
  background: rgba(23, 32, 51, .78);
}

.image-lightbox.is-visible {
  display: flex;
}

.image-lightbox img {
  max-width: min(1100px, 94vw);
  max-height: 86vh;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 22px 70px rgba(0, 0, 0, .35);
  object-fit: contain;
}

.image-lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 1.8rem;
  line-height: 1;
}

.image-lightbox-close:hover {
  background: #e8edf3;
}

.markdown-body p,
.example-list p {
  margin: 0 0 12px;
  color: inherit;
}

.markdown-body p:last-child,
.example-list p:last-child {
  margin-bottom: 0;
}

.markdown-body ul,
.markdown-body ol,
.example-list ul,
.example-list ol {
  margin: 0 0 14px;
  padding-left: 24px;
}

.markdown-body code,
.example-list code {
  border: 1px solid #d7dee8;
  border-radius: 4px;
  padding: 1px 5px;
  background: #f3f6fa;
  color: #1b2a41;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
  font-size: .92em;
}

.markdown-body pre,
.example-list pre {
  overflow-x: auto;
  border: 1px solid #cfd8e4;
  border-radius: 8px;
  margin: 12px 0 16px;
  padding: 14px;
  background: #101820;
  color: #f5f7fa;
}

.markdown-body pre code,
.example-list pre code {
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font-size: .95rem;
  line-height: 1.5;
}

.markdown-body blockquote,
.example-list blockquote {
  margin: 12px 0;
  border-left: 4px solid var(--line);
  padding: 4px 0 4px 14px;
  color: var(--muted);
}

.resource-list {
  margin-top: 20px;
}

.resource-list ul {
  display: grid;
  gap: 8px;
  margin: 0 0 16px;
  padding-left: 20px;
}

.resource-list a {
  color: var(--primary);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.trainer-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.trainer-actions .hard {
  background: var(--accent);
}

.trainer-actions .unsure {
  background: #c98a05;
}

.trainer-actions .unsure:hover {
  background: #a97000;
}

.trainer-actions .easy {
  background: var(--ok);
}

.choice-list {
  display: grid;
  gap: 10px;
  margin: 18px 0;
}

.choice-list label {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin: 0;
  padding: 12px;
  color: var(--text);
  background: #fafbfd;
}

.choice-list input {
  width: 18px;
  min-height: 18px;
}

.test-result-list {
  display: grid;
  gap: 10px;
}

.test-result {
  border: 1px solid var(--line);
  border-left-width: 5px;
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.test-result span {
  display: inline-block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 700;
}

.test-result p {
  margin: 8px 0 0;
}

.test-result.is-correct {
  border-left-color: var(--ok);
}

.test-result.is-wrong {
  border-left-color: var(--accent);
}
.test-feedback-popup {
  position: fixed;
  left: 50%;
  top: clamp(220px, 30vh, 300px);
  z-index: 1000;
  min-width: min(280px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px 18px;
  background: #fff;
  box-shadow: 0 16px 40px rgba(23, 32, 51, .16);
  color: var(--text);
  font-weight: 800;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -12px);
  transition: opacity .18s ease, transform .18s ease;
}

.test-feedback-popup.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.test-feedback-popup.is-correct {
  border-color: rgba(31, 122, 77, .35);
  color: var(--ok);
}

.test-feedback-popup.is-wrong {
  border-color: rgba(178, 59, 90, .35);
  color: var(--accent);
}

.danger-button {
  background: #a93636;
}

.danger-button:hover {
  background: #842929;
}

.admin-list {
  display: grid;
  gap: 12px;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
}

.admin-row p {
  margin-bottom: 0;
}

.code-tools {
  display: grid;
  gap: 14px;
}

.code-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.code-stat {
  display: block;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  color: var(--text);
  text-align: left;
}

.code-stat:hover {
  border-color: var(--primary);
  background: #f2fbf8;
}

.code-stat span {
  display: block;
  color: var(--primary);
  font-size: 1.8rem;
  font-weight: 850;
  line-height: 1;
}

.code-stat strong {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: .88rem;
}

.code-bulk-actions {
  align-items: center;
}

.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.small-action {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--primary);
  font-size: .9rem;
  font-weight: 750;
  text-decoration: none;
}

.small-action:hover {
  border-color: var(--primary);
  background: #f2fbf8;
}

.code-row.is-selected {
  border-color: rgba(18, 107, 97, .45);
  background: #f2fbf8;
}

.code-select {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}

.code-select input {
  width: 18px;
  min-height: 18px;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.switch input {
  width: 20px;
  min-height: 20px;
}

@media (max-width: 760px) {
  .status-panel,
  .admin-row {
    grid-template-columns: 1fr;
  }

  .trainer-header,
  .admin-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .trainer-header-actions {
    justify-content: flex-start;
  }

  .term-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .overview-stats,
  .overview-columns,
  .code-stat-grid {
    grid-template-columns: 1fr;
  }

  .status-list li {
    flex-direction: column;
    gap: 2px;
  }
}
