/* MatterShot — app chrome. The css-v2 design system (loaded via /css-v2/main.css
   in index.html) provides tokens + every primitive; this file styles the
   editor-specific surfaces: the tool rail, canvas stage, contextual options
   bar, action bar, empty state and the inline text editor. */

@import url("/css-v2/tokens.css");

html, body { height: 100%; margin: 0; background: var(--pm-black); color: var(--pm-white); }
body {
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  font-family: var(--ff-body);
  overflow: hidden;
  overscroll-behavior: none; /* no pull-to-refresh mid-edit on Android */
}
a { color: inherit; }
button { font: inherit; cursor: pointer; }

/* ------------------------------------------------------------------ */
/* Editor frame                                                        */
/* ------------------------------------------------------------------ */
.ms-app { flex: 1; min-height: 0; display: flex; }

.ms-rail {
  flex: 0 0 auto;
  width: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 8px;
  background: var(--pm-ink);
  border-inline-end: 1px solid var(--border-color-subtle);
  overflow-y: auto;
  overflow-x: hidden;
}
.ms-rail__sep { width: 24px; height: 1px; background: var(--border-color-subtle); margin: 6px 0; flex: 0 0 auto; }

.ms-tool {
  width: 40px; height: 40px;
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--pm-gray-300);
  border: 1px solid transparent;
  background: transparent;
  transition: background var(--dur-fast) var(--ease-out-expo), color var(--dur-fast) var(--ease-out-expo);
}
.ms-tool svg { width: 20px; height: 20px; }
.ms-tool:hover { background: var(--pm-gray-800); color: var(--pm-white); }
.ms-tool:focus-visible { outline: 2px solid var(--pm-accent); outline-offset: 1px; }
.ms-tool.is-active { background: color-mix(in srgb, var(--pm-purple-500) 30%, transparent); color: var(--pm-white); border-color: var(--pm-purple-400); }

.ms-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.ms-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #141418;
}
.ms-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ms-stage.is-dragover { outline: 2px dashed var(--pm-accent); outline-offset: -8px; }

/* ------------------------------------------------------------------ */
/* Contextual options bar                                              */
/* ------------------------------------------------------------------ */
.ms-options {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  display: none;
  align-items: center;
  gap: var(--sp-3);
  max-width: calc(100% - 24px);
  padding: 8px 12px;
  background: color-mix(in srgb, var(--pm-ink) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-color-base);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  overflow-x: auto;
  overflow-y: visible;
}
.ms-options.is-visible { display: flex; }

.ms-opt { display: flex; flex-direction: column; gap: 3px; flex: 0 0 auto; }
.ms-opt + .ms-opt { border-inline-start: 1px solid var(--border-color-subtle); padding-inline-start: var(--sp-3); }
.ms-opt__label { font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--pm-gray-400); white-space: nowrap; }
.ms-opt__ctrl { display: flex; align-items: center; gap: 6px; }
.ms-opt--hint { justify-content: center; color: var(--pm-gray-400); font-size: var(--fs-100); max-width: 320px; }

.ms-swatches { display: flex; align-items: center; gap: 4px; }
.ms-swatch {
  width: 22px; height: 22px; border-radius: 6px; padding: 0;
  border: 1px solid rgba(255,255,255,0.22);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.2);
}
.ms-swatch.is-active { outline: 2px solid var(--pm-accent); outline-offset: 1px; }
.ms-swatch--custom { overflow: hidden; background: conic-gradient(red, yellow, lime, aqua, blue, magenta, red); }
.ms-swatch--custom::-webkit-color-swatch-wrapper { padding: 0; }
.ms-swatch--custom::-webkit-color-swatch { border: none; }

.ms-slider { display: flex; align-items: center; gap: 8px; }
.ms-slider .form-slider { width: 120px; }
.ms-slider__val { min-width: 3ch; font-size: var(--fs-100); color: var(--pm-gray-300); font-variant-numeric: tabular-nums; }

