/* Shared responsive guardrails for the student, teacher and whiteboard surfaces. */
html[data-theme] #app,
html[data-theme] .shell,
html[data-theme] .shell > .main,
html[data-theme] .student-shell,
html[data-theme] .student-main,
html[data-theme] .play-page,
html[data-theme] .play-body {
  min-width: 0;
}

html[data-theme] :is(.panel, .analytics-panel, .teacher-student-card, .question-row, .lesson-card, .task-card) {
  min-width: 0;
}

html[data-theme] :is(.shell .main, .student-main, .play-page) {
  padding-inline: clamp(14px, 2.2vw, 36px);
}

html[data-theme] :is(.shell .main, .student-main) > * {
  max-width: 100%;
}

/* Tablet portrait: keep teacher content wide enough for filters and data cards. */
@media (min-width: 601px) and (max-width: 900px) {
  html[data-theme] .shell {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  html[data-theme] .shell .sidebar {
    padding: 20px 8px 14px;
  }

  html[data-theme] .shell .sidebar .brand {
    justify-content: center;
    padding: 0 0 24px;
  }

  html[data-theme] .shell .sidebar .nav {
    min-width: 0;
  }

  html[data-theme] .shell .sidebar .nav a {
    justify-content: center;
    min-height: 46px;
    padding: 10px 8px;
  }

  html[data-theme] .shell .main {
    padding-inline: clamp(16px, 2.5vw, 24px);
  }

  html[data-theme] .shell .topbar {
    min-height: 66px;
    height: auto;
    gap: 10px;
    flex-wrap: wrap;
    padding-block: 10px;
  }

  html[data-theme] .shell .top-actions {
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  html[data-theme] .shell .analytics-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  html[data-theme] .teacher-student-toolbar {
    flex-wrap: wrap;
  }

  html[data-theme] .teacher-student-toolbar input {
    flex: 1 1 280px;
  }
}

/* Portrait tablets keep short labels under each icon; landscape tablets keep the compact rail. */
@media (min-width: 601px) and (max-width: 900px) and (min-height: 621px) {
  html[data-theme] .shell .sidebar .nav-label {
    display: none;
  }

  html[data-theme] .shell .sidebar .nav a {
    position: relative;
    flex-direction: column;
    gap: 2px;
    min-height: 52px;
    padding: 5px 2px;
  }

  html[data-theme] .shell .sidebar .nav a span {
    display: block;
    font-size: 11px;
    line-height: 1.2;
    white-space: nowrap;
  }

  html[data-theme] .shell .sidebar .nav a.active::after {
    position: absolute;
    top: 7px;
    right: 8px;
    margin: 0;
  }
}

/* Phones: put teacher navigation on its own scrollable, labelled row. */
@media (max-width: 600px) {
  html[data-theme] .shell .sidebar {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "brand" "nav";
    gap: 8px;
    height: auto;
    padding: 11px 14px 8px;
    overflow: visible;
  }

  html[data-theme] .shell .sidebar .brand {
    grid-area: brand;
    justify-content: flex-start;
    gap: 9px;
    padding: 0;
    font-size: 17px;
  }

  html[data-theme] .shell .sidebar .brand > span:not(.brand-mark) {
    display: block;
  }

  html[data-theme] .shell .sidebar .brand small {
    display: none;
  }

  html[data-theme] .shell .sidebar .nav-label,
  html[data-theme] .shell .sidebar-bottom {
    display: none;
  }

  html[data-theme] .shell .sidebar .nav {
    grid-area: nav;
    display: flex;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    gap: 5px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 1px 1px 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--primary) transparent;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  html[data-theme] .shell .sidebar .nav::-webkit-scrollbar { height: 4px; }
  html[data-theme] .shell .sidebar .nav::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 2px; }

  html[data-theme] .shell .sidebar .nav a {
    display: inline-flex;
    flex: 0 0 auto;
    gap: 7px;
    min-height: 42px;
    padding: 8px 11px;
    white-space: nowrap;
  }

  html[data-theme] .shell .sidebar .nav a span {
    display: inline-flex;
    font-size: 12px;
  }

  html[data-theme] .shell .sidebar .nav a.active::after {
    display: none;
  }

  html[data-theme] .shell .main {
    padding: 0 15px 28px;
  }

  html[data-theme] .shell .topbar {
    min-height: 58px;
    height: auto;
    gap: 8px;
    margin-bottom: 18px;
    padding: 8px 0;
  }

  html[data-theme] .shell .page-heading {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 18px;
  }

  html[data-theme] .shell .page-heading > div:first-child {
    flex: 1 1 100%;
    min-width: 0;
  }

  html[data-theme] .shell .hero-copy {
    max-width: 100%;
  }

  html[data-theme] .teacher-student-toolbar {
    align-items: stretch;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
  }

  html[data-theme] .teacher-student-toolbar input {
    flex: 1 1 100%;
    width: 100%;
  }

  html[data-theme] .teacher-student-toolbar > span {
    align-self: center;
  }

  html[data-theme] .teacher-student-toolbar > .btn {
    width: auto;
    margin-left: auto;
  }

  html[data-theme] .analytics-table {
    overflow: visible;
  }

  html[data-theme] .analytics-table-head {
    display: none;
  }

  html[data-theme] .analytics-table-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 0;
    gap: 9px 14px;
    margin-bottom: 8px;
    padding: 12px 10px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--primary);
    background: var(--surface-soft);
  }

  html[data-theme] .analytics-table-row > span {
    grid-column: 1 / -1;
    overflow: visible;
    white-space: normal;
    font-size: 14px;
  }

  html[data-theme] .analytics-table-row > strong {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
    min-width: 0;
    white-space: normal;
    font-size: 15px;
  }

  html[data-theme] .analytics-table-row > strong::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
  }
}

/* Very short desktop displays: the teacher menu stays independently scrollable. */
@media (min-width: 601px) and (max-height: 620px) {
  html[data-theme] .shell .sidebar {
    height: 100dvh;
    overflow-y: auto;
    padding-block: 12px;
  }

  html[data-theme] .shell .sidebar .brand {
    padding-bottom: 12px;
  }

  html[data-theme] .shell .sidebar .nav {
    gap: 1px;
  }

  html[data-theme] .shell .sidebar .nav a {
    min-height: 40px;
    padding-block: 7px;
  }

  html[data-theme] .shell .sidebar-tip {
    display: none;
  }
}

/* On extra-wide desktops, use more of the screen while keeping readable line lengths. */
@media (min-width: 1920px) {
  html[data-theme] .shell .main {
    max-width: 1760px;
  }
}
