/* ==========================================================
   mobile.css — SSY Mobile Adaptation
   Only applies on screens < 768px
   Loaded after all other styles to override them
   ========================================================== */

/* ---- Hide on desktop (mobile-only elements) ---- */
.mobile-tab-bar {
  display: none;
}

/* The mobile label is an alternate label, not an additional visible label. */
.mobile-tab-label-default {
  display: none !important;
}

.mobile-tab-label-mobile {
  display: none !important;
}

/* Desktop keeps the original podium; phones use the compact list below. */
.ranking-mobile-list {
  display: none;
}

.excellent-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.excellent-subtitle {
  color: #94a3b8;
  font-size: 0.875rem;
}

.excellent-mode-switch {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: white;
}

.excellent-mode-switch button,
.excellent-date-toolbar button,
.excellent-date-chips button {
  border: 0;
  cursor: pointer;
  font: inherit;
}

.excellent-mode-switch button {
  padding: 8px 14px;
  border-radius: 8px;
  background: transparent;
  color: #64748b;
  font-size: 0.875rem;
  font-weight: 700;
}

.excellent-mode-switch button.active {
  background: linear-gradient(135deg, #a78bfa, #60a5fa);
  color: white;
}

.excellent-upload {
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid rgba(167,139,250,0.18);
  border-radius: 14px;
  background: rgba(255,255,255,0.85);
}

.excellent-upload-fields {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.excellent-field {
  flex: 1;
  min-width: 160px;
}

.excellent-field label,
.excellent-date-input span {
  display: block;
  margin-bottom: 5px;
  color: #94a3b8;
  font-size: 0.8125rem;
}

.excellent-field input {
  width: 100%;
  box-sizing: border-box;
  padding: 9px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font: inherit;
}

.excellent-image-picker {
  flex: 1;
  min-width: 180px;
  padding: 11px;
}

.excellent-image-picker img {
  max-height: 60px;
  max-width: 100%;
  border-radius: 6px;
}

.excellent-upload-button {
  padding: 10px 20px;
  border: 0;
  border-radius: 20px;
  background: linear-gradient(135deg, #a78bfa, #60a5fa);
  color: white;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
}

.excellent-date-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
  padding: 14px 16px;
  border: 1px solid rgba(167,139,250,0.18);
  border-radius: 14px;
  background: rgba(255,255,255,0.82);
}

.excellent-today-button {
  padding: 9px 15px;
  border-radius: 9px;
  background: #f3e8ff;
  color: #7c3aed;
  font-weight: 700;
}

.excellent-date-input {
  min-width: 170px;
}

.excellent-date-input input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  color: #334155;
  font: inherit;
}

.excellent-selected-date {
  align-self: center;
  color: #334155;
  font-weight: 700;
}

.excellent-date-total {
  margin-left: auto;
  align-self: center;
  color: #7c3aed;
  font-weight: 800;
}

.excellent-date-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 18px;
  padding-bottom: 3px;
  scrollbar-width: thin;
}

.excellent-date-chips button {
  flex: 0 0 auto;
  min-width: 76px;
  padding: 8px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 9px;
  background: white;
  color: #475569;
  font-size: 0.8125rem;
  font-weight: 700;
}

.excellent-date-chips button small {
  display: block;
  margin-top: 2px;
  color: #94a3b8;
  font-size: 0.7rem;
  font-weight: 600;
}

.excellent-date-chips button.active {
  border-color: transparent;
  background: linear-gradient(135deg, #a78bfa, #60a5fa);
  color: white;
}

.excellent-date-chips button.active small {
  color: rgba(255,255,255,0.82);
}

.excellent-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.excellent-card {
  overflow: hidden;
  border-radius: 14px;
  background: rgba(255,255,255,0.88);
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}

.excellent-card > img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  cursor: pointer;
}

.excellent-card-body {
  padding: 12px;
}

.excellent-card-body strong,
.excellent-card-body span,
.excellent-card-body p {
  display: block;
}

.excellent-card-body span {
  margin-top: 4px;
  color: #94a3b8;
  font-size: 0.8125rem;
}

.excellent-card-body p {
  margin: 7px 0 0;
  color: #64748b;
  font-size: 0.8125rem;
}

