/* Phone workspace: canvas stays primary; resources and properties become sheets. */

@media (max-width: 760px) {
  html,
  body {
    width: 100%;
    height: 100%;
    max-width: 100%;
    overflow: hidden;
  }

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

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

  .primary-button,
  .quiet-button,
  .icon-button,
  .small-icon-button {
    min-height: 44px;
  }

  .editor-shell {
    height: 100dvh;
    grid-template-rows: 56px minmax(0, 1fr);
  }

  .editor-topbar {
    z-index: 60;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: max(6px, env(safe-area-inset-top)) 10px 6px;
  }

  .file-identity strong {
    font-size: 10px;
  }

  .file-identity span {
    font-size: 9px;
  }

  .stage-crumbs,
  .save-state,
  .topbar-actions .icon-button,
  .topbar-actions .quiet-button {
    display: none !important;
  }

  .topbar-actions .primary-button {
    min-height: 40px;
    padding-inline: 14px;
    font-size: 11px;
  }

  .editor-body {
    display: block;
    min-width: 0;
    min-height: 0;
  }

  .canvas-stage {
    position: absolute;
    inset: 56px 0 calc(64px + env(safe-area-inset-bottom));
    z-index: 1;
    display: grid;
    min-width: 0;
    min-height: 0;
    margin: 0 !important;
    grid-template-rows: 44px minmax(0, 1fr) 56px;
  }

  .canvas-toolbar {
    gap: 5px;
    max-width: 100%;
    padding: 0 8px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .canvas-toolbar::-webkit-scrollbar {
    display: none;
  }

  .canvas-file-meta {
    flex: 0 0 auto;
  }

  .canvas-file-meta b,
  .toolbar-divider,
  .tool-button.labelled {
    display: none;
  }

  .toolbar-spacer {
    min-width: 6px;
  }

  .fit-button,
  .zoom-control {
    flex: 0 0 auto;
  }

  .fit-button {
    min-height: 36px;
  }

  .canvas-coordinate {
    padding: 30px 20px 100px;
  }

  .artboard-name {
    max-width: calc(100vw - 40px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .variant-tray {
    gap: 7px;
    max-width: 100%;
    padding: 7px 9px;
    overflow-x: auto;
  }

  .variant-title {
    display: none;
  }

  .variant-list {
    flex: 0 0 auto;
  }

  .variant-tray .compact-button {
    position: sticky;
    right: 0;
    min-height: 40px;
    white-space: nowrap;
  }

  .tool-dock {
    position: fixed;
    inset: auto 0 0;
    z-index: 70;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    width: 100%;
    height: calc(64px + env(safe-area-inset-bottom));
    min-height: 0;
    padding: 4px 6px env(safe-area-inset-bottom);
    background: rgba(17, 24, 39, .97);
    border-top: 1px solid rgba(255, 255, 255, .09);
    border-right: 0;
    backdrop-filter: blur(18px);
  }

  .tool-dock button {
    width: 100%;
    min-width: 0;
    min-height: 54px;
    padding: 4px 0;
    border-radius: 9px;
  }

  .tool-dock button svg {
    width: 17px;
    height: 17px;
  }

  .tool-dock button span {
    font-size: 8px;
  }

  .dock-spacer {
    display: none;
  }

  .library-panel {
    position: fixed;
    inset: 56px 0 calc(64px + env(safe-area-inset-bottom));
    z-index: 55;
    display: grid !important;
    grid-template-rows: 62px minmax(0, 1fr);
    width: 100%;
    min-width: 0;
    background: #fff;
    border: 0;
    box-shadow: 0 -18px 55px rgba(20, 28, 42, .2);
    opacity: 0;
    pointer-events: none;
    transform: translateX(-102%);
    transition: transform .24s ease, opacity .2s ease;
  }

  .library-panel.mobile-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateX(0);
  }

  .panel-header {
    padding: 0 14px;
  }

  .mobile-sheet-close {
    display: grid;
    width: 44px;
    height: 44px;
    place-items: center;
    color: var(--ink-soft);
    background: #f1f2f5;
    border: 0;
    border-radius: 50%;
    font-size: 18px;
  }

  .library-view {
    padding: 14px 14px calc(24px + env(safe-area-inset-bottom));
  }

  .properties-panel {
    position: fixed;
    inset: auto 0 calc(64px + env(safe-area-inset-bottom));
    z-index: 50;
    display: grid;
    width: 100%;
    height: min(58dvh, 540px);
    min-width: 0;
    max-width: none;
    grid-template-rows: 56px 42px minmax(0, 1fr) auto;
    background: #fff;
    border: 0;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -14px 44px rgba(20, 28, 42, .2);
    transform: translateY(calc(100% - 56px));
    transition: transform .24s ease;
  }

  .properties-panel.mobile-open {
    transform: translateY(0);
  }

  .properties-header {
    min-height: 56px;
    padding: 0 16px;
    cursor: pointer;
  }

  .properties-header::before {
    position: absolute;
    top: 7px;
    left: 50%;
    width: 34px;
    height: 4px;
    content: "";
    background: #d7d9de;
    border-radius: 999px;
    transform: translateX(-50%);
  }

  .properties-header h2 {
    margin-top: 4px;
    font-size: 14px;
  }

  .inspector-content {
    padding: 14px 15px calc(28px + env(safe-area-inset-bottom));
  }

  .inspector-content h3 {
    font-size: 16px;
  }

  .field-label,
  .field-head,
  .inspector-section-head strong,
  .switch-row strong,
  .rule-row strong,
  .check-row strong {
    font-size: 12px;
  }

  .field-hint,
  .inspector-content > p,
  .switch-row small,
  .rule-row small,
  .check-row small {
    font-size: 10px;
  }

  .text-input,
  .text-area,
  .select-input,
  .number-input {
    min-height: 44px;
    border-radius: 9px;
  }

  .app-dialog,
  .reference-skill-dialog,
  .postproduction-review-dialog {
    inset: auto 0 0;
    width: 100%;
    max-width: none;
    max-height: min(92dvh, 860px);
    margin: auto 0 0;
    border-radius: 20px 20px 0 0;
  }

  .app-dialog .dialog-head {
    position: sticky;
    top: 0;
    z-index: 3;
    min-height: 60px;
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(18px);
  }

  .reference-skill-form,
  .version-list,
  .template-manager-list {
    max-height: calc(92dvh - 60px);
    overflow-y: auto;
  }

  .dialog-form-grid,
  .post-review-compare {
    grid-template-columns: 1fr;
  }

  .dialog-actions {
    position: sticky;
    bottom: 0;
    z-index: 3;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding-bottom: calc(13px + env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(18px);
  }

  .dialog-actions > * {
    width: 100%;
  }

  .post-review-compare img {
    height: 180px;
  }

  .toast {
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom));
    left: 12px;
    width: auto;
    text-align: center;
    transform: translateY(12px);
  }

  .toast.show {
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .library-panel,
  .properties-panel {
    transition: none !important;
  }
}
