/* v3.9.6.1 isolates project thumbnails from the global mobile canvas sizing rule. */

body .image-import-field {
  display: none;
}

body[data-show-import-image="true"] .image-import-field {
  display: grid;
}

.export-options-dialog {
  width: min(540px, calc(100vw - 20px));
}

#checkWebUpdateBtn {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.export-options-body {
  display: grid;
  gap: 10px;
}

.export-options-body > :where(h2, p) {
  margin: 0;
}

.export-settings-disclosure {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
}

.export-settings-disclosure summary {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 11px;
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.export-settings-disclosure summary::-webkit-details-marker { display: none; }
.export-settings-disclosure summary::after { content: "+"; color: var(--muted); font-size: 18px; }
.export-settings-disclosure[open] summary::after { content: "−"; }

.export-style-choice {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin: 0;
  padding: 0;
  border: 0;
}

.export-style-choice legend {
  grid-column: 1 / -1;
  margin-bottom: 1px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.export-style-choice label {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 0;
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.export-style-choice input { position: absolute; width: 1px; height: 1px; margin: 0; opacity: 0; pointer-events: none; }
.export-style-choice label:focus-within { outline: 0 !important; box-shadow: none !important; }
.export-style-choice input:checked + span { color: var(--accent); }
.export-style-choice small { display: block; color: var(--muted); font-size: 10px; font-weight: 500; }

.export-settings-grid {
  display: grid;
  gap: 8px;
  max-height: min(52dvh, 430px);
  padding: 10px;
  overflow-y: auto;
  border-top: 1px solid var(--line);
  scrollbar-width: none;
}

.export-settings-grid::-webkit-scrollbar { display: none; }
.export-settings-grid > label:not(.export-switch) { display: grid; gap: 5px; color: var(--text); font-size: 12px; font-weight: 650; }
.export-settings-grid :where(select, input[type="text"], .expandable-select-toggle) { min-height: 38px; }
.export-switch { display: flex; min-height: 34px; align-items: center; gap: 8px; color: var(--text); font-size: 12px; }
.export-switch input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.export-rerender-button { width: 100%; min-height: 42px; }

.ios-image-save-body {
  grid-template-rows: auto auto minmax(140px, 1fr) auto;
}

.ios-image-save-body > [data-ios-export-name] {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ios-image-save-body .export-settings-disclosure[open] {
  max-height: min(48dvh, 420px);
  overflow-y: auto;
  scrollbar-width: none;
}

.ios-image-save-body .export-settings-disclosure[open]::-webkit-scrollbar { display: none; }

.ios-export-image-frame {
  display: grid;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ece8df;
}

.ios-image-save-body .ios-export-image-frame img {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  user-select: auto;
  -webkit-user-select: auto;
  -webkit-user-drag: auto;
  -webkit-touch-callout: default;
}

/* Basic panel dimensions stay compact and side by side in every orientation. */
.panel .recognition-picker {
  margin-bottom: 5px;
}

.panel .dimension-field-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0 0 8px;
}

.panel .dimension-field-row .field {
  min-width: 0;
  margin: 0;
}

.panel .dimension-field-row input[type="number"] {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
}

/* Statistics use separators instead of three framed cards. */
.panel .stats {
  gap: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.panel .stat {
  padding: 7px 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.panel .stat + .stat {
  border-left: 1px solid var(--line);
}

/* Project library preview-first rows. */
#projectLibraryDialog .project-library-head {
  grid-template-columns: minmax(0, 1fr) auto;
}

#projectLibraryDialog #backupProjectLibraryBtn {
  width: auto;
  min-width: 54px;
  height: 38px;
  min-height: 38px;
  padding: 6px 11px;
  font-size: 12px;
  font-weight: 700;
}

#projectLibraryDialog .project-card {
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 8px 10px;
  padding: 10px;
}

#projectLibraryDialog .project-card-preview {
  display: grid;
  box-sizing: border-box;
  width: 58px;
  min-width: 0;
  height: 58px;
  min-height: 0;
  grid-column: 1;
  grid-row: 1;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f3efe7;
  image-rendering: pixelated;
}

#projectLibraryDialog .project-card-preview canvas {
  display: block;
  box-sizing: border-box;
  width: 100% !important;
  min-width: 0 !important;
  max-width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
  max-height: 100% !important;
  margin: 0 !important;
  border: 0;
  border-radius: 0;
  background: #fff;
  object-fit: contain;
  box-shadow: none;
  image-rendering: pixelated;
}

