  @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@500;600;700;800&family=Source+Sans+3:wght@400;500;600;700&family=IBM+Plex+Mono:wght@500;600&display=swap');

  :root {
    --bg: #f5f7f9;
    --surface: #ffffff;
    --surface-2: #eaf0f6;
    --border: #dbe3ea;
    --text: #16232f;
    --text-muted: #62727f;
    --accent: #1f5ca8;
    --accent-strong: #164680;
    --accent-soft: #dde8f5;
    --accent-contrast: #ffffff;
    --highlight: #ea6a24;
    --highlight-soft: #fbe4d3;
    --warn: #b0590f;
    --warn-soft: #f6e2cd;
    --danger: #c1443a;
    --danger-soft: #f6dfdc;
    --shadow: 0 1px 2px rgba(15, 30, 45, 0.06), 0 8px 24px -12px rgba(15, 30, 45, 0.18);
  }
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --bg: #0c1b2a; --surface: #12253a; --surface-2: #1a324a; --border: #2a465f;
      --text: #eaf1f8; --text-muted: #9db2c4; --accent: #5b9bdc; --accent-strong: #8dc0ee;
      --accent-soft: #1c3f63; --accent-contrast: #08182a; --highlight: #f38a4d; --highlight-soft: #3a2415;
      --warn: #e3a15a; --warn-soft: #3a2c18;
      --danger: #ef8a7d; --danger-soft: #3a1f1d;
      --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 12px 32px -16px rgba(0,0,0,0.5);
    }
  }
  :root[data-theme="dark"] {
    --bg: #0c1b2a; --surface: #12253a; --surface-2: #1a324a; --border: #2a465f;
    --text: #eaf1f8; --text-muted: #9db2c4; --accent: #5b9bdc; --accent-strong: #8dc0ee;
    --accent-soft: #1c3f63; --accent-contrast: #08182a; --highlight: #f38a4d; --highlight-soft: #3a2415;
    --warn: #e3a15a; --warn-soft: #3a2c18;
    --danger: #ef8a7d; --danger-soft: #3a1f1d;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 12px 32px -16px rgba(0,0,0,0.5);
  }

  * { box-sizing: border-box; }
  html { background: var(--bg); }
  body {
    margin: 0; background: var(--bg); color: var(--text);
    font-family: "Source Sans 3", system-ui, sans-serif; font-size: 15px; line-height: 1.5;
    padding: 0 20px;
  }
  h1, h2, h3 { font-family: "Poppins", system-ui, sans-serif; letter-spacing: -0.01em; text-wrap: balance; margin: 0; }
  .mono { font-family: "IBM Plex Mono", monospace; font-variant-numeric: tabular-nums; }
  button { font-family: inherit; cursor: pointer; }
  a { color: inherit; }

  #app { max-width: 980px; margin: 0 auto; padding-block: 28px 64px; }

  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 28px; flex-wrap: wrap; }
  .brand { display: flex; align-items: center; gap: 10px; }
  .brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
  .brand-mark svg { width: 18px; height: 18px; }
  .brand-text { display: flex; flex-direction: column; line-height: 1.15; }
  .brand-text b { font-family: "Poppins"; font-weight: 800; font-size: 16px; }
  .brand-text span { font-size: 11.5px; color: var(--text-muted); letter-spacing: 0.02em; }

  .who { display: flex; align-items: center; gap: 10px; font-size: 13.5px; color: var(--text-muted); }
  .who b { color: var(--text); font-weight: 600; }
  .btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); padding: 7px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; }
  .btn-ghost:hover { background: var(--surface-2); }

  .gate-wrap { display: flex; justify-content: center; padding-top: 8vh; }
  .gate { width: 100%; max-width: 380px; }
  .gate-header { text-align: center; margin-bottom: 26px; }
  .gate-header .brand-mark { margin: 0 auto 14px; width: 46px; height: 46px; border-radius: 13px; }
  .gate-header .brand-mark svg { width: 24px; height: 24px; }
  .gate-header h1 { font-size: 21px; font-weight: 800; }
  .gate-header p { color: var(--text-muted); font-size: 13.5px; margin-top: 6px; }

  .chooser-links { display: flex; flex-direction: column; gap: 10px; }
  .chooser-link { display: flex; flex-direction: column; align-items: flex-start; gap: 3px; text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); }
  .chooser-link:hover { border-color: var(--accent); }
  .chooser-link-title { font-family: "Poppins"; font-weight: 800; font-size: 15px; }
  .chooser-link-sub { font-size: 12.5px; color: var(--text-muted); }
  .link-back { display: block; margin: 18px auto 0; background: none; border: none; color: var(--text-muted); font-size: 12.5px; font-weight: 600; }
  .link-back:hover { color: var(--text); }

  .card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 22px; box-shadow: var(--shadow); }

  label.field { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; letter-spacing: 0.01em; }
  input, select, textarea {
    width: 100%; font-family: inherit; font-size: 14.5px; color: var(--text);
    background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 11px; outline: none;
  }
  input:focus, select:focus, textarea:focus { border-color: var(--accent); }
  input.pin-input { font-family: "IBM Plex Mono"; letter-spacing: 0.3em; font-size: 20px; text-align: center; font-weight: 600; }
  .field-gap { margin-bottom: 14px; }

  .btn-primary { width: 100%; background: var(--accent); color: var(--accent-contrast); border: none; padding: 11px 0; border-radius: 9px; font-weight: 700; font-size: 14.5px; margin-top: 4px; }
  .btn-primary:hover { background: var(--accent-strong); }
  .btn-primary:disabled { opacity: 0.55; cursor: default; }
  .btn-small { background: var(--accent-soft); color: var(--accent-strong); border: none; padding: 7px 12px; border-radius: 7px; font-weight: 700; font-size: 12.5px; }
  .btn-small.outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
  .btn-small.danger { background: var(--danger-soft); color: var(--danger); }

  .error-msg { color: var(--danger); font-size: 13px; margin-top: 10px; text-align: center; }
  .hint-msg { color: var(--text-muted); font-size: 12px; margin-top: 14px; text-align: center; }

  .expiry-banner { display: flex; align-items: center; gap: 10px; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 11px 14px; font-size: 13px; font-weight: 600; margin-bottom: 20px; }
  .progress-card { display: flex; align-items: center; gap: 18px; margin-bottom: 26px; }
  .ring { position: relative; width: 58px; height: 58px; flex-shrink: 0; }
  .ring svg { transform: rotate(-90deg); }
  .ring-label { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: "IBM Plex Mono"; font-weight: 600; font-size: 13px; }
  .progress-text h3 { font-size: 15px; }
  .progress-text p { margin: 3px 0 0; color: var(--text-muted); font-size: 13px; }

  .program-group { margin-bottom: 26px; }
  .program-title { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
  .program-title h2 { font-size: 15.5px; }
  .program-title span { font-size: 12px; color: var(--text-muted); }

  .exercise-list { display: flex; flex-direction: column; gap: 10px; }
  .exercise-row { display: flex; align-items: center; gap: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; box-shadow: var(--shadow); }
  .thumb { width: 64px; height: 64px; border-radius: 9px; flex-shrink: 0; overflow: hidden; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; position: relative; }
  .thumb video { width: 100%; height: 100%; object-fit: cover; }
  .thumb svg { width: 24px; height: 24px; color: var(--accent-strong); }
  .ex-info { flex: 1; min-width: 0; }
  .ex-info h3 { font-size: 14.5px; font-weight: 700; }
  .ex-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
  .ex-meta .mono { color: var(--text); font-weight: 600; }
  .ex-note { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-style: italic; }

  .check-toggle { flex-shrink: 0; width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface); display: flex; align-items: center; justify-content: center; }
  .check-toggle.done { background: var(--highlight); border-color: var(--highlight); }
  .check-toggle svg { width: 18px; height: 18px; color: var(--accent-contrast); opacity: 0; }
  .check-toggle.done svg { opacity: 1; }

  .video-modal-backdrop { position: fixed; inset: 0; background: rgba(10, 16, 13, 0.6); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
  .video-modal { background: var(--surface); border-radius: 14px; padding: 18px; max-width: 480px; width: 100%; box-shadow: var(--shadow); }
  .video-modal video { width: 100%; border-radius: 9px; background: #000; }
  .video-modal h3 { font-size: 15.5px; margin-bottom: 4px; }
  .video-modal p { font-size: 13px; color: var(--text-muted); margin: 8px 0 0; }

  .empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
  .empty-state svg { width: 40px; height: 40px; margin-bottom: 14px; color: var(--border); }

  .tabs { display: flex; gap: 4px; margin-bottom: 22px; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .tab-btn { background: none; border: none; padding: 10px 14px; font-weight: 600; font-size: 13.5px; color: var(--text-muted); border-bottom: 2px solid transparent; white-space: nowrap; }
  .tab-btn.active { color: var(--accent-strong); border-bottom-color: var(--accent); }

  .panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 10px; flex-wrap: wrap; }
  .panel-head h2 { font-size: 17px; }
  .panel-head p.sub { color: var(--text-muted); font-size: 13px; margin: 4px 0 0; }

  table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
  th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 700; padding: 0 10px 8px; }
  td { padding: 12px 10px; border-top: 1px solid var(--border); vertical-align: middle; }
  .table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; overflow-x: auto; box-shadow: var(--shadow); margin-bottom: 22px; }
  .table-wrap table { min-width: 560px; }

  .pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
  .pill.ok { background: var(--accent-soft); color: var(--accent-strong); }
  .pill.warn { background: var(--warn-soft); color: var(--warn); }
  .pill.off { background: var(--surface-2); color: var(--text-muted); }

  .form-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 24px; }
  .form-card h3 { font-size: 14.5px; margin-bottom: 14px; }
  .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 14px; }
  .form-actions { margin-top: 14px; display: flex; gap: 10px; align-items: center; }
  .checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin-top: 4px; }
  .chip-check { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px; background: var(--bg); }
  .chip-check input { width: auto; }

  .exercise-admin-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 24px; }
  .exercise-admin-card { background: var(--surface); border: 1px solid var(--border); border-radius: 13px; overflow: hidden; box-shadow: var(--shadow); }
  .exercise-admin-thumb { height: 110px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; position: relative; }
  .exercise-admin-thumb video { width: 100%; height: 100%; object-fit: cover; }
  .exercise-admin-thumb svg { width: 28px; height: 28px; color: var(--accent-strong); }
  .exercise-admin-body { padding: 12px 13px; }
  .exercise-admin-body h4 { font-size: 13.5px; margin-bottom: 4px; }
  .exercise-admin-body p { font-size: 12px; color: var(--text-muted); margin: 0 0 8px; min-height: 15px; }
  .upload-btn { position: relative; overflow: hidden; display: inline-flex; }
  .upload-btn input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

  .chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
  .chip { background: var(--surface-2); color: var(--text); font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }

  .assign-list { display: flex; flex-direction: column; gap: 10px; }
  .assign-row { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 13px 15px; box-shadow: var(--shadow); }
  .assign-row-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
  .assign-row-top b { font-size: 14px; }
  .assign-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

  .toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
    padding: 10px 18px; border-radius: 9px; font-size: 13px; font-weight: 600; box-shadow: var(--shadow); z-index: 80;
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
  }
  .toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

  @media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