.excellent-delete-button {
  margin-top: 7px;
  padding: 0;
  border: 0;
  background: transparent;
  color: #ef4444;
  cursor: pointer;
  font: inherit;
  font-size: 0.8125rem;
}

.excellent-loading,
.excellent-empty {
  padding: 52px 20px;
  color: #94a3b8;
  text-align: center;
}

.excellent-empty div {
  margin-bottom: 8px;
  font-size: 42px;
}

.excellent-empty strong,
.excellent-empty span {
  display: block;
}

.excellent-empty strong {
  color: #64748b;
}

.excellent-empty span {
  margin-top: 6px;
  font-size: 0.8125rem;
}

.excellent-stats-view {
  overflow: hidden;
  border: 1px solid rgba(167,139,250,0.18);
  border-radius: 14px;
  background: rgba(255,255,255,0.82);
}

.excellent-stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(135deg, rgba(167,139,250,0.12), rgba(96,165,250,0.12));
}

.excellent-stats-header strong,
.excellent-stats-header span {
  display: block;
}

.excellent-stats-header span {
  margin-top: 4px;
  color: #94a3b8;
  font-size: 0.8125rem;
}

.excellent-stats-header b {
  color: #7c3aed;
  white-space: nowrap;
}

.excellent-stats-list {
  padding: 0 16px;
}

.excellent-stat-row {
  display: grid;
  grid-template-columns: 30px minmax(100px, 1fr) minmax(150px, 1fr) 56px;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  border-bottom: 1px solid #f1f5f9;
}

.excellent-stat-row:last-child {
  border-bottom: 0;
}

.excellent-stat-rank {
  color: #7c3aed;
  font-weight: 800;
  text-align: center;
}

.excellent-stat-dates {
  display: flex;
  gap: 5px;
  overflow: hidden;
}

.excellent-stat-dates span {
  padding: 3px 6px;
  border-radius: 6px;
  background: #f8fafc;
  color: #64748b;
  font-size: 0.75rem;
  white-space: nowrap;
}

.excellent-stat-row > b {
  color: #7c3aed;
  text-align: right;
  white-space: nowrap;
}

/* ==========================================================
   Mobile (< 768px)
   ========================================================== */