#projectLibraryDialog .project-card-main {
  grid-column: 2;
  grid-row: 1;
}

#projectLibraryDialog .project-card-actions {
  grid-column: 3;
  grid-row: 1;
}

/* Settings use one expandable column in every orientation. */
#uiSettingsDialog {
  width: min(520px, calc(100vw - 20px));
  max-width: calc(100vw - 20px);
}

#uiSettingsDialog .ui-settings-form {
  height: min(680px, calc(100dvh - 16px));
}

#uiSettingsDialog .settings-scroll {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 8px;
  padding: 8px 2px;
}

#uiSettingsDialog .settings-group {
  display: block;
  grid-column: 1 !important;
  grid-row: auto !important;
  gap: 7px;
  margin: 0;
  padding: 10px;
  border-radius: 9px;
}

#uiSettingsDialog .settings-group summary {
  display: flex;
  min-height: 38px;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

#uiSettingsDialog .settings-group summary::-webkit-details-marker { display: none; }
#uiSettingsDialog .settings-group summary::after { content: "+"; color: var(--muted); font-size: 17px; }
#uiSettingsDialog .settings-group[open] summary::after { content: "−"; }
#uiSettingsDialog .settings-group > :not(summary) { margin-top: 7px; }

/* The drawing tool row sits slightly below the drawing tab header. */
.panel .drawing-panel {
  padding-top: 8px;
}

/* Current focus color behaves as a compact color-picker entry point. */
.focus-current-row {
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  text-align: left;
  box-shadow: none;
}

.focus-current-row:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* Optional compact mode removes explanatory copy and lets following controls rise. */
body[data-hide-tool-help="true"] :where(.panel, .focus-inspector, .focus-bead-parameter-panel) .hint {
  display: none !important;
}

.tab-icon { display: none; }
.tab-icon svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#uiSettingsDialog :where(.settings-field, .field-row) {
  gap: 4px;
  margin: 0;
}

#uiSettingsDialog :where(select, input[type="text"], input[type="number"]) {
  min-height: 36px;
  padding-block: 6px;
  font-size: 12px;
}

#uiSettingsDialog .switch-line {
  min-height: 30px;
  margin: 0;
  padding: 2px 5px;
  font-size: 12px;
}

#uiSettingsDialog .settings-group > .switch-line {
  margin-top: 3px;
}

#uiSettingsDialog .settings-group > .switch-line + .switch-line {
  margin-top: 1px;
}

#uiSettingsDialog .hint {
  margin: 0;
  font-size: 11px;
  line-height: 1.4;
}

#uiSettingsDialog .dialog-actions {
  margin-top: 8px;
}

@media (max-width: 680px) {
  #uiSettingsDialog .settings-scroll {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 7px;
  }

  #uiSettingsDialog .settings-group:nth-child(n) {
    grid-column: 1;
    grid-row: auto;
  }
}

@media (orientation: portrait) and (pointer: coarse) {
  html,
  body,
  .app,
  .workspace-bar,
  .panel,
  .focus-inspector,
  .focus-bead-parameter-panel {
    overscroll-behavior: none;
  }

  .workspace-bar {
    touch-action: pan-x;
  }

  .workspace-bar :where(button, [role="button"]) {
    touch-action: manipulation;
  }

  .inspector-handle {
    position: relative;
    z-index: 2;
    overflow: visible;
    touch-action: none;
  }

  .inspector-handle::before {
    content: "";
    position: absolute;
    inset: -9px 0;
  }
}

