*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  background: #f0f0f0;
  color: #1a1a1a;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background: #1a1a1a;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-title {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.header-version {
  font-size: 12px;
  font-weight: 400;
  color: #888;
  letter-spacing: 0;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.btn-ghost-light {
  background: transparent;
  color: #ccc;
  border: 1px solid #444;
  font-size: 13px;
}
.btn-ghost-light:hover { color: #fff; border-color: #888; }

/* ── Toggle switch ── */
.switch-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.switch-label {
  font-size: 13px;
  color: #ccc;
}
.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-slider {
  position: absolute;
  inset: 0;
  background: #444;
  border-radius: 999px;
  transition: background-color 150ms ease;
}
.switch-slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 150ms ease;
}
.switch input:checked + .switch-slider {
  background: #2563eb;
}
.switch input:checked + .switch-slider::before {
  transform: translateX(18px);
}
.switch input:focus-visible + .switch-slider {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* ── Main ── */
.main {
  max-width: 960px;
  margin: 0 auto;
  padding: 28px 24px;
}

.empty-state {
  color: #777;
  text-align: center;
  margin-top: 48px;
}

/* ── App list ── */
.app-list {
  display: flex;
  flex-direction: column;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: #fff;
}
.app-row:first-child { border-radius: 8px 8px 0 0; }
.app-row:last-child  { border-radius: 0 0 8px 8px; border-bottom: none; }

/* ── App row ── */
.app-row {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 48px;
  border-bottom: 1px solid #f0f0f0;
}
.app-row:last-child { border-bottom: none; }
.app-row:hover { background: #fafafa; }

.app-row-name {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

/* ── App grid (learner view / coach preview) ── */
.app-list--grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
  border: none;
  background: none;
  border-radius: 0;
}
.app-grid-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  background: #fff;
  text-decoration: none;
  color: inherit;
}
.app-grid-card:hover { background: #fafafa; }
.app-grid-thumb {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.app-grid-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.app-grid-thumb-placeholder {
  font-size: 32px;
  font-weight: 600;
  color: #999;
}
.app-grid-name {
  font-size: 14px;
  font-weight: 500;
  text-align: center;
}

/* ── Icon buttons ── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #444;
  cursor: pointer;
  text-decoration: none;
}
.icon-btn:hover { background: #f0f0f0; color: #1a1a1a; }
.icon-btn--dim { color: #ccc; cursor: pointer; }
.icon-btn--dim:hover { background: #f0f0f0; color: #aaa; }

/* ── Kebab menu ── */
.kebab-wrap {
  position: relative;
}
.kebab-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 7px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  min-width: 180px;
  z-index: 50;
  padding: 4px 0;
}
.kebab-menu[hidden] { display: none; }
.kebab-menu button {
  display: block;
  width: 100%;
  padding: 8px 14px;
  text-align: left;
  background: none;
  border: none;
  font-size: 13px;
  cursor: pointer;
  color: #1a1a1a;
}
.kebab-menu button:hover { background: #f5f5f5; }
.kebab-menu button.danger { color: #b91c1c; }
.kebab-menu hr { border: none; border-top: 1px solid #f0f0f0; margin: 4px 0; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 12px;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  line-height: 1;
}
.btn:hover { opacity: .85; }
.btn:active { opacity: .7; }

.btn-primary { background: #2563eb; color: #fff; }
.btn-ghost {
  background: #f0f0f0;
  color: #1a1a1a;
  border: 1px solid #ddd;
}
.btn-danger { background: #fee2e2; color: #b91c1c; }

/* ── Modals ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal[hidden] { display: none; }

.modal-box {
  background: #fff;
  border-radius: 10px;
  padding: 28px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.modal-box h2 {
  font-size: 18px;
  font-weight: 600;
}

.modal-box form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-box label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  font-weight: 500;
  color: #555;
}
.modal-box input[type="text"],
.modal-box textarea,
.modal-box input[type="file"],
.modal-box select {
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-family: inherit;
  width: 100%;
}
.modal-box textarea {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
  resize: vertical;
}

.modal-box input[type="text"]:focus,
.modal-box textarea:focus,
.modal-box select:focus {
  outline: 2px solid #2563eb;
  border-color: transparent;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── Toggle ── */
.code-input-toggle {
  display: flex;
  gap: 4px;
}
.toggle-btn {
  padding: 5px 12px;
  border-radius: 4px;
  border: 1px solid #ddd;
  background: #f5f5f5;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  color: #555;
}
.toggle-btn.active {
  background: #1a1a1a;
  color: #fff;
  border-color: #1a1a1a;
}

.edit-view-actions {
  margin-top: 8px;
}

/* ── Chart modal ── */
.modal--chart { padding: 0; background: #1a1a1a; }
.modal-box--chart {
  max-width: none;
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  padding: 0;
  gap: 0;
  overflow: hidden;
}
.chart-modal-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  height: 44px;
  background: #1a1a1a;
  color: #fff;
  flex-shrink: 0;
}
.chart-modal-title {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
}
.chart-modal-close {
  background: none;
  border: none;
  color: #aaa;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.chart-modal-close:hover { color: #fff; }
.chart-modal-frame {
  flex: 1;
  border: none;
  width: 100%;
}

/* ── Login modal ── */
.modal-box--narrow { max-width: 320px; }
.login-user-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.login-user-btn {
  width: 100%;
  padding: 10px 14px;
  text-align: left;
  background: #f8f8f8;
  border: 1px solid #e8e8e8;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.login-user-btn:hover { background: #f0f0f0; }
.login-new {
  display: flex;
  gap: 8px;
}
.login-new input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 5px;
  font-size: 14px;
}
.login-new input:focus { outline: 2px solid #2563eb; border-color: transparent; }

/* ── Analytics tabs (runner) ── */
.analytics-tabs {
  display: flex;
  gap: 4px;
  margin-left: auto;
}
.analytics-tab {
  padding: 4px 12px;
  border-radius: 4px;
  border: 1px solid #444;
  background: transparent;
  color: #aaa;
  font-size: 12px;
  cursor: pointer;
}
.analytics-tab.active {
  background: #fff;
  color: #1a1a1a;
  border-color: #fff;
}
.analytics-tab:hover:not(.active) { color: #fff; border-color: #888; }

/* ── Chart config (modal) ── */
.modal-box .checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.modal-hint {
  font-size: 12px;
  color: #888;
  margin: -6px 0 0;
}
.modal-hint-inline {
  font-weight: 400;
  color: #999;
}

/* ── Companion list (modal) ── */
.modal-subheading {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.companion-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}
.companion-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #f8f8f8;
  border-radius: 5px;
}
.companion-label {
  flex: 1;
  font-size: 13px;
}
.companion-limit {
  font-size: 12px;
  color: #999;
  margin-bottom: 8px;
}

/* ── Runner ── */
.runner-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.runner-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  height: 44px;
  background: #1a1a1a;
  color: #fff;
  flex-shrink: 0;
}
.runner-back {
  color: #aaa;
  text-decoration: none;
  font-size: 13px;
}
.runner-back:hover { color: #fff; }
.runner-title {
  font-size: 14px;
  font-weight: 500;
  flex: 1;
}
.runner-status--ok  { font-size: 13px; color: #4ade80; }
.runner-status--err { font-size: 13px; color: #f87171; }

.runner-shell iframe {
  flex: 1;
  border: none;
  width: 100%;
}

.runner-start-gate {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}
.runner-start-gate[hidden] {
  /* An author-stylesheet `display` rule always beats the UA stylesheet's [hidden]
     rule, regardless of specificity — so the base rule above permanently defeats
     `element.hidden = true` unless overridden explicitly here. This was the actual
     "split screen" bug: the gate never visually hid, it just sat stacked above the
     iframe once the iframe became visible too. */
  display: none;
}
.runner-start-name {
  font-size: 24px;
  font-weight: 600;
}
.runner-start-btn {
  font-size: 20px;
  padding: 16px 48px;
}

/* The gate's "Playing as" row is the last thing between a coach and a session written
   to someone's record, so it is stated at reading size and turns amber the moment it
   isn't the coach themselves — quiet enough to ignore when it says "Me", impossible to
   miss when it doesn't. */
.runner-play-as {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  padding: 10px 16px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: #fafafa;
}
.runner-play-as select {
  font-size: 16px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #bbb;
  background: #fff;
}
.runner-play-as--other {
  background: #fff4d6;
  border-color: #e6c65c;
  color: #6b4e00;
  font-weight: 600;
}
.runner-as-chip {
  font-size: 13px;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: #e6c65c;
  color: #4a3600;
}
.runner-as-chip[hidden] { display: none; }


/* ── Session list (modal) ── */
.session-list {
  display: flex;
  flex-direction: column;
  border: 1px solid #e8e8e8;
  border-radius: 6px;
  overflow: hidden;
}
.session-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
}
.session-row:last-child { border-bottom: none; }
.session-row:hover { background: #fafafa; }
.session-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.session-time {
  font-size: 13px;
  color: #1a1a1a;
}
.session-summary {
  font-size: 12px;
  color: #777;
  font-variant-numeric: tabular-nums;
}
.session-delete {
  color: #aaa;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}
.session-delete:hover { color: #b91c1c; background: #fee2e2; }
.sessions-empty,
.sessions-loading {
  font-size: 13px;
  color: #999;
  padding: 12px 0;
}

/* ── Asset manager ── */
.modal-box--wide { max-width: 700px; }

.asset-missing { color: #f87171; }

.asset-section-title {
  font-size: 12px;
  font-weight: 600;
  color: #777;
  margin: 16px 0 6px;
}
.asset-section-title:first-child { margin-top: 0; }

.asset-list {
  display: flex;
  flex-direction: column;
  border: 1px solid #e8e8e8;
  border-radius: 6px;
  overflow: hidden;
}
.asset-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid #f0f0f0;
}
.asset-row:last-child { border-bottom: none; }
.asset-row:hover { background: #fafafa; }

.asset-type {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: #e8e8e8;
  color: #555;
  border-radius: 3px;
  padding: 2px 5px;
  flex-shrink: 0;
  width: 34px;
  text-align: center;
}

.asset-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.asset-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.asset-meta { font-size: 11px; color: #999; }
.asset-name code { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; background: #f0f0f0; padding: 1px 4px; border-radius: 3px; }

.asset-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

/* ── Misc ── */
.error { color: #b91c1c; }
.header-username {
  font-size: 13px;
  color: #ccc;
  padding: 0 4px;
}

/* ── Playing as ── */
.header-select {
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #2a2a2a;
  color: #fff;
  max-width: 180px;
}
/* Amber, not the app's normal accent: this is a state the coach must notice they are
   in, since everything they do while it's on lands in someone else's data. */
.play-as-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: #fff4d6;
  border-bottom: 1px solid #e6c65c;
  color: #6b4e00;
  font-size: 14px;
}
.play-as-banner[hidden] { display: none; }
.play-as-banner-clear {
  background: none;
  border: 1px solid #b8912a;
  color: #6b4e00;
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 13px;
  cursor: pointer;
}
.play-as-banner-clear:hover { background: #f2e3b0; }
body.is-playing-as .header { box-shadow: inset 0 -3px 0 #e6c65c; }

/* ── Login page ── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 32px;
  position: relative;
}
.login-back {
  position: absolute;
  top: 12px;
  left: 12px;
  background: none;
  border: none;
  cursor: pointer;
  color: #888;
  padding: 4px;
  display: flex;
}
.login-back:hover { color: #1a1a1a; }
.login-title {
  font-size: 20px;
  font-weight: 600;
  text-align: center;
  margin-bottom: 20px;
}
.login-input {
  width: 100%;
  padding: 9px 12px;
  border: 2px solid #e0e0e0;
  border-radius: 6px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.15s;
}
.login-input:focus { border-color: #3b82f6; }
.login-error {
  color: #b91c1c;
  font-size: 13px;
  margin-top: 6px;
}
.login-btn-full {
  width: 100%;
  margin-top: 14px;
  padding: 10px;
  font-size: 15px;
}
.passphrase-toggle-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}
.passphrase-eye {
  color: #888;
  padding: 4px;
}
.passphrase-eye:hover { color: #1a1a1a; }
.passphrase-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px 16px;
}
.passphrase-word-wrap {
  display: flex;
  align-items: baseline;
  gap: 6px;
}
.passphrase-digit {
  font-size: 11px;
  color: #aaa;
  user-select: none;
  min-width: 14px;
  transition: color 0.1s;
}
.passphrase-input-wrap {
  position: relative;
  flex: 1;
}
.auth-word-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1.5px solid #d1d5db;
  padding: 4px 0;
  font-size: 14px;
  outline: none;
  position: relative;
  z-index: 1;
  transition: border-color 0.15s;
}
.auth-word-input:focus { border-bottom-color: #3b82f6; }
.auth-word-input.input-invalid { border-bottom-color: #ef4444; }
.auth-ghost-text {
  position: absolute;
  left: 0;
  top: 0;
  padding: 4px 0;
  font-size: 14px;
  color: #aaa;
  pointer-events: none;
  white-space: nowrap;
}
.auth-action-area {
  margin-top: 16px;
  min-height: 80px;
}
.auth-suggestion-display {
  font-size: 12px;
  color: #6b7280;
  min-height: 40px;
  text-align: center;
}
.auth-remember {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
  font-size: 13px;
  color: #555;
  cursor: pointer;
}