.ms-options .form-select { min-width: 92px; padding: 5px 26px 5px 10px; font-size: var(--fs-100); }

.ms-seg { display: inline-flex; border: 1px solid var(--border-color-base); border-radius: var(--radius-sm); overflow: hidden; }
.ms-seg__btn { padding: 5px 10px; background: transparent; color: var(--pm-gray-300); font-size: var(--fs-100); border: 0; }
.ms-seg__btn:hover { color: var(--pm-white); }
.ms-seg__btn.is-active { background: var(--pm-purple-500); color: var(--pm-white); }

.ms-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-100); color: var(--pm-gray-200); }
.ms-toggle input { accent-color: var(--pm-purple-400); width: 16px; height: 16px; }

.ms-options .btn { white-space: nowrap; }
.ms-btn-danger { color: #ff8593 !important; border-color: rgba(255,70,90,0.4) !important; }

.ms-resize { display: flex; align-items: center; gap: 6px; }
.ms-num {
  width: 70px; padding: 5px 8px; font: inherit; font-size: var(--fs-100);
  color: var(--pm-white); background: var(--pm-gray-900);
  border: 1px solid var(--border-color-base); border-radius: var(--radius-sm);
}
.ms-resize__x { color: var(--pm-gray-400); }

/* ------------------------------------------------------------------ */
/* Action bar                                                          */
/* ------------------------------------------------------------------ */
.ms-actionbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 8px 12px;
  background: var(--pm-ink);
  border-block-start: 1px solid var(--border-color-subtle);
}
.ms-actgroup { display: flex; align-items: center; gap: 4px; }
.ms-actgroup--end { margin-inline-start: auto; }
.ms-actbtn {
  height: 36px; min-width: 36px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); color: var(--pm-gray-300);
  border: 1px solid transparent; background: transparent;
}
.ms-actbtn svg { width: 18px; height: 18px; }
.ms-actbtn:hover { background: var(--pm-gray-800); color: var(--pm-white); }
.ms-actbtn:disabled { opacity: 0.4; pointer-events: none; }
.ms-actbtn:focus-visible { outline: 2px solid var(--pm-accent); outline-offset: 1px; }
.ms-zoom { font-size: var(--fs-100); font-variant-numeric: tabular-nums; color: var(--pm-gray-200); }
.ms-actionbar .btn { display: inline-flex; align-items: center; gap: 6px; }
.ms-actionbar .btn svg { width: 16px; height: 16px; }

/* ------------------------------------------------------------------ */
/* Empty state                                                         */
/* ------------------------------------------------------------------ */
.ms-empty {
  position: absolute; inset: 0; z-index: 6;
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-6);
  background:
    radial-gradient(700px 400px at 50% 30%, rgba(115,0,139,0.16), transparent 60%),
    #141418;
}
.ms-empty__inner { max-width: 520px; text-align: center; }
.ms-empty__icon { display: inline-flex; opacity: 0.9; margin-bottom: var(--sp-4); }
.ms-empty__title { font-family: var(--ff-display); font-size: var(--fs-600); margin: 0 0 var(--sp-3); }
.ms-empty__lead { color: var(--pm-gray-300); margin: 0 0 var(--sp-5); }
.ms-empty__actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); justify-content: center; }
.ms-empty__delay { display: inline-flex; align-items: center; gap: 8px; margin-top: var(--sp-4); color: var(--pm-gray-400); font-size: var(--fs-100); }

/* ------------------------------------------------------------------ */
/* Inline text editor overlay                                          */
/* ------------------------------------------------------------------ */
.ms-textedit {
  position: absolute; z-index: 7;
  margin: 0; padding: 0; border: 0;
  background: transparent;
  color: #fff;
  outline: 1px dashed var(--pm-purple-400);
  outline-offset: 4px;
  resize: none; overflow: hidden;
  white-space: pre;
  box-sizing: content-box;
  caret-color: var(--pm-accent);
  transform-origin: top left;
}

/* Hide the floating cookie chip inside the editor — it overlaps the action
   bar; the panel is still reachable from Settings. */
