@media (max-width: 1279px) {
  .app-shell {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
  }

  .app-shell.layout-tablet .side-panel,
  .app-shell.layout-mobile .side-panel {
    position: absolute;
    inset: 0 0 0 auto;
    width: min(100%, 360px);
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 0;
    z-index: 4;
    transform: translateX(100%);
    transition: transform 180ms cubic-bezier(0.2, 0, 0, 1);
  }

  .app-shell.history-open.layout-tablet .side-panel,
  .app-shell.history-open.layout-mobile .side-panel {
    transform: translateX(0);
  }
}

@media (max-width: 767px) {
  .topbar {
    padding-left: 8px;
    padding-right: 8px;
  }

  .topbar-title h2 {
    font-size: 1.3rem;
  }

  .form-grid,
  .converter-grid,
  .date-grid,
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .button-grid.scientific,
  .button-grid.programmer {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .memory-toolbar {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .scientific-angle-operators {
    justify-content: start;
  }

  .programmer-control-row {
    gap: 0.5rem;
  }

  .programmer-memory-actions {
    margin-left: auto;
  }
}

@media (max-width: 540px) {
  .window-control {
    width: 40px;
  }

  .app-shell {
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }

  .display-panel {
    min-height: 120px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .memory-toolbar {
    font-size: 0.82rem;
  }

  .button-grid.standard,
  .button-grid.scientific,
  .button-grid.programmer {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .calculator-layout.programmer .button-grid.programmer {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .programmer-operator-groups {
    flex-wrap: wrap;
    gap: 0.9rem;
  }

  .programmer-group-button {
    font-size: 0.88rem;
  }

  .calc-button {
    min-height: 50px;
    font-size: 1rem;
  }

  .display-value {
    font-size: clamp(2.8rem, 15vw, 4.4rem);
  }
}

@media (max-width: 320px) and (max-height: 520px) {
  .topbar {
    padding: 6px 12px 0;
  }

  .topbar-title {
    gap: 8px;
  }

  .topbar-title h2 {
    font-size: 1.08rem;
  }

  .mode-title-row {
    gap: 8px;
  }

  .mode-glyph {
    width: 16px;
    height: 16px;
  }

  .icon-button {
    width: 28px;
    height: 28px;
    border-radius: 6px;
  }

  .main-panel {
    padding: 0 3px 3px;
  }

  .display-panel {
    min-height: 92px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .display-expression {
    min-height: 0.9rem;
    font-size: 0.82rem;
  }

  .display-value {
    min-height: 3.5rem;
    font-size: clamp(3.45rem, 18vw, 4.7rem);
  }

  .memory-toolbar {
    padding: 0 6px 4px;
    font-size: 0.72rem;
  }

  .memory-toolbar button {
    min-height: 22px;
    padding: 0.1rem 0.2rem;
  }

  .button-grid {
    padding: 0 4px 4px;
  }

  .calc-button {
    min-height: 0;
    font-size: 0.98rem;
    border-radius: 3px;
  }
}

@media (min-width: 420px) and (max-width: 500px) and (min-height: 880px) {
  .desktop-shell {
    justify-content: stretch;
    align-items: stretch;
  }

  .app-shell {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    height: 100vh;
    height: 100dvh;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .topbar {
    padding: 10px 14px 2px;
  }

  .topbar-title h2 {
    font-size: 1.15rem;
  }

  .mode-title-row {
    gap: 8px;
  }

  .mode-glyph {
    width: 16px;
    height: 16px;
  }

  .icon-button {
    width: 30px;
    height: 30px;
  }

  .display-panel {
    min-height: 206px;
    padding: 0 14px 8px;
  }

  .display-expression {
    min-height: 1.25rem;
    font-size: 0.96rem;
  }

  .display-value {
    min-height: 4.8rem;
    font-size: clamp(4.7rem, 17vw, 5.35rem);
  }

  .memory-toolbar {
    padding: 0 6px 8px;
  }

  .memory-toolbar button {
    min-height: 28px;
    font-size: 0.88rem;
  }

  .button-grid {
    padding: 0 4px 4px;
  }

  .calc-button {
    border-radius: 4px;
  }
}
