/* Shared touch-first layout for the Sketch site. Desktop composition is unchanged. */
.mobile-workbench-tabs {
  display: none;
}

.blog-column-ai {
  display: none !important;
}

@media (max-width: 820px) {
  :root {
    --mobile-gutter: max(12px, env(safe-area-inset-left));
    --mobile-bottom: max(12px, env(safe-area-inset-bottom));
  }

  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
    -webkit-text-size-adjust: 100%;
  }

  button,
  a,
  input,
  textarea {
    touch-action: manipulation;
  }

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

  /* Home and blog shelf */
  .site-shell {
    padding-inline: var(--mobile-gutter) !important;
  }

  .site-nav {
    gap: 14px;
  }

  .nav-links {
    scrollbar-width: none;
  }

  .nav-links::-webkit-scrollbar {
    display: none;
  }

  .all-posts-panel {
    overflow: visible !important;
  }

  .all-post-category {
    padding-inline: 8px !important;
  }

  .all-post-books.all-post-books--cells {
    display: flex !important;
    grid-template-columns: none !important;
    grid-template-rows: none !important;
    gap: 14px !important;
    width: 100%;
    overflow-x: auto !important;
    overflow-y: hidden;
    padding: 18px 12px 28px !important;
    scroll-padding-inline: 12px;
    scroll-snap-type: x mandatory;
    scrollbar-width: thin;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .all-post-books--cells::before,
  .all-post-books--cells::after {
    display: none !important;
  }

  .all-post-books--cells .all-post-cell {
    flex: 0 0 min(312px, calc(100vw - 64px));
    min-width: min(312px, calc(100vw - 64px));
    scroll-snap-align: center;
  }

  .all-post-books--cells .all-post-bay,
  .all-post-books--cells .all-post-cell--full .all-post-bay {
    grid-template-columns: repeat(4, minmax(58px, 1fr)) !important;
    gap: 18px 8px !important;
  }

  /* Article */
  .post-top-row {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
  }

  .post-top-row .back-link,
  .post-edit-button {
    min-height: 44px;
  }

  .post-top-row .back-link {
    width: fit-content;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .post-edit-button {
    margin: 0 !important;
  }

  .post-paper {
    overflow: visible !important;
  }

  .post-content pre,
  .post-content .table-wrap,
  .post-content .katex-display,
  .post-content mjx-container[display="true"] {
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .reader-assistant-launcher {
    right: 14px !important;
    bottom: var(--mobile-bottom) !important;
    min-width: 74px;
    min-height: 44px;
  }

  .reader-assistant {
    inset: auto 0 0 !important;
    width: 100vw !important;
    height: min(78dvh, 680px) !important;
    max-height: calc(100dvh - env(safe-area-inset-top) - 8px);
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 24px 24px 0 0 !important;
    box-shadow: 0 -7px 0 #2d2d2d !important;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .reader-assistant header,
  .reader-assistant form {
    padding-inline: 14px;
  }

  .reader-assistant header button,
  .reader-assistant form button {
    min-width: 44px;
    min-height: 44px;
  }

  .reader-assistant textarea {
    min-height: 48px;
    font-size: 16px !important;
  }

  body.is-reader-assistant-open {
    overflow: hidden;
  }

  .selection-ai-action {
    min-height: 44px;
    padding: 0 14px;
  }

  .post-edit-modal {
    align-items: flex-end;
    padding: 0;
  }

  .post-edit-dialog {
    width: 100%;
    max-width: none;
    border-radius: 24px 24px 0 0;
    padding: 28px 20px max(24px, env(safe-area-inset-bottom));
  }

  /* Create */
  .admin-chrome {
    grid-template-columns: minmax(0, 1fr) auto !important;
    gap: 8px 12px !important;
    padding: 10px 12px !important;
  }

  .admin-chrome .admin-status {
    justify-self: end;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .admin-chrome .chrome-actions {
    grid-column: 1 / -1;
    justify-content: stretch !important;
    flex-wrap: nowrap !important;
    gap: 7px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  .admin-chrome .chrome-actions::-webkit-scrollbar {
    display: none;
  }

  .admin-chrome .admin-button {
    flex: 1 0 auto;
    min-height: 42px;
  }

  .admin-login {
    width: calc(100% - 24px) !important;
    margin-top: 12vh !important;
    padding: 24px 20px !important;
  }

  .admin-workbench,
  .admin-workbench.is-sidebar-collapsed {
    display: block !important;
    width: 100% !important;
    padding: 0 12px calc(24px + env(safe-area-inset-bottom)) !important;
  }

  .mobile-workbench-tabs {
    position: sticky;
    top: 0;
    z-index: 55;
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin: 0 -12px 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--writer-line);
    background: rgba(251, 250, 247, .96);
    backdrop-filter: blur(12px);
  }

  .mobile-workbench-tabs button {
    min-height: 42px;
    border: 2px solid var(--writer-ink);
    border-radius: 9px 11px 8px 10px;
    background: #fffdfa;
    color: var(--writer-ink);
    font: 750 13px/1 var(--ui-font);
  }

  .mobile-workbench-tabs button[aria-selected="true"] {
    background: #ffe66d;
    box-shadow: 3px 3px 0 var(--writer-ink);
  }

  .admin-workbench[data-mobile-view="write"] .admin-sidebar,
  .admin-workbench[data-mobile-view="preview"] .admin-sidebar,
  .admin-workbench[data-mobile-view="details"] .admin-document {
    display: none !important;
  }

  .admin-workbench[data-mobile-view="details"] .admin-sidebar {
    display: block !important;
  }

  .admin-workbench[data-mobile-view="write"] .admin-document,
  .admin-workbench[data-mobile-view="preview"] .admin-document {
    display: grid !important;
  }

  .admin-sidebar {
    position: static !important;
    width: 100%;
    max-height: none !important;
    margin: 0 0 16px;
    padding: 20px 18px 24px !important;
    border-width: 3px !important;
    box-shadow: 7px 7px 0 #30302e !important;
  }

  .admin-sidebar .document-title-row input {
    font-size: 32px !important;
  }

  .admin-document {
    width: 100% !important;
    min-height: calc(100dvh - 176px) !important;
    height: calc(100dvh - 176px);
    padding: 7px !important;
    border-radius: 16px 20px 18px 19px !important;
    box-shadow: 5px 5px 0 rgba(45, 45, 45, .9) !important;
  }

  .editor-grid,
  .admin-workbench.is-preview-open .editor-grid {
    display: block !important;
    min-height: 100%;
    height: 100%;
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden;
  }

  .markdown-pane,
  .preview-pane {
    width: 100%;
    height: 100%;
    min-height: 100%;
    border: 0 !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .admin-workbench[data-mobile-view="preview"] .markdown-pane {
    display: none !important;
  }

  .admin-workbench[data-mobile-view="preview"] .preview-pane {
    display: block !important;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .admin-workbench[data-mobile-view="write"] .preview-pane {
    display: none !important;
  }

  .rich-editor {
    min-height: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden;
  }

  .rich-editor .toastui-editor-defaultUI {
    min-height: 100%;
    height: 100% !important;
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .rich-editor .toastui-editor-main {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: auto !important;
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .rich-editor .toastui-editor-main-container {
    min-height: 0 !important;
    height: 100% !important;
    min-width: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  .rich-editor .toastui-editor-toolbar {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .rich-editor .toastui-editor-toolbar::-webkit-scrollbar {
    display: none;
  }

  .rich-editor .toastui-editor-defaultUI-toolbar {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    flex-wrap: nowrap;
  }

  .rich-editor .toastui-editor-contents,
  .rich-editor .ProseMirror,
  .markdown-source,
  .admin-preview-body {
    width: calc(100% - 28px) !important;
    max-width: none !important;
    padding-top: 28px !important;
    padding-bottom: 92px !important;
    font-size: 17px !important;
  }

  .paste-hint {
    display: none;
  }

  .image-drag-handle {
    width: 36px !important;
    height: 36px !important;
  }

  .image-drag-handle.is-nw { left: -20px !important; top: -20px !important; }
  .image-drag-handle.is-ne { right: -20px !important; top: -20px !important; }
  .image-drag-handle.is-se { right: -20px !important; bottom: -20px !important; }

  .image-drag-label {
    left: 20px !important;
    top: -48px !important;
    max-width: calc(100vw - 64px);
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

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