:root {
    --ink: #EDEDED;
    --ink-soft: #8C8C8C;
    --paper: #0B0B0B;
    --paper-raised: #171717;
    --line: #2A2A2A;
    --hull: #000000;
    --hull-raised: #161616;
    --hull-line: rgba(255, 255, 255, 0.09);
    --cream: #EDEDED;
    --brass: #A6192E;
    --brass-soft: #D14156;
    --signal: #A6192E;
    --signal-soft: rgba(166, 25, 46, 0.16);
    --danger: #C22839;
    --radius-s: 3px;
    --radius-m: 6px;
  }
  :root:not([data-theme="light"]) {
    @media (prefers-color-scheme: dark) {
      --paper: #0B0B0B;
      --paper-raised: #171717;
      --ink: #EDEDED;
      --ink-soft: #8C8C8C;
      --line: #2A2A2A;
      --signal-soft: rgba(166, 25, 46, 0.16);
    }
  }
  :root[data-theme="dark"] {
    --paper: #0B0B0B;
    --paper-raised: #171717;
    --ink: #EDEDED;
    --ink-soft: #8C8C8C;
    --line: #2A2A2A;
    --signal-soft: rgba(166, 25, 46, 0.16);
  }

  * { box-sizing: border-box; }
  html, body { margin: 0; padding: 0; }
  body {
    background: var(--paper);
    color: var(--ink);
    font-family: "IBM Plex Sans", -apple-system, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }
  h1, h2, h3, .display {
    font-family: "Fraunces", Georgia, "Times New Roman", serif;
    font-weight: 600;
    letter-spacing: -0.01em;
    margin: 0;
  }
  .mono { font-family: "IBM Plex Mono", "SF Mono", monospace; }

  /* ---------- Login ---------- */
  #view-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--hull);
    color: var(--cream);
    padding: 24px;
  }
  .login-card {
    width: 100%;
    max-width: 380px;
  }
  .mark {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 40px;
  }
  .mark-glyph {
    width: 34px; height: 34px;
    border: 1.5px solid var(--brass-soft);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-family: "Fraunces", serif;
    font-size: 17px;
    color: var(--brass-soft);
    flex-shrink: 0;
  }
  .mark-word { font-size: 15px; letter-spacing: 0.04em; color: var(--cream); opacity: 0.85; }
  .login-card h1 {
    font-size: 34px;
    color: var(--cream);
    margin-bottom: 8px;
    line-height: 1.15;
  }
  .login-card p.sub {
    color: var(--cream);
    opacity: 0.6;
    margin: 0 0 36px;
    font-size: 14.5px;
  }
  .field { margin-bottom: 16px; }
  .field label {
    display: block;
    font-size: 12.5px;
    color: var(--cream);
    opacity: 0.55;
    margin-bottom: 6px;
  }
  .field input {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--hull-line);
    border-radius: var(--radius-s);
    padding: 11px 13px;
    color: var(--cream);
    font-family: inherit;
    font-size: 14.5px;
  }
  .field input:focus { outline: 2px solid var(--brass-soft); outline-offset: 1px; }
  .btn-primary {
    width: 100%;
    background: var(--brass);
    color: #F5F5F5;
    border: none;
    border-radius: var(--radius-s);
    padding: 12px;
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 6px;
  }
  .btn-primary:hover { background: var(--brass-soft); }
  .preview-row {
    margin-top: 34px;
    padding-top: 22px;
    border-top: 1px solid var(--hull-line);
  }
  .preview-row p { font-size: 12px; color: var(--cream); opacity: 0.45; margin: 0 0 10px; }
  .preview-btns { display: flex; gap: 8px; }
  .btn-ghost {
    flex: 1;
    background: transparent;
    border: 1px solid var(--hull-line);
    color: var(--cream);
    padding: 9px 10px;
    border-radius: var(--radius-s);
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
  }
  .btn-ghost:hover { border-color: var(--brass-soft); color: var(--brass-soft); }

  /* ---------- App shell ---------- */
  #view-app { display: none; min-height: 100vh; }
  #view-app.active { display: flex; }
  .sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--hull);
    color: var(--cream);
    padding: 26px 18px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
  }
  .sidebar .mark { margin-bottom: 34px; }
  .sidebar .mark-word { font-size: 13.5px; }
  .nav-group { margin-bottom: 22px; }
  .nav-label {
    font-size: 10.5px;
    letter-spacing: 0.08em;
    color: var(--cream);
    opacity: 0.4;
    padding: 0 10px;
    margin-bottom: 8px;
  }
  .nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-s);
    color: var(--cream);
    opacity: 0.72;
    font-size: 14px;
    cursor: pointer;
    margin-bottom: 2px;
  }
  .nav-item:hover { opacity: 1; background: rgba(236,233,224,0.05); }
  .nav-item.on { opacity: 1; background: rgba(182,132,46,0.16); color: var(--brass-soft); }
  .nav-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
  .sidebar-foot {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--hull-line);
  }
  .role-switch {
    display: flex;
    background: rgba(236,233,224,0.06);
    border-radius: var(--radius-s);
    padding: 3px;
    margin-bottom: 14px;
  }
  .role-switch button {
    flex: 1;
    background: none;
    border: none;
    color: var(--cream);
    opacity: 0.55;
    font-family: inherit;
    font-size: 11.5px;
    padding: 6px 4px;
    border-radius: 2px;
    cursor: pointer;
  }
  .role-switch button.on { background: var(--paper-raised); opacity: 1; color: var(--hull); font-weight: 600; }
  .whoami { font-size: 12.5px; color: var(--cream); opacity: 0.5; padding: 0 4px; }
  .whoami b { color: var(--cream); opacity: 1; display: block; font-size: 13.5px; margin-bottom: 1px; }

  .main {
    flex: 1;
    padding: 40px 48px 80px;
    max-width: 1040px;
  }
  .page-head { margin-bottom: 32px; }
  .page-head h1 { font-size: 28px; margin-bottom: 6px; }
  .page-head .sub { color: var(--ink-soft); font-size: 14.5px; }
  .screen { display: none; }
  .screen.active { display: block; }

  /* ---------- Dashboard widgets ---------- */
  .stat-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1px;
    background: var(--line);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    overflow: hidden;
    margin-bottom: 36px;
  }
  .stat {
    background: var(--paper-raised);
    padding: 18px 20px;
  }
  .stat .num { font-family: "Fraunces", serif; font-size: 26px; font-weight: 600; }
  .stat .lbl { font-size: 12.5px; color: var(--ink-soft); margin-top: 3px; }

  .section-title {
    font-size: 12px;
    letter-spacing: 0.03em;
    color: var(--ink-soft);
    margin: 0 0 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--line);
  }

  .route-card {
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    padding: 22px 24px;
    margin-bottom: 36px;
    background: var(--paper-raised);
  }
  .route-card .tag {
    display: inline-block;
    font-size: 11px;
    color: var(--signal);
    background: var(--signal-soft);
    padding: 3px 9px;
    border-radius: 20px;
    margin-bottom: 12px;
  }
  .route-card h3 { font-size: 20px; margin-bottom: 4px; }
  .route-card .meta { font-size: 13px; color: var(--ink-soft); margin-bottom: 16px; }
  .bar { height: 7px; background: var(--line); border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
  .bar > i { display: block; height: 100%; background: var(--signal); border-radius: 4px; }
  .bar-lbl { font-size: 12.5px; color: var(--ink-soft); display: flex; justify-content: space-between; margin-bottom: 18px; }
  .btn-continue {
    background: var(--brass);
    color: #F5F5F5;
    border: none;
    padding: 10px 18px;
    border-radius: var(--radius-s);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
  }
  .btn-continue:hover { background: var(--brass-soft); }

  .list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--line);
  }
  .list-row:last-child { border-bottom: none; }
  .list-row .name { font-size: 14.5px; font-weight: 500; }
  .list-row .desc { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
  .pill {
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 20px;
    white-space: nowrap;
  }
  .pill.req { background: rgba(168,75,58,0.12); color: var(--danger); }
  .pill.opt { background: var(--line); color: var(--ink-soft); }

  /* ---------- Catalog ---------- */
  .chip-row { display: flex; gap: 8px; margin-bottom: 28px; flex-wrap: wrap; }
  .chip {
    font-size: 13px;
    padding: 7px 14px;
    border-radius: 20px;
    border: 1px solid var(--line);
    color: var(--ink-soft);
    cursor: pointer;
    background: var(--paper-raised);
  }
  .chip.on { background: var(--hull); color: var(--cream); border-color: var(--hull); }
  .course-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
  .course-item {
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    padding: 18px;
    background: var(--paper-raised);
  }
  .course-item .cat { font-size: 11px; color: var(--brass); margin-bottom: 8px; font-weight: 600; }
  .course-item h4 { font-family: "Fraunces", serif; font-size: 16.5px; font-weight: 600; margin-bottom: 8px; line-height: 1.3; }
  .course-item .meta { font-size: 12px; color: var(--ink-soft); margin-bottom: 14px; }
  .course-item .status { font-size: 12px; }
  .status.done { color: var(--signal); }
  .status.progress { color: var(--brass); }

  /* ---------- Course player ---------- */
  .player-layout { display: flex; gap: 28px; }
  .player-main { flex: 1; }
  .video-block {
    aspect-ratio: 16/9;
    background: var(--hull);
    border-radius: var(--radius-m);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 18px;
    position: relative;
  }
  .play-glyph {
    width: 58px; height: 58px;
    border: 1.5px solid var(--brass-soft);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--brass-soft);
  }
  .lesson-list { width: 280px; flex-shrink: 0; }
  .lesson {
    display: flex;
    gap: 12px;
    padding: 12px 10px;
    border-radius: var(--radius-s);
    cursor: pointer;
  }
  .lesson.on { background: var(--signal-soft); }
  .lesson-check {
    width: 18px; height: 18px;
    border-radius: 50%;
    border: 1.5px solid var(--line);
    flex-shrink: 0;
    margin-top: 2px;
    display: flex; align-items: center; justify-content: center;
    font-size: 10px;
  }
  .lesson-check.done { background: var(--signal); border-color: var(--signal); color: white; }
  .lesson-title { font-size: 13.5px; font-weight: 500; }
  .lesson-dur { font-size: 11.5px; color: var(--ink-soft); }

  /* ---------- Admin ---------- */
  table { width: 100%; border-collapse: collapse; }
  th {
    text-align: left;
    font-size: 11.5px;
    letter-spacing: 0.02em;
    color: var(--ink-soft);
    font-weight: 500;
    padding: 0 12px 10px;
    border-bottom: 1px solid var(--line);
  }
  td { padding: 13px 12px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
  tr:last-child td { border-bottom: none; }
  .person-cell { display: flex; align-items: center; gap: 10px; }
  .avatar {
    width: 30px; height: 30px;
    border-radius: 50%;
    background: var(--cream);
    background: var(--signal-soft);
    color: var(--signal);
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600;
    flex-shrink: 0;
  }
  .mini-bar { width: 90px; height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 8px; }
  .mini-bar > i { display: block; height: 100%; background: var(--signal); }
  .btn-small {
    background: var(--paper);
    border: 1px solid var(--line);
    color: var(--ink);
    padding: 6px 12px;
    border-radius: var(--radius-s);
    font-family: inherit;
    font-size: 12.5px;
    cursor: pointer;
  }
  .btn-small:hover { border-color: var(--brass); color: var(--brass); }
  .btn-small:disabled { opacity: 0.35; cursor: not-allowed; }
  .btn-small:disabled:hover { border-color: var(--line); color: var(--ink); }
  .toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 22px; }
  .btn-dark {
    background: var(--brass);
    color: #F5F5F5;
    border: none;
    padding: 10px 16px;
    border-radius: var(--radius-s);
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
  }
  .btn-dark:hover { background: var(--brass-soft); }

  .assign-panel {
    display: none;
    border: 1px solid var(--brass-soft);
    background: var(--paper-raised);
    border-radius: var(--radius-m);
    padding: 22px 24px;
    margin-bottom: 28px;
  }
  .assign-panel.open { display: block; }
  .assign-panel h3 { font-size: 16px; margin-bottom: 16px; }
  .assign-row { display: flex; gap: 10px; margin-bottom: 12px; }
  .assign-row select, .assign-row input {
    flex: 1;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    font-family: inherit;
    font-size: 13.5px;
    background: var(--paper);
    color: var(--ink);
  }
  .assign-actions { display: flex; gap: 8px; margin-top: 6px; }

  @media (max-width: 720px) {
    #view-app.active { flex-direction: column; }
    .sidebar { width: 100%; height: auto; position: relative; flex-direction: row; overflow-x: auto; padding: 14px; }
    .sidebar .mark, .nav-label, .sidebar-foot .whoami { display: none; }
    .nav-group { display: flex; gap: 4px; margin-bottom: 0; }
    .main { padding: 24px 18px 60px; }
    .player-layout { flex-direction: column; }
    .lesson-list { width: 100%; }
    .stat-row { grid-template-columns: 1fr; }
  }