/* A touch-first editing layout. Desktop styles remain in the existing sheets. */
.display-toggles {
  display: contents;
}

.tool-danger:hover {
  color: #d84954;
  background: #fff0f0;
}

@media (max-width: 680px) {
  html,
  body,
  .app-shell,
  main {
    height: 100dvh;
  }

  body {
    overflow: hidden;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    height: 56px;
    padding: 0 12px;
    gap: 8px;
  }

  .crumb {
    min-width: 0;
    flex: 1;
  }

  .crumb > button,
  .crumb > span,
  .crumb > svg {
    display: none;
  }

  .crumb strong {
    display: block;
    max-width: none;
    overflow: hidden;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .top-actions {
    gap: 4px;
    flex: 0 0 auto;
  }

  .top-actions .save-state,
  .top-actions .icon-button {
    display: none;
  }

  .top-actions .import,
  .top-actions .export {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    font-size: 0;
  }

  .top-actions .import svg,
  .top-actions .export svg {
    width: 18px;
  }

  .workspace {
    display: block;
    overflow: hidden;
  }

  .canvas-zone {
    height: calc(100dvh - 56px - 224px);
    min-height: 300px;
  }

  .canvas-toolbar {
    height: 92px;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-rows: 48px 36px;
    gap: 0 8px;
    padding: 4px 10px;
  }

  .tool-group {
    grid-column: 1 / -1;
    grid-row: 1;
    width: 100%;
    min-width: 0;
    gap: 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .tool-group::-webkit-scrollbar {
    display: none;
  }

  .tool {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
  }

  .tool svg {
    width: 19px;
    height: 19px;
  }

  .canvas-toolbar .grid-label {
    display: flex;
    grid-column: 1;
    grid-row: 2;
    height: 30px;
    padding: 0 4px;
    gap: 4px;
    white-space: nowrap;
  }

  .canvas-toolbar .grid-label > svg:last-child {
    display: none;
  }

  .display-toggles {
    grid-column: 2;
    grid-row: 2;
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: center;
    gap: 4px;
  }

  .code-toggle {
    height: 30px;
    padding: 0 6px;
    gap: 4px;
  }

  .code-toggle input {
    width: 24px;
  }

  .zoom-group {
    grid-column: 3;
    grid-row: 2;
    gap: 1px;
  }

  .zoom-group #fitGrid,
  .zoom-group .zoom-reset,
  .zoom-group .zoom-input {
    display: none;
  }

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

  .canvas-stage {
    min-height: 0;
    padding: 18px;
    touch-action: none;
  }

  .cell {
    width: 18px;
    height: 18px;
  }

  .statusbar {
    height: 30px;
    padding: 0 12px;
  }

  .statusbar > span:first-child {
    min-width: 0;
  }

  #statusText {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .status-summary span:first-child {
    display: none;
  }

  .statusbar .status-summary > span + span {
    padding-left: 0;
    border-left: 0;
  }

  .inspector {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: 116px minmax(0, 1fr);
    width: auto;
    height: 224px;
    padding: 0;
    border-top: 1px solid var(--line);
    border-left: 0;
    background: #fffdfa;
    box-shadow: 0 -8px 24px #2a273510;
    overflow: hidden;
  }

  .inspector .project-panel,
  .inspector .legend,
  .inspector .brush-panel {
    display: none;
  }

  .inspector .panel {
    min-width: 0;
    padding: 14px 12px;
    border-bottom: 0;
  }

  .inspector .panel-title {
    margin-bottom: 10px;
  }

  .inspector .panel-title h2 {
    font-size: 12px;
  }

  .inspector .panel:nth-child(2) {
    border-right: 1px solid var(--line);
  }

  .selected-color {
    display: grid;
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .large-swatch {
    width: 36px;
    height: 36px;
  }

  .selected-color strong,
  .selected-color p {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .selected-color p {
    display: none;
  }

  .selected-color .icon-button {
    display: none;
  }

  .palette-panel {
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .palette-panel .panel-title {
    position: sticky;
    top: 0;
    z-index: 1;
    padding-top: 1px;
    background: #fffdfa;
  }

  .palette-tabs {
    gap: 14px;
    margin: 10px 0 8px;
  }

  .palette-tabs button {
    padding-bottom: 6px;
  }

  .search {
    height: 32px;
  }

  .palette-series summary {
    height: 30px;
  }

  .color-grid {
    grid-template-columns: repeat(7, 1fr);
    gap: 9px;
    padding-bottom: 11px;
  }

  .color-dot {
    width: 20px;
  }

  .shape-panel {
    top: 10px;
    left: 10px;
  }

  .selection-actions {
    position: fixed;
    right: 10px;
    bottom: 236px;
    left: auto !important;
    transform: none;
  }

  .toast {
    bottom: 238px;
    max-width: calc(100vw - 32px);
    text-align: center;
  }

  dialog {
    width: calc(100vw - 24px);
    max-height: calc(100dvh - 24px);
    overflow: auto;
  }

  dialog form {
    padding: 24px 20px;
  }
}

@media (max-width: 380px) {
  .canvas-zone {
    height: calc(100dvh - 56px - 214px);
  }

  .inspector {
    grid-template-columns: 104px minmax(0, 1fr);
    height: 214px;
  }

  .inspector .panel {
    padding-right: 9px;
    padding-left: 9px;
  }

  .statusbar {
    font-size: 11px;
  }

}