@media (orientation: portrait) {
  :root {
    --portrait-gesture-reserve: calc(var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)) + 8px);
  }

  .focus-session-group.focus-group-hidden { display: none !important; }

  .inspector-head,
  .focus-panel-head,
  .focus-parameter-head {
    border-bottom: 0 !important;
  }

  .panel[data-snap="collapsed"],
  .focus-inspector[data-snap="collapsed"],
  .focus-bead-parameter-panel[data-snap="collapsed"] {
    transform: translateY(calc(100% - 64px - var(--portrait-gesture-reserve))) !important;
    overflow: hidden !important;
    overscroll-behavior: none !important;
    touch-action: none;
  }

  .panel[data-snap="collapsed"] .inspector-head,
  .focus-inspector[data-snap="collapsed"] .focus-panel-head,
  .focus-bead-parameter-panel[data-snap="collapsed"] .focus-parameter-head {
    height: calc(64px + var(--portrait-gesture-reserve));
    grid-template-rows: 64px;
    padding-top: 0;
    padding-bottom: var(--portrait-gesture-reserve);
    border-bottom: 0;
    border-radius: 12px 12px 0 0;
    background: var(--surface);
    box-shadow: 0 -8px 24px rgba(36, 36, 33, .12);
  }

  .focus-bead-parameter-panel[data-snap="collapsed"] .focus-parameter-head {
    flex: 0 0 calc(64px + var(--portrait-gesture-reserve));
  }

  .panel[data-snap="collapsed"] .inspector-handle,
  .focus-inspector[data-snap="collapsed"] .inspector-handle,
  .focus-bead-parameter-panel[data-snap="collapsed"] .inspector-handle {
    display: none;
  }

  :where(.panel, .focus-inspector, .focus-bead-parameter-panel)[data-snap="collapsed"] :where(.panel-tabs, .focus-tabs) {
    height: 64px;
  }

  :where(.panel, .focus-inspector, .focus-bead-parameter-panel)[data-snap="collapsed"] :where(.panel-tabs, .focus-tabs) button {
    display: grid;
    min-height: 60px;
    grid-template-rows: 27px 18px;
    place-items: center;
    align-content: center;
    gap: 2px;
    padding: 4px 2px;
    font-size: 11px;
    touch-action: manipulation;
  }

  :where(.panel-tabs, .focus-tabs) button::after,
  :where(.panel-tabs, .focus-tabs) .tab-label {
    border: 0 !important;
    text-decoration: none !important;
  }

  :where(.panel, .focus-inspector, .focus-bead-parameter-panel)[data-snap="collapsed"] .tab-icon {
    display: grid;
    place-items: center;
  }

  :where(.panel, .focus-inspector, .focus-bead-parameter-panel):not([data-snap="collapsed"]) .tab-icon {
    display: none;
  }

  .focus-session-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .focus-bead-parameter-panel.tabs-detached:not([data-snap="collapsed"]) .focus-parameter-head {
    position: absolute;
    inset: 0 0 auto;
    z-index: 3;
    display: block;
    height: 0;
    flex: 0 0 0;
    margin: 0;
    padding: 0;
    pointer-events: none;
  }

  .focus-bead-parameter-panel.tabs-detached:not([data-snap="collapsed"]) .focus-parameter-head .inspector-handle {
    position: absolute;
    top: -18px;
    right: 14px;
    left: 14px;
    height: 36px;
    min-height: 36px;
    margin: 0;
    pointer-events: auto;
  }

  .focus-bead-parameter-panel.tabs-detached:not([data-snap="collapsed"]) .focus-bead-controls {
    padding-top: 0;
  }

  .focus-bead-parameter-panel.tabs-detached:not([data-snap="collapsed"]) .focus-colors-section:not(.focus-group-hidden) {
    padding-top: 22px !important;
  }

}

@media (orientation: landscape) {
  .focus-bead-sidebar {
    box-sizing: border-box;
    padding-top: var(--top-safe);
  }
}

.focus-bead-stage {
  background-color: #E8E3DA !important;
  background-image: none !important;
}

html[data-theme="dark"] .focus-bead-stage {
  background-color: #191B19 !important;
}

html[data-theme="dark"] :where(.hint, .focus-status, .focus-progress-label) {
  color: var(--muted) !important;
}

html[data-theme="dark"] #paletteList .chip {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--text);
  box-shadow: none;
}

#smoothnessValue,
#filterStrengthValue {
  color: var(--accent);
  background: var(--accent-soft);
}

.android-gallery-saved-dialog {
  width: min(370px, calc(100vw - 28px));
  max-width: calc(100vw - 28px);
  padding: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
}

.android-gallery-saved-body {
  display: grid;
  gap: 16px;
  padding: 24px 20px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 68px color-mix(in srgb, var(--text) 22%, transparent);
  text-align: center;
}

.android-gallery-success-icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin: 0 auto;
  place-items: center;
  border-radius: 18px;
  background: var(--accent-soft);
  color: var(--accent);
}