@media (max-width: 767px) {
  /* ---- Base ---- */
  html {
    font-size: 14px;
  }

  body {
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }

  /* ---- Hide left sidebar (navigation moved to bottom) ---- */
  aside.sidebar {
    display: none !important;
  }

  /* ---- Main content: full width ---- */
  .main-content {
    margin-left: 0 !important;
    padding: 10px !important;
    max-width: 100vw !important;
  }

  /* ---- Header: compact ---- */
  header > div {
    height: 52px !important;
    padding: 0 12px !important;
    gap: 10px !important;
  }

  header > div > div:first-child {
    font-size: 20px !important;
  }

  header > div > div:last-child {
    gap: 6px !important;
  }

  .header-tab {
    padding: 5px 10px !important;
    font-size: 0.875rem !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .header-btn {
    padding: 5px 10px !important;
    font-size: 0.8125rem !important;
  }

  .header-select {
    padding: 4px 8px !important;
    font-size: 0.8125rem !important;
    max-width: 90px !important;
  }

  header a[href="/admin.html"] {
    display: none !important;
  }

  /* ---- Bottom Tab Bar ---- */
  .mobile-tab-bar {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--header-bg, rgba(255,255,255,0.92));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-color, rgba(0,0,0,0.08));
    z-index: 1000;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-left: 4px;
    padding-right: 4px;
    gap: 0;
  }

  .mobile-tab-bar::-webkit-scrollbar {
    display: none;
  }

  .mobile-tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 56px;
    height: 100%;
    padding: 4px 4px;
    border: none;
    background: transparent;
    color: var(--text-secondary, #6b7280);
    font-size: 10px;
    font-weight: 600;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.2s;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    position: relative;
    font-family: 'Nunito', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  }

  .mobile-tab-item .mobile-tab-icon {
    font-size: 20px;
    line-height: 1;
  }

  .mobile-tab-item .mobile-tab-label {
    font-size: 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .mobile-tab-item.active {
    color: #a78bfa;
    background: rgba(167, 139, 250, 0.12);
  }

  .mobile-tab-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: linear-gradient(135deg, #a78bfa, #60a5fa);
    border-radius: 0 0 4px 4px;
  }

  /* ---- Homework tab layout ---- */
  div[x-data="homeworkTab()"] {
    flex-direction: column !important;
    padding: 0 !important;
    gap: 12px !important;
  }

  div[x-data="homeworkTab()"] > aside {
    width: 100% !important;
    flex-shrink: unset !important;
  }

  .glass-sidebar {
    padding: 12px !important;
  }

  .cal-day {
    width: 40px !important;
    height: 40px !important;
    font-size: 16px !important;
  }

  /* ---- Homework items ---- */
  .hw-item {
    padding: 10px 12px !important;
  }

  .hw-item img {
    width: 100% !important;
    max-height: none !important;
    border-radius: 8px;
  }

  /* Split layout: stack vertically */
  div[x-data="homeworkTab()"] > div[style*="display:flex"] {
    flex-direction: column !important;
  }

  div[x-data="homeworkTab()"] [style*="width:40%"],
  div[x-data="homeworkTab()"] [style*="width:55%"] {
    width: 100% !important;
    position: static !important;
    max-width: 100% !important;
    min-width: 0 !important;
    max-height: none !important;
  }

  /* Thumbnail grid */
  div[x-data="homeworkTab()"] [style*="grid-template-columns:repeat(2"] {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  /* ---- Add homework form ---- */
  textarea {
    font-size: 16px !important;
  }

  .upload-box {
    padding: 16px !important;
  }

  /* ---- Excellent tab ---- */
  div[x-show="activeTab==='excellent'"] [style*="grid-template-columns"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }

  /* ---- Checkin tab ---- */
  div[x-show="activeTab==='checkin'"] > div:nth-child(2) {
    gap: 6px !important;
  }

  .toggle-pill {
    padding: 6px 10px !important;
    font-size: 14px !important;
  }

  .student-btn {
    padding: 6px 10px !important;
    font-size: 15px !important;
    min-height: 44px;
    -webkit-tap-highlight-color: transparent !important;
    outline: none !important;
  }

  .student-btn:focus {
    outline: none !important;
    box-shadow: none !important;
  }

  /* ---- Ranking tab ---- */
  .ranking-container {
    display: block !important;
  }

  .ranking-group {
    padding: 10px !important;
    margin-bottom: 12px !important;
    border-radius: 14px !important;
    background: rgba(255,255,255,0.7) !important;
  }

  .ranking-group-title {
    margin-bottom: 8px !important;
    padding: 7px !important;
    font-size: 15px !important;
    border-radius: 9px !important;
  }

  .ranking-group > .rank-top3-container,
  .ranking-group > .rank-row {
    display: none !important;
  }

  .ranking-mobile-list {
    display: block !important;
  }

  .ranking-mobile-row {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr) 56px 42px;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 6px 4px;
    border-bottom: 1px solid #eef2f7;
  }

  .ranking-mobile-row:last-child {
    border-bottom: 0;
  }

  .ranking-mobile-number {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f1f5f9;
    color: #64748b;
    font-size: 12px;
    font-weight: 700;
  }

  .ranking-mobile-number.rank-gold {
    background: #fef3c7;
    color: #b45309;
  }

  .ranking-mobile-number.rank-silver {
    background: #e2e8f0;
    color: #475569;
  }

  .ranking-mobile-number.rank-bronze {
    background: #ffedd5;
    color: #c2410c;
  }

  .ranking-mobile-name {
    min-width: 0;
    overflow: hidden;
    color: #334155;
    font-size: 14px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ranking-mobile-bar {
    width: 56px;
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: #e2e8f0;
  }

  .ranking-mobile-bar .rank-bar {
    height: 100%;
  }

  .ranking-mobile-points {
    color: #7c3aed;
    font-size: 13px;
    font-weight: 700;
    text-align: right;
    white-space: nowrap;
  }

  .rank-top3-container {
    flex-direction: column !important;
    gap: 10px !important;
    padding: 16px 0 !important;
  }

  .rank-top3-item {
    min-width: auto !important;
    padding: 16px !important;
  }

  .rank-top3-item.rank-1 {
    order: -1 !important;
    transform: scale(1) !important;
    padding: 20px !important;
  }

  .rank-top3-item.rank-2 {
    order: 0 !important;
  }

  .rank-top3-item.rank-3 {
    order: 1 !important;
  }

  .rank-row-large {
    padding: 10px 12px !important;
    gap: 10px !important;
  }

  div[x-show="activeTab==='ranking'"] > div:nth-child(2) {
    padding: 12px !important;
    margin-bottom: 12px !important;
    border-radius: 14px !important;
  }

  div[x-show="activeTab==='ranking'"] > div:nth-child(2) > div:nth-child(2) {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  div[x-show="activeTab==='ranking'"] > div:nth-child(2) > div:nth-child(2)::-webkit-scrollbar {
    display: none;
  }

  div[x-show="activeTab==='ranking'"] > div:nth-child(2) button {
    flex: 0 0 auto;
    min-width: 92px;
    padding: 8px 12px !important;
    font-size: 13px !important;
  }

  div[x-show="activeTab==='ranking'"] > div:nth-child(2) button small {
    font-size: 11px !important;
  }

  div[x-show="activeTab==='ranking'"] > div:nth-child(2) > div:last-child {
    margin-top: 8px !important;
    padding-top: 8px !important;
    font-size: 12px !important;
  }

  .rank-num-large {
    width: 36px !important;
    height: 36px !important;
    font-size: 15px !important;
  }

  .rank-name-large {
    font-size: 15px !important;
    min-width: 60px !important;
  }

  .rank-score-large {
    height: 28px !important;
  }

  .rank-score-text {
    font-size: 13px !important;
  }

  /* ---- Vocabulary tab ---- */
  div[x-show="activeTab==='vocabulary'"] [style*="grid-template-columns:repeat(auto-fill,minmax(250px"] {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }

  .word-card {
    padding: 10px !important;
  }

  /* ---- Quiz tab ---- */
  div[x-show="activeTab==='quiz'"][x-data="quizTab()"] > div:first-child {
    max-width: 100% !important;
    padding: 0 !important;
  }

  div[x-show="!quizStarted"] {
    max-width: 100% !important;
    padding: 12px !important;
  }

  div[x-show="!quizStarted"] > div {
    padding: 16px !important;
  }

  div[x-show="!quizStarted"] [style*="grid-template-columns:1fr 1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  div[x-show="quizStarted"] > div:first-child {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  div[x-show="quizStarted"] [style*="font-size:3rem"],
  div[x-show="quizStarted"] [style*="font-size:56px"] {
    font-size: 2rem !important;
  }

  .quiz-ctrl {
    padding: 8px 12px !important;
    font-size: 16px !important;
  }

  .quiz-ctrl-main {
    padding: 10px 20px !important;
    font-size: 18px !important;
  }

  .quiz-ctrl-sm {
    padding: 4px 8px !important;
    font-size: 13px !important;
  }

  .word-wall-chip {
    padding: 6px 12px !important;
    font-size: 15px !important;
    margin: 0 6px 6px 0 !important;
  }

  div[x-show="quizStarted"][style*="position:fixed"] [style*="font-size:4.5rem"] {
    font-size: 2.5rem !important;
  }

  /* ---- Essay tab ---- */
  div[x-show="view==='submission'"] > div:last-child {
    grid-template-columns: 1fr !important;
  }

  .essay-card, .essay-sub-card {
    padding: 12px !important;
  }

  .essay-sub-card img {
    height: 100px !important;
  }

  /* ---- Choice fill ---- */
  .choicefill-container {
    padding: 12px !important;
  }

  .choicefill-dateinfo {
    padding: 12px !important;
    font-size: 16px !important;
    margin-bottom: 12px !important;
  }

  .choicefill-passage {
    padding: 16px !important;
    font-size: 16px !important;
    line-height: 1.8 !important;
  }

  .choicefill-blank {
    min-width: 60px !important;
  }

  .choicefill-options {
    padding: 12px !important;
    font-size: 16px !important;
  }

  .choicefill-option-item {
    padding: 8px 14px !important;
    font-size: 16px !important;
    border-radius: 16px !important;
  }

  .choicefill-answers {
    padding: 16px !important;
    font-size: 16px !important;
  }

  .choicefill-answer-item {
    padding: 10px 0 !important;
    font-size: 16px !important;
    gap: 10px !important;
  }

  .choicefill-answer-num {
    width: 40px !important;
    font-size: 18px !important;
  }

  .choicefill-answer-word {
    font-size: 18px !important;
  }

  .choicefill-explanation {
    font-size: 15px !important;
  }

  .choicefill-toggle-btn {
    padding: 12px !important;
    font-size: 18px !important;
    border-radius: 10px !important;
  }

  /* ---- Word game ---- */
  .wg-mode-cards {
    grid-template-columns: 1fr !important;
  }

  .wg-card-grid {
    gap: 8px !important;
  }

  .wg-card {
    padding: 5px 3px !important;
    border-radius: 10px !important;
    min-height: 48px !important;
  }

  /* ---- General overrides ---- */
  h2 {
    font-size: 18px !important;
  }

  input[type="text"],
  input[type="number"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px !important;
  }

  /* ---- Content font scaling (inline styles override) ---- */
  /* Main content area: scale down all large inline font sizes */
  .main-content [style*="font-size: 56px"],
  .main-content [style*="font-size:56px"] {
    font-size: 32px !important;
  }

  .main-content [style*="font-size: 48px"],
  .main-content [style*="font-size:48px"] {
    font-size: 28px !important;
  }

  .main-content [style*="font-size: 40px"],
  .main-content [style*="font-size:40px"] {
    font-size: 24px !important;
  }

  .main-content [style*="font-size: 36px"],
  .main-content [style*="font-size:36px"] {
    font-size: 24px !important;
  }

  .main-content [style*="font-size: 32px"],
  .main-content [style*="font-size:32px"] {
    font-size: 22px !important;
  }

  .main-content [style*="font-size: 28px"],
  .main-content [style*="font-size:28px"] {
    font-size: 20px !important;
  }

  .main-content [style*="font-size: 26px"],
  .main-content [style*="font-size:26px"] {
    font-size: 18px !important;
  }

  .main-content [style*="font-size: 24px"],
  .main-content [style*="font-size:24px"] {
    font-size: 16px !important;
  }

  .main-content [style*="font-size: 22px"],
  .main-content [style*="font-size:22px"] {
    font-size: 16px !important;
  }

  .main-content [style*="font-size: 20px"],
  .main-content [style*="font-size:20px"] {
    font-size: 15px !important;
  }

  .main-content [style*="font-size: 18px"],
  .main-content [style*="font-size:18px"] {
    font-size: 14px !important;
  }

  /* Login modal font scaling */
  div[x-show="loginModalOpen"] [style*="font-size: 28px"],
  div[x-show="loginModalOpen"] [style*="font-size:28px"] {
    font-size: 20px !important;
  }

  div[x-show="loginModalOpen"] [style*="font-size: 24px"],
  div[x-show="loginModalOpen"] [style*="font-size:24px"] {
    font-size: 16px !important;
  }

  div[x-show="loginModalOpen"] [style*="font-size: 18px"],
  div[x-show="loginModalOpen"] [style*="font-size:18px"] {
    font-size: 15px !important;
  }

  /* Toast notifications */
  div[x-show*="toasts"] [style*="font-size: 24px"],
  div[x-show*="toasts"] [style*="font-size:24px"] {
    font-size: 15px !important;
  }

  .bg-blob-1 {
    width: 200px !important;
    height: 200px !important;
  }

  .bg-blob-2 {
    width: 150px !important;
    height: 150px !important;
  }

  .bg-blob-3 {
    width: 120px !important;
    height: 120px !important;
  }

  [data-theme="dark"] .bg-blob {
    opacity: 0.15 !important;
  }

  [style*="resize:horizontal"] {
    resize: none !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  div[style*="max-width:400px"] {
    max-width: 92vw !important;
  }

  #hwLightbox img {
    max-width: 95vw !important;
    max-height: 85vh !important;
  }

  div[x-show="loginModalOpen"] > div {
    width: 92vw !important;
    max-width: 360px !important;
    padding: 24px !important;
  }

  button, .btn, .toggle-pill, .student-btn, .date-item, .cal-day {
    min-height: 44px;
  }

  @media (prefers-reduced-motion: reduce) {
    .bg-blob {
      display: none !important;
    }
  }
}

/* Excellent homework: keep desktop cards readable across wide monitors. */
@media (min-width: 1400px) {
  .excellent-gallery {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    max-width: 1320px;
  }
}

@media (min-width: 1025px) and (max-width: 1399px) {
  .excellent-gallery {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 768px) and (max-width: 1024px) {
  .excellent-gallery {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.excellent-card,
.excellent-card > img {
  min-width: 0;
}

/* ==========================================================
   Tablet (768px - 1024px)
   ========================================================== */
@media (min-width: 768px) and (max-width: 1024px) {
  aside.sidebar {
    width: 60px !important;
  }

  .sidebar-tab span:not(.sidebar-tab-icon) {
    display: none !important;
  }

  .main-content {
    margin-left: 60px !important;
  }

  header > div {
    gap: 12px !important;
    padding: 0 16px !important;
  }

  .header-tab {
    padding: 6px 12px !important;
    font-size: 16px !important;
  }

  div[x-data="homeworkTab()"] > aside {
    width: 220px !important;
  }
}

/* ==========================================================
   Mobile hardening overrides
   These rules must load after the page's inline styles.
   ========================================================== */
@media (max-width: 767px) {
  body {
    overflow-x: hidden !important;
    padding-bottom: calc(112px + env(safe-area-inset-bottom)) !important;
  }

  .main-content {
    padding-bottom: 120px !important;
  }

  /* Give the homework content more of the first viewport. */
  .glass-sidebar {
    padding: 8px !important;
  }

  .glass-sidebar .cal-day {
    width: 32px !important;
    height: 32px !important;
    min-height: 0 !important;
    font-size: 14px !important;
  }

  /* Keep all ten destinations discoverable without tiny horizontal scrolling. */
  .mobile-tab-bar {
    display: grid !important;
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    grid-template-rows: repeat(2, minmax(0, 1fr)) !important;
    height: calc(112px + env(safe-area-inset-bottom)) !important;
    padding: 0 4px env(safe-area-inset-bottom) !important;
    overflow: hidden !important;
    z-index: 100 !important;
  }

  .mobile-tab-item {
    min-width: 0 !important;
    max-width: none !important;
    width: 100% !important;
    min-height: 44px !important;
    height: 100% !important;
    padding: 5px 2px !important;
    font-size: 11px !important;
  }

  .mobile-tab-item .mobile-tab-icon {
    font-size: 20px !important;
  }

  .mobile-tab-item .mobile-tab-label {
    font-size: 11px !important;
    line-height: 1.2 !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }

  .mobile-tab-label-default {
    display: none !important;
  }

  .mobile-tab-label-mobile {
    display: block !important;
  }

  /* Long English homework text must be allowed to shrink and wrap. */
  .hw-item > div:first-child {
    min-width: 0 !important;
  }

  .hw-item > div:first-child > span {
    flex: 1 1 auto !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-wrap: anywhere !important;
    word-break: break-word !important;
    white-space: pre-wrap !important;
  }

  /* Mobile-only learning menu; desktop sidebar and routes are unchanged. */
  .mobile-learning-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    align-items: flex-end;
    justify-content: center;
    padding: 12px;
    background: rgba(15, 23, 42, 0.38);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
  }

  .mobile-learning-sheet {
    width: min(100%, 520px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    box-sizing: border-box;
    padding: 18px 14px calc(14px + env(safe-area-inset-bottom));
    border-radius: 18px 18px 12px 12px;
    background: #ffffff;
    box-shadow: 0 -10px 35px rgba(15, 23, 42, 0.18);
  }

  .mobile-learning-sheet-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 0 4px 12px;
  }

  .mobile-learning-sheet-title {
    color: #1e293b;
    font-size: 20px;
    font-weight: 800;
  }

  .mobile-learning-sheet-subtitle {
    margin-top: 3px;
    color: #64748b;
    font-size: 13px;
  }

  .mobile-learning-close {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    color: #64748b;
    font-size: 28px;
    line-height: 1;
  }

  .mobile-learning-options {
    display: grid;
    gap: 8px;
  }

  .mobile-learning-option {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 64px;
    box-sizing: border-box;
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #ffffff;
    color: #1e293b;
    text-align: left;
    text-decoration: none;
  }

  .mobile-learning-option:active {
    background: #f8fafc;
  }

  .mobile-learning-option-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 10px;
    background: #f3e8ff;
    font-size: 21px;
  }

  .mobile-learning-option-copy {
    display: flex;
    flex: 1;
    min-width: 0;
    flex-direction: column;
    gap: 3px;
  }

  .mobile-learning-option-copy strong {
    font-size: 16px;
    font-weight: 700;
  }

  .mobile-learning-option-copy small {
    overflow: hidden;
    color: #64748b;
    font-size: 12px;
    line-height: 1.35;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-learning-option-arrow {
    flex: 0 0 auto;
    color: #94a3b8;
    font-size: 26px;
    line-height: 1;
  }

  /* Stack presentation and image preview panels on narrow screens. */
  [x-show="$store.homeworkPresentation?.active"] {
    padding: calc(16px + env(safe-area-inset-top)) 12px
      calc(16px + env(safe-area-inset-bottom)) !important;
  }

  [x-show="$store.homeworkPresentation?.active"] > div[style*="display:flex"] {
    flex-direction: column !important;
    gap: 12px !important;
  }

  [x-show="$store.homeworkPresentation?.active"] [style*="flex:0 1 44%"] {
    flex: 1 1 auto !important;
    width: 100% !important;
  }

  div[x-data="homeworkTab()"] [style*="width:40%"],
  div[x-data="homeworkTab()"] [style*="width:55%"] {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    position: static !important;
    resize: none !important;
  }

  /* The image split wrapper is nested inside the tab, so target it directly. */
  div[x-show*="items.length>0"] > div[style*="display:flex"] {
    display: flex !important;
    flex-direction: column !important;
    width: 100% !important;
    max-width: 100% !important;
    gap: 10px !important;
  }

  div[x-show*="items.length>0"] .hw-list {
    width: 100% !important;
    max-height: none !important;
    overflow: visible !important;
  }

  /* Open a clicked homework image inside the phone viewport. */
  div[x-show*="items.length>0"] .img-preview-panel {
    position: fixed !important;
    inset: calc(12px + env(safe-area-inset-top)) 12px
      calc(12px + env(safe-area-inset-bottom)) !important;
    z-index: 1200 !important;
    width: auto !important;
    max-width: none !important;
    min-width: 0 !important;
    max-height: none !important;
    box-sizing: border-box !important;
    padding: 12px !important;
    overflow: auto !important;
    border-radius: 16px !important;
    background: rgba(255, 255, 255, 0.98) !important;
  }

  div[x-show*="items.length>0"] .img-preview-panel > img {
    display: block !important;
    width: auto !important;
    height: auto !important;
    max-width: 100% !important;
    max-height: calc(100dvh - 92px) !important;
    margin: 0 auto !important;
    object-fit: contain !important;
  }

  /* Make the quiz setup and fullscreen controls usable by touch. */
  div[x-show="!quizStarted"] [style*="grid-template-columns:1fr 1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
  }

  div[x-show="quizStarted"][style*="position:fixed"] {
    z-index: 300 !important;
    padding: calc(16px + env(safe-area-inset-top)) 12px
      calc(16px + env(safe-area-inset-bottom)) !important;
  }

  /* Narrow login modal without width-plus-padding overflow. */
  div[x-show="loginModalOpen"] > div {
    box-sizing: border-box !important;
    width: calc(100vw - 24px) !important;
    max-width: 360px !important;
    padding: 20px !important;
  }

  div[x-show="loginModalOpen"] > div > div:last-child {
    flex-wrap: wrap !important;
  }

  div[x-show="loginModalOpen"] > div > div:last-child button {
    flex: 1 1 120px !important;
    min-width: 0 !important;
  }

  /* Prevent the choice-fill page from using desktop-sized typography. */
  .choicefill-container {
    padding: 12px !important;
  }

  .choicefill-passage,
  .choicefill-options {
    padding: 16px !important;
    font-size: 18px !important;
    line-height: 1.8 !important;
  }

  .choicefill-option-item {
    padding: 10px 14px !important;
    font-size: 16px !important;
    border-width: 2px !important;
  }

  .choicefill-answers {
    padding: 16px !important;
    font-size: 16px !important;
  }

  .choicefill-answer-item {
    gap: 8px !important;
    padding: 12px 0 !important;
    font-size: 16px !important;
    align-items: flex-start !important;
  }

  .choicefill-answer-num {
    width: 28px !important;
    font-size: 18px !important;
  }

  .choicefill-answer-word {
    margin-right: 4px !important;
    font-size: 18px !important;
  }

  .choicefill-explanation {
    font-size: 15px !important;
  }

  .choicefill-toggle-btn {
    min-height: 44px !important;
    padding: 12px !important;
    font-size: 18px !important;
  }

  /* History dialog: keep the date control and word cards within the viewport. */
  div[x-show="showHistoryModal"] > div {
    width: calc(100vw - 24px) !important;
    max-height: 88vh !important;
  }

  div[x-show="showHistoryModal"] > div > div:nth-child(2) {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    align-items: center !important;
  }

  div[x-show="showHistoryModal"] [style*="minmax(180px,1fr)"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  /* Rankings: show the useful mobile columns without a 640px table. */
  div[x-show="!leaderboardLoading && leaderboardData.length>0"] {
    overflow-x: hidden !important;
  }

  div[x-show="!leaderboardLoading && leaderboardData.length>0"] table {
    min-width: 0 !important;
    table-layout: fixed !important;
    font-size: 0.78rem !important;
  }

  div[x-show="!leaderboardLoading && leaderboardData.length>0"] th,
  div[x-show="!leaderboardLoading && leaderboardData.length>0"] td {
    padding: 8px 3px !important;
    white-space: normal !important;
    word-break: break-word !important;
  }

  div[x-show="!leaderboardLoading && leaderboardData.length>0"] th:nth-child(4),
  div[x-show="!leaderboardLoading && leaderboardData.length>0"] th:nth-child(5),
  div[x-show="!leaderboardLoading && leaderboardData.length>0"] th:nth-child(6),
  div[x-show="!leaderboardLoading && leaderboardData.length>0"] th:nth-child(7),
  div[x-show="!leaderboardLoading && leaderboardData.length>0"] td:nth-child(4),
  div[x-show="!leaderboardLoading && leaderboardData.length>0"] td:nth-child(5),
  div[x-show="!leaderboardLoading && leaderboardData.length>0"] td:nth-child(6),
  div[x-show="!leaderboardLoading && leaderboardData.length>0"] td:nth-child(7) {
    display: none !important;
  }

  /* Essay and exam controls should use the full phone width. */
  div[x-show="showCreateForm"] [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  div[x-show="isAdmin"] [style*="min-width:200px"] {
    min-width: 0 !important;
    width: 100% !important;
  }

  /* Excellent homework: keep date controls and cards easy to scan on phones. */
  .excellent-heading {
    display: block;
    margin-bottom: 12px;
  }

  .excellent-heading h2 {
    margin-bottom: 3px !important;
    font-size: 22px !important;
  }

  .excellent-subtitle {
    font-size: 12px;
  }

  .excellent-mode-switch {
    width: 100%;
    margin-top: 12px;
  }

  .excellent-mode-switch button {
    flex: 1;
    min-height: 40px;
  }

  .excellent-upload {
    padding: 12px;
  }

  .excellent-upload-fields {
    display: grid;
    grid-template-columns: 1fr;
  }

  .excellent-field,
  .excellent-image-picker {
    width: 100%;
    min-width: 0;
  }

  .excellent-upload-button {
    width: 100%;
    min-height: 42px;
  }

  .excellent-date-toolbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: end;
    gap: 9px;
    padding: 12px;
  }

  .excellent-date-input {
    min-width: 0;
  }

  .excellent-selected-date {
    grid-column: 1 / 2;
    align-self: center;
    font-size: 13px;
  }

  .excellent-date-total {
    grid-column: 2 / 3;
    margin-left: 0;
    align-self: center;
    font-size: 13px;
  }

  .excellent-date-chips {
    margin-bottom: 12px;
  }

  .excellent-gallery {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .excellent-card > img {
    aspect-ratio: 16 / 10;
  }

  .excellent-stats-header {
    padding: 13px;
  }

  .excellent-stats-list {
    padding: 0 12px;
  }

  .excellent-stat-row {
    grid-template-columns: 25px minmax(0, 1fr) 52px;
    gap: 8px;
    min-height: 50px;
  }

  .excellent-stat-dates {
    display: none;
  }

  .excellent-stat-row > b {
    font-size: 13px;
  }
}
