:root {
  color-scheme: light;
  --ink: #18212b;
  --muted: #64717f;
  --line: #d9e0e6;
  --panel: #ffffff;
  --surface: #f6f7f8;
  --primary: #143a5a;
  --primary-2: #0f6b7a;
  --danger: #b42318;
  --ok: #167a4a;
  --warn: #a15c05;
  --accent: #d64545;
  --gold: #f0b24a;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--surface);
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 12px;
  cursor: pointer;
}

button:hover {
  border-color: var(--primary-2);
}

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

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

label input,
label select {
  color: var(--ink);
  font-size: 15px;
}

fieldset {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

legend {
  color: var(--muted);
  font-size: 13px;
  padding: 0 4px;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 78px;
}

.account-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.compact-button {
  min-height: 32px;
  padding: 5px 9px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  object-fit: contain;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary-2);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 10px;
  font-size: 14px;
  line-height: 1.25;
  letter-spacing: 0;
}

.account-pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  padding: 5px 10px;
  font-size: 13px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin: 10px 0 18px;
}

.tab {
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  min-width: 110px;
}

.tab.is-active {
  color: var(--primary);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

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

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

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.compact-form,
.member-form,
.video-form {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(100px, 140px) auto;
  gap: 10px;
  align-items: end;
}

.member-form {
  grid-template-columns: minmax(190px, 1fr) 120px 110px auto;
}

.member-form input,
.member-form select,
.member-form button,
.member-editor input,
.member-editor select {
  height: 40px;
  min-height: 40px;
}

.members-panel {
  grid-column: 1 / -1;
}

.member-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.member-entry {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.member-entry.is-selected {
  border-color: var(--primary-2);
  background: #edf7f8;
}

.member-item {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
}

.member-role {
  color: var(--muted);
  font-size: 12px;
  text-transform: capitalize;
}

.member-identity {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.member-identity > span {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.member-identity strong,
.member-identity small {
  overflow-wrap: anywhere;
}

.member-identity small,
.member-permission-note {
  color: var(--muted);
  font-size: 12px;
}

.member-permission-note {
  margin-bottom: 0;
}

.member-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

.member-actions button {
  min-height: 36px;
  padding: 6px 9px;
}

.member-editor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.member-editor-actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.danger-button {
  border-color: #e6b8b4;
  color: var(--danger);
}

.video-form {
  grid-template-columns: minmax(180px, 1.3fr) minmax(160px, 1fr) minmax(130px, 0.8fr) auto;
}

.settings-panel {
  grid-column: span 2;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 12px;
  align-items: end;
}

.checkbox-row,
.button-row,
.inline-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.inline-controls {
  color: var(--muted);
  font-size: 13px;
}

.check-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}

.check-pill input {
  width: auto;
  min-height: 0;
}

.divider {
  height: 1px;
  background: var(--line);
  margin: 14px 0;
}

.profile-list,
.video-list,
.allowed-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.profile-account-form {
  display: grid;
  grid-template-columns: minmax(200px, 1fr) auto;
  align-items: end;
  gap: 10px;
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.profile-button,
.video-button {
  display: grid;
  justify-items: start;
  width: 100%;
  min-height: 56px;
  text-align: left;
}

.profile-button {
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.profile-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--surface);
}

.profile-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
}

.profile-button-copy {
  display: grid;
  justify-items: start;
  gap: 3px;
  min-width: 0;
}

.profile-button-copy strong,
.profile-button-copy small {
  overflow-wrap: anywhere;
}

.profile-button small,
.video-button small,
.allowed-item span {
  color: var(--muted);
  font-size: 12px;
}

.profile-button.is-selected,
.video-button.is-selected {
  border-color: var(--primary-2);
  background: #edf7f8;
}

.allowed-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.allowed-item > div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.channel-item {
  display: grid;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
}

.channel-heading,
.channel-actions,
.transport-controls,
.speed-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.channel-heading {
  justify-content: space-between;
}

.channel-heading > div:first-child {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.channel-heading span,
.channel-summary {
  color: var(--muted);
  font-size: 12px;
}

.channel-summary,
.inline-error {
  margin: 0;
}

.inline-error {
  color: var(--danger);
  font-size: 13px;
}

.segmented-control {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented-control button {
  min-height: 34px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  padding: 6px 10px;
}

.segmented-control button:last-child {
  border-right: 0;
}

.segmented-control button[aria-pressed="true"] {
  background: var(--primary);
  color: #fff;
}

.channel-video-picker,
.channel-playlists {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.channel-video-picker summary,
.channel-playlists summary {
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
}

.playlist-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-top: 10px;
}

.playlist-list div {
  display: grid;
  gap: 2px;
  border-left: 3px solid var(--gold);
  background: var(--surface);
  padding: 8px;
}

.playlist-list strong,
.playlist-list span {
  overflow-wrap: anywhere;
}

.playlist-list strong {
  font-size: 12px;
}

.playlist-list span {
  color: var(--muted);
  font-size: 11px;
}

.channel-video-list {
  display: grid;
  gap: 6px;
  max-height: 340px;
  margin-top: 10px;
  overflow: auto;
}

.channel-video-choice {
  display: grid;
  grid-template-columns: auto 72px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 52px;
  border-bottom: 1px solid var(--line);
  padding: 5px 2px;
  color: var(--ink);
}

.channel-video-choice input {
  width: auto;
  min-height: 0;
}

.channel-video-choice img {
  width: 72px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 4px;
  background: var(--surface);
}

.video-allow-mark {
  color: var(--ok);
  font-size: 11px;
  font-weight: 700;
}

.channel-video-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.channel-video-copy strong,
.channel-video-copy small {
  overflow-wrap: anywhere;
}

.channel-video-copy strong {
  font-size: 13px;
}

.channel-video-copy small {
  color: var(--muted);
  font-size: 11px;
}

.empty-state {
  margin: 0;
  color: var(--muted);
}

.access-gate {
  display: grid;
  justify-items: center;
  width: min(480px, 100%);
  margin: clamp(36px, 9vh, 96px) auto 0;
  text-align: center;
}

.access-gate > img {
  width: 82px;
  height: 82px;
  object-fit: contain;
  margin-bottom: 18px;
}

.access-gate h2 {
  font-size: 26px;
}

.access-gate > p {
  color: var(--muted);
  line-height: 1.55;
}

.access-config {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: end;
  gap: 10px;
  width: 100%;
  border: 1px solid var(--line);
  padding: 12px;
  margin: 8px 0 14px;
}

.google-signin-button {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  min-width: 190px;
}

.child-portal-main {
  margin-top: 18px;
}

.child-welcome {
  margin-bottom: 0;
  color: var(--muted);
}

.child-profile-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.child-profile-heading > div {
  min-width: 0;
}

.child-profile-heading h2 {
  overflow-wrap: anywhere;
}

.child-profile-heading span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.player-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 320px;
  gap: 16px;
  align-items: start;
}

.sidebar-panel,
.verifier-panel {
  position: sticky;
  top: 14px;
}

.sidebar-panel {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 28px);
  overflow: hidden;
}

.library-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.library-heading h3 {
  margin-bottom: 0;
}

.library-search {
  flex: 0 0 auto;
  margin-top: 10px;
}

.library-result-count {
  flex: 0 0 auto;
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.child-video-list {
  min-height: 96px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.child-video-list .video-button[hidden],
.child-video-list .empty-state[hidden],
.child-video-list .child-video-group[hidden] {
  display: none;
}

.child-video-group {
  border-bottom: 1px solid var(--line);
}

.child-video-group summary {
  display: list-item;
  padding: 10px 4px;
  cursor: pointer;
}

.child-video-group-heading {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: calc(100% - 20px);
  vertical-align: middle;
}

.child-video-group-heading strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.child-video-group-heading small {
  flex: 0 0 auto;
  color: var(--muted);
}

.child-video-group-list {
  display: grid;
  gap: 6px;
  padding-bottom: 8px;
}

.child-video-list .video-button {
  grid-template-columns: 84px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 6px;
}

.child-video-thumbnail {
  width: 84px;
  aspect-ratio: 16 / 9;
  border-radius: 4px;
  background: var(--surface);
  object-fit: cover;
}

.child-video-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.child-video-copy strong,
.child-video-copy small {
  overflow-wrap: anywhere;
}

.child-video-copy strong {
  font-size: 13px;
  line-height: 1.25;
}

.player-main {
  display: grid;
  gap: 12px;
}

.video-stage {
  width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 280px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #0b1117;
}

.youtube-frame,
.youtube-frame iframe {
  width: 100%;
  height: 100%;
}

.control-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.transport-controls {
  flex-wrap: wrap;
}

.transport-controls button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
}

.transport-controls button img {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
}

#start-video-button {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

#start-video-button img {
  filter: brightness(0) invert(1);
}

.speed-selector {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.metric-grid div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  min-height: 66px;
}

.metric-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.metric-grid strong {
  font-size: 22px;
}

.attention-box {
  display: none;
  border: 1px solid var(--gold);
  border-radius: 8px;
  background: #fff7e6;
  margin-top: 14px;
  padding: 12px;
}

.attention-box.is-active {
  display: block;
}

.attention-box p {
  color: var(--warn);
  font-weight: 700;
}

.event-feed {
  margin-top: 14px;
}

pre {
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b1117;
  color: #e6edf3;
  padding: 10px;
  font-size: 12px;
}

.events-panel {
  overflow: hidden;
}

.events-table {
  overflow: auto;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  background: #eef2f5;
  color: var(--primary);
}

td code {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 1050px) {
  .dashboard-grid,
  .player-layout {
    grid-template-columns: 1fr;
  }

  .settings-panel {
    grid-column: auto;
  }

  .settings-grid,
  .form-grid,
  .compact-form,
  .member-form,
  .profile-account-form,
  .access-config,
  .video-form {
    grid-template-columns: 1fr;
  }

  .sidebar-panel,
  .verifier-panel {
    position: static;
  }

  .sidebar-panel {
    max-height: min(680px, 70vh);
  }

  .channel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .member-item {
    grid-template-columns: minmax(180px, 1fr) auto auto;
  }

  .member-actions {
    grid-column: 1 / -1;
  }

  .member-editor {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .account-actions {
    width: 100%;
    justify-content: space-between;
  }

  .member-item {
    grid-template-columns: 1fr auto;
  }

  .member-identity,
  .member-actions {
    grid-column: 1 / -1;
  }

  .member-role {
    grid-column: 1;
  }

  .brand-logo {
    width: 46px;
    height: 46px;
    flex-basis: 46px;
  }

  h1 {
    font-size: 28px;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    flex: 0 0 auto;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .video-stage {
    min-height: 210px;
  }

  .channel-actions,
  .control-strip,
  .speed-selector {
    align-items: stretch;
    width: 100%;
  }

  .channel-actions,
  .speed-selector {
    flex-wrap: wrap;
  }

  .channel-video-choice {
    grid-template-columns: auto 56px minmax(0, 1fr);
  }

  .channel-video-choice img {
    width: 56px;
  }

  .playlist-list {
    grid-template-columns: 1fr;
  }
}
