@media (max-width: 980px) {
  .session-strip {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .session-strip__center,
  .session-strip__meta {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .workspace-main {
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .whiteboard-panel {
    min-height: 0;
  }
}

@media (max-width: 980px) {
  .history-panel {
    height: auto;
    max-height: none;
  }
}

@media (max-width: 720px) {
  .app-shell {
    --frame-padding: 12px;
    --workspace-gap: 12px;
  }

  .session-strip {
    display: none;
  }

  .session-strip-mobile {
    display: block;
    padding: 10px 12px 0;
    border-bottom: 1px solid rgba(102, 82, 56, 0.12);
    background: rgba(255, 252, 246, 0.78);
  }

  .session-strip-mobile__top,
  .session-strip-mobile__brand,
  .session-strip-mobile__actions,
  .mobile-meta-drawer__roster,
  .mobile-meta-drawer__pills {
    display: flex;
    align-items: center;
  }

  .session-strip-mobile__top {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    min-height: 44px;
  }

  .session-strip-mobile__brand,
  .session-strip-mobile__actions {
    gap: 8px;
  }

  .session-strip-mobile__room {
    min-width: 0;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .session-strip-mobile__title {
    font-size: 22px;
    font-family: var(--font-display);
    line-height: 1;
  }

  .mobile-room-code {
    min-height: 26px;
    max-width: 100%;
    padding: 0 10px;
    font-size: 10px;
  }

  .mobile-seat-pill--white,
  .mobile-seat-pill--black {
    color: var(--text-faint);
  }

  .mobile-seat-pill.is-active {
    color: var(--green);
  }

  .session-strip-mobile__versus {
    color: var(--text-faint);
    font-size: 10px;
  }

  .mobile-meta-drawer {
    display: grid;
    gap: 10px;
    padding: 10px 0 12px;
    margin-top: 10px;
    border-top: 1px solid rgba(102, 82, 56, 0.12);
  }

  .mobile-meta-drawer__summary {
    color: var(--text-soft);
    font-size: 12px;
    line-height: 1.45;
  }

  .mobile-meta-drawer__roster {
    gap: 8px;
    flex-wrap: wrap;
  }

  .mobile-meta-drawer__pills {
    gap: 8px;
    flex-wrap: wrap;
  }

  .mobile-meta-drawer__actions {
    display: flex;
  }

  .mobile-meta-drawer .mobile-seat-pill {
    min-height: 28px;
    padding: 0 12px;
    font-size: 11px;
  }

  .mobile-meta-drawer__copy {
    width: 100%;
    min-height: 38px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 10px;
    min-height: 0;
    overflow: hidden;
    padding: 10px 12px 12px;
  }

  .workspace-main {
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 10px;
    min-height: 0;
  }

  .workspace.history-expanded .workspace-main {
    grid-template-rows: auto minmax(0, 1fr);
  }

  .board-wrap,
  .capture-rail,
  .control-row--board {
    width: 100%;
  }

  .control-row--board {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .control-row--board button {
    min-height: 34px;
    padding: 0;
    border-radius: 10px;
    font-size: 0;
  }

  .control-row--board button::before {
    font-size: 13px;
    line-height: 1;
  }

  .mobile-history-bar {
    display: block;
    width: 100%;
    max-width: min(540px, 100%);
    margin-inline: auto;
    padding: 2px 0 0;
  }

  .workspace.history-expanded .mobile-history-bar {
    display: none;
  }

  .workspace.history-expanded .chess-panel {
    grid-template-rows: auto;
    gap: 0;
    height: auto;
  }

  .workspace.history-expanded .capture-rail,
  .workspace.history-expanded .board-wrap,
  .workspace.history-expanded .control-row--board {
    display: none;
  }

  .mobile-dock {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0;
    background: rgba(255, 252, 246, 0.96);
    backdrop-filter: blur(12px);
    border-top: 1px solid rgba(83, 66, 45, 0.14);
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  }

  .mobile-dock__button {
    min-height: 44px;
    border-radius: 12px;
    background: transparent;
    border: 0;
    color: var(--text-soft);
    font-size: 13px;
    font-weight: 700;
  }

  .mobile-dock__button.is-active {
    background: var(--green);
    color: #fffdf8;
  }

  .app-shell {
    padding-bottom: calc(64px + env(safe-area-inset-bottom));
  }

  .workspace.mobile-section--chess .whiteboard-panel {
    display: none;
  }

  .workspace.mobile-section--whiteboard .chess-panel,
  .workspace.mobile-section--whiteboard .history-panel,
  .workspace.mobile-section--whiteboard .workspace-main {
    display: none;
  }

  .panel-head__actions .whiteboard-tools-toggle {
    display: inline-flex;
  }

  .panel-head__actions .whiteboard-tools-toggle.is-active {
    background: var(--green);
    color: #fffdf8;
    border-color: rgba(78, 120, 89, 0.64);
  }

  .history-panel.is-collapsed {
    display: none;
  }

  .history-dock {
    width: 100%;
    gap: 8px;
  }

  .history-panel {
    display: grid;
    height: auto;
    max-height: min(40dvh, 320px);
  }

  .workspace.history-expanded .history-panel {
    max-height: none;
  }

  .history-head {
    align-items: center;
  }

  .history-head__copy {
    gap: 2px;
  }

  .history-head h2 {
    font-size: 15px;
  }

  .history-count {
    font-size: 10px;
  }

  .history-position {
    min-height: 26px;
  }

  .history-nav {
    gap: 6px;
    padding: 10px 12px 12px;
  }

  .history-nav button {
    width: 38px;
    min-width: 38px;
    min-height: 38px;
  }

  .history-toggle {
    display: none;
  }

  .history-panel.is-collapsed {
    background: rgba(255, 251, 244, 0.96);
  }

  .history-panel.is-collapsed .history-head {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: 12px;
  }

  .history-panel.is-collapsed .history-head__copy {
    min-width: 0;
  }

  .history-panel.is-collapsed .history-head__actions {
    flex-direction: row;
    margin-left: auto;
  }

  .history-panel.is-collapsed .history-position {
    display: none;
  }

  .history-panel.is-collapsed .history-toggle {
    width: auto;
  }

  .whiteboard-panel {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    height: 100%;
    padding: 10px 0 0;
    overflow: auto;
  }

  .whiteboard-panel .panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .whiteboard-panel .panel-head__copy {
    min-width: 0;
  }

  .whiteboard-panel .panel-head,
  .whiteboard-primary-controls,
  .whiteboard-toolbar {
    padding-inline: 10px;
  }

  .whiteboard-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 0 0 auto;
  }

  .whiteboard-stage-shell,
  .whiteboard-sidebar {
    display: contents;
  }

  .whiteboard-panel .panel-head h2 {
    font-size: 15px;
  }

  .whiteboard-panel .panel-head__actions {
    width: auto;
    margin-left: auto;
    flex-wrap: nowrap;
    justify-content: flex-end;
    gap: 0;
  }

  .session-strip-mobile__actions .icon-button {
    width: 34px;
    min-width: 34px;
    min-height: 34px;
    border-radius: 9px;
  }

  .whiteboard-primary-controls {
    gap: 8px;
  }

  .whiteboard-primary-controls__top {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: start;
  }

  .tool-button-rail {
    width: 100%;
    justify-content: space-between;
  }

  .whiteboard-quick-actions {
    gap: 6px;
  }

  .whiteboard-quick-actions button {
    width: 36px;
    min-width: 36px;
    min-height: 36px;
    border-radius: 10px;
  }

  .tool-button {
    width: 36px;
    height: 36px;
    min-height: 36px;
    border-radius: 10px;
  }

  .color-picker-shell {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 8px 10px;
    gap: 10px;
  }

  .palette-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .palette {
    gap: 8px;
  }

  .swatch {
    width: 22px;
    height: 22px;
    min-height: 22px;
  }

  .color-preview {
    width: 26px;
    min-width: 26px;
    height: 26px;
    border-radius: 8px;
  }

  .color-picker-copy strong {
    font-size: 11px;
  }

  .color-picker-copy span {
    font-size: 10px;
  }

  .tool-item {
    gap: 6px;
    padding: 10px 12px;
    border-radius: 14px;
  }

  .tool-label-row {
    gap: 8px;
  }

  .tool-label-row label,
  .tool-label-row output {
    font-size: 10px;
  }

  .canvas-stage {
    flex: 0 0 auto;
    width: 100%;
    max-width: none;
    min-height: 0;
    max-height: none;
    height: auto;
    align-self: stretch;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .whiteboard-toolbar {
    gap: 8px;
    flex: 0 0 auto;
    min-height: 0;
    overflow: visible;
    padding-bottom: 10px;
  }

  .palette-shell {
    gap: 8px;
    padding: 8px;
  }

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

  .whiteboard-toolbar__actions button {
    width: 100%;
    min-width: 0;
    min-height: 36px;
    border-radius: 10px;
  }

  .whiteboard-toolbar__swatches {
    gap: 6px;
    padding: 8px;
    border: 1px solid rgba(102, 82, 56, 0.12);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.62);
  }

  .whiteboard-toolbar__label {
    font-size: 10px;
  }

  .panel-head__actions .whiteboard-tools-toggle {
    display: inline-flex;
    width: auto;
    min-width: 72px;
    min-height: 34px;
    padding: 0 10px;
    margin-right: 0;
    font-size: 11px;
  }

  .session-gate {
    padding: 0;
    background: var(--frame-bg);
  }

  .session-gate__card {
    width: min(92vw, 400px);
    padding: 30px 20px 20px;
    border-radius: 18px;
  }

  .session-gate__brand h2 {
    font-size: 40px;
  }

  .promotion-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .toast-stack {
    left: 12px;
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    width: auto;
  }
}

@media (max-width: 720px) and (max-height: 700px) {
  .whiteboard-toolbar {
    max-height: min(34dvh, 220px);
    overflow: auto;
    padding-inline-end: 2px;
  }

  .tool-item {
    padding: 10px 12px;
  }

  .color-picker-shell {
    min-height: 44px;
    padding: 8px 10px;
  }

  .canvas-stage {
    max-height: none;
  }
}

@media (max-width: 720px) and (max-height: 480px) {
  .whiteboard-panel .panel-head {
    align-items: center;
  }

  .whiteboard-panel .panel-head__actions {
    width: auto;
    justify-content: flex-end;
  }

  .panel-head__actions .whiteboard-tools-toggle {
    margin-right: 0;
  }

  .whiteboard-toolbar {
    max-height: min(42dvh, 140px);
    overflow: auto;
  }

  .canvas-stage {
    max-height: none;
  }
}