.consent__chip { display: none !important; }

/* ------------------------------------------------------------------ */
/* Responsive                                                          */
/* ------------------------------------------------------------------ */
/* Touch niceties — harmless with a mouse. iOS (Safari and Chrome, both
   WebKit) zooms the page on double-tap unless the TOUCHED element opts out,
   and touch-action doesn't inherit — so cover every element on the page,
   site chrome and modals included. `manipulation` keeps panning and
   pinch-zoom (accessibility) and drops only the double-tap zoom. The canvas
   (inline `none`) and the options sliders override it with higher
   specificity. Contained overscroll stops a bar fling from rubber-banding
   the page. */
body, body * { touch-action: manipulation; }
.ms-rail, .ms-actionbar, .ms-options { overscroll-behavior-x: contain; }
.ms-tool, .ms-actbtn, .ms-seg__btn, .ms-swatch,
.ms-options .btn, .ms-actionbar .btn, .ms-empty__actions .btn {
  -webkit-tap-highlight-color: transparent;
}

@media (max-width: 760px) {
  .ms-app { flex-direction: column; }
  /* Bottom-docked chrome: canvas on top, then the action bar, then the tool
     rail on the very bottom edge — the thumb zone. `order` swaps rail and
     main without touching the DOM. The rail absorbs the home-indicator
     safe-area when running as an installed app. */
  .ms-main { order: 1; }
  .ms-rail {
    order: 2;
    width: 100%; flex-direction: row; overflow-x: auto; overflow-y: hidden;
    border-inline-end: none; border-block-end: none;
    border-block-start: 1px solid var(--border-color-subtle);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
  }
  .ms-rail__sep { width: 1px; height: 24px; margin: 0 4px; align-self: center; }
  /* The action groups' min-content width exceeds a phone screen; without a
     scroll container the whole layout viewport expands past device-width. */
  .ms-actionbar { overflow-x: auto; }
  .ms-actgroup { flex: 0 0 auto; }
  /* Pinch already zooms and the % button re-fits — the zoom ± buttons and
     the duplicate fit icon just push Export off-screen on a phone. */
  .ms-actionbar [data-a="zin"],
  .ms-actionbar [data-a="zout"],
  .ms-actionbar [data-a="fiticon"] { display: none; }
  /* Options dock to the bottom of the stage, right above the action bar,
     where thumbs already are — instead of floating over the image top. */
  .ms-options {
    top: auto; bottom: 8px; left: 8px; right: 8px;
    transform: none; max-width: none;
  }
  .ms-slider .form-slider { width: 110px; }
}

@media (max-width: 520px) {
  /* The Export dialog has "Copy image" — the bar keeps only one primary. */
  .ms-actionbar [data-a="copy"] { display: none; }
  .ms-empty__title { font-size: var(--fs-500); }
  .ms-empty__actions { flex-direction: column; align-items: stretch; }
  .ms-empty__actions .btn { justify-content: center; }
}

/* Finger-sized controls wherever the primary pointer is a finger,
   including landscape phones and tablets wider than 760px. */
@media (pointer: coarse) {
  .ms-tool { width: 44px; height: 44px; }
  .ms-actbtn { height: 44px; min-width: 44px; }
  .ms-actionbar .btn { min-height: 44px; }
  .ms-swatch { width: 28px; height: 28px; border-radius: 8px; }
  .ms-seg__btn { padding: 8px 14px; }
  .ms-toggle input { width: 20px; height: 20px; }
  .ms-num { padding: 9px 8px; }
  .ms-options { padding: 10px 12px; }
  .ms-options .form-select { padding-top: 8px; padding-bottom: 8px; }
  /* A horizontal slider inside a horizontally-scrollable bar: the slider
     must own the gesture, or every drag scrolls the bar instead. */
  .ms-options .form-slider { touch-action: none; }
  .ms-slider .form-slider { width: 130px; }
  .ms-empty__actions .btn { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .ms-tool { transition: none; }
}
