@media (max-width: 820px) {
  html,
  body {
    overflow-x: hidden;
  }

  .app-shell {
    width: 100%;
    min-height: auto !important;
    padding: 10px !important;
  }

  .workspace {
    width: 100% !important;
    max-width: 100% !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px !important;
  }

  .control-panel {
    position: static !important;
    top: auto !important;
    width: auto !important;
    max-height: none !important;
    overflow: visible !important;
    padding: 14px !important;
    border-radius: 10px !important;
  }

  .brand-block {
    grid-template-columns: 46px minmax(0, 1fr) !important;
    gap: 11px !important;
    padding: 10px !important;
    margin-bottom: 14px !important;
  }

  .brand-mark {
    width: 46px !important;
    height: 46px !important;
  }

  .controls {
    gap: 10px !important;
  }

  button,
  input,
  select,
  textarea {
    font-size: 16px !important;
  }

  .button-stack {
    position: sticky;
    bottom: 0;
    z-index: 30;
    margin: 14px -14px -14px !important;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid #d9e5f2;
    background: rgba(248, 251, 255, 0.96);
    backdrop-filter: blur(10px);
  }

  .button-stack button {
    min-height: 46px;
  }

  .activity-panel,
  .print-preview-shell {
    min-width: 0 !important;
    width: 100% !important;
  }

  .worksheet {
    max-width: 100% !important;
    min-width: 0 !important;
    border-radius: 8px !important;
  }

  .worksheet-masthead,
  .student-strip {
    min-width: 0 !important;
  }

  .worksheet-body {
    min-width: 0 !important;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 8px !important;
  }

  .control-panel {
    padding: 12px !important;
  }

  .button-stack {
    margin-right: -12px !important;
    margin-left: -12px !important;
    margin-bottom: -12px !important;
    padding-right: 12px;
    padding-left: 12px;
  }

  .worksheet-footer {
    gap: 4px !important;
  }
}

@media print {
  html:has(.worksheet),
  html:has(.worksheet) body {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
    background: #ffffff !important;
  }

  html:has(.worksheet) .app-shell,
  html:has(.worksheet) .workspace,
  html:has(.worksheet) .activity-panel {
    width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible !important;
  }

  html:has(.worksheet) .control-panel,
  html:has(.worksheet) .button-stack,
  html:has(.worksheet) .account-widget {
    display: none !important;
  }

  html:has(.worksheet) .worksheet {
    width: 210mm !important;
    height: 297mm !important;
    min-height: 0 !important;
    max-height: 297mm !important;
    margin: 0 !important;
    overflow: hidden !important;
    page-break-before: auto !important;
    page-break-after: auto !important;
    break-before: auto !important;
    break-after: auto !important;
  }
}