.android-gallery-success-icon svg { width: 28px; height: 28px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.android-gallery-saved-copy { display: grid; gap: 7px; }
.android-gallery-saved-copy h2, .android-gallery-saved-copy p { margin: 0; }
.android-gallery-saved-copy h2 { font-size: 20px; }
.android-gallery-saved-copy p { color: var(--muted); font-size: 12px; line-height: 1.65; }
.android-gallery-saved-actions { display: grid; grid-template-columns: minmax(0, .82fr) minmax(0, 1.18fr); gap: 8px; }
.android-gallery-saved-actions button { min-width: 0; }
button.primary,
button.primary:hover:not(:disabled) {
  box-shadow: none !important;
}

@media (orientation: landscape) {
  .preview-canvas-frame {
    inset: 10px 58px 10px 10px;
  }
}
html[data-theme="light"] .stat strong {
  color: var(--text);
}

html[data-theme="dark"] .stat strong {
  color: var(--text);
}
html[data-theme="dark"] label:has(input[type="checkbox"]),
html[data-theme="dark"] :where(.switch-line, .compact-check, .export-switch, .smart-effect-option, .tool-toggle-control) {
  color: var(--text) !important;
}
/* Vertical scrolling stays functional without persistent right-edge indicators. */
:where(.panel, .focus-inspector, .focus-bead-controls, .settings-scroll, .project-library-list, .history-card, .about-scroll) {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

:where(.panel, .focus-inspector, .focus-bead-controls, .settings-scroll, .project-library-list, .history-card, .about-scroll)::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

/* Smooth launch restore and explicit mirror toggle feedback. */
.startup-restore-veil {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: none;
  place-items: center;
  background: var(--bg);
  opacity: 1;
  visibility: visible;
  transition: opacity .24s ease, visibility 0s linear .24s;
}
html.welcome-complete.startup-restore-pending .startup-restore-veil { display: grid; }
html:not(.welcome-complete) .startup-restore-veil { display: none; }
.startup-restore-veil.is-finished { opacity: 0; visibility: hidden; pointer-events: none; }
.startup-restore-mark { display: grid; justify-items: center; gap: 12px; color: var(--muted); font-size: 12px; }
.startup-restore-mark img { width: 52px; height: 52px; border-radius: 15px; }
.startup-restore-track { position: relative; width: 68px; height: 3px; overflow: hidden; border-radius: 99px; background: var(--line); }
.startup-restore-track::after { content: ""; position: absolute; inset: 0; width: 42%; border-radius: inherit; background: var(--accent); animation: startup-restore-progress .9s ease-in-out infinite; }
@keyframes startup-restore-progress { from { transform: translateX(-120%); } to { transform: translateX(340%); } }
@media (prefers-reduced-motion: reduce) { .startup-restore-track::after { animation: none; width: 100%; } }
.preview-shell .canvas-action-rail #mirrorCanvasBtn[aria-pressed="true"] {
  color: var(--accent) !important;
  background: var(--accent-soft) !important;
  border-color: color-mix(in srgb, var(--accent) 34%, var(--line)) !important;
}

/* iOS long-press export follows the active appearance. */
html[data-theme="dark"] .ios-image-save-dialog,
html[data-theme="dark"] .ios-image-save-body {
  border-color: var(--line) !important;
  background: var(--surface) !important;
  color: var(--text) !important;
}
html[data-theme="dark"] .ios-image-save-body > [data-ios-export-name] { color: var(--muted) !important; }
html[data-theme="dark"] .ios-export-image-frame {
  border-color: var(--line) !important;
  background: var(--bg) !important;
}
html[data-theme="dark"] .ios-image-save-body [data-ios-export-close] {
  border-color: var(--line) !important;
  background: var(--surface-2) !important;
  color: var(--text) !important;
}

/* Restore persistent brand-green primary actions. */
.startup-restore-veil[hidden] { display: none !important; }
button.primary,
button.primary:hover:not(:disabled),
button.primary:focus-visible:not(:disabled),
button.primary:active:not(:disabled) {
  border-color: var(--accent) !important;
  background: var(--accent) !important;
  color: #fff !important;
  box-shadow: none !important;
}

/* Drawing tool names follow the existing help-text preference. */
.drawing-icon-tools button {
  min-height: 56px;
  grid-template-rows: 20px auto;
  align-content: center;
  gap: 3px;
  padding: 5px 2px 4px;
}
.drawing-tool-label {
  display: block;
  max-width: 100%;
  overflow: hidden;
  font-size: 10px;
  font-weight: 650;
  line-height: 1.15;
  text-overflow: ellipsis;
  white-space: nowrap;
}
body[data-hide-tool-help="true"] .drawing-tool-label { display: none !important; }
body[data-hide-tool-help="true"] .drawing-icon-tools button {
  min-height: 42px;
  grid-template-rows: 20px;
  gap: 0;
  padding: 0;
}
