/* ============================================================
   Token Image Editor - Module Styles
   All rules scoped to .token-image-editor to avoid leaking
   into Foundry's core UI.
   ============================================================ */

/* ── Window sizing ─────────────────────────────────────────── */
.token-image-editor .window-content {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Root layout ───────────────────────────────────────────── */
.token-image-editor .tie-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #1e1e2e;
  color: #cdd6f4;
  font-family: var(--font-primary, sans-serif);
  font-size: 13px;
}

/* ── Toolbar ───────────────────────────────────────────────── */
.token-image-editor .tie-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: #181825;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.token-image-editor .tie-toolbar__group {
  display: flex;
  align-items: center;
  gap: 3px;
}

.token-image-editor .tie-toolbar__group + .tie-toolbar__group {
  border-left: 1px solid #45475a;
  margin-left: 4px;
  padding-left: 6px;
}

.token-image-editor .tie-toolbar .tie-toolbar__group--save {
  margin-left: auto;
  border-left: 1px solid #45475a;
  padding-left: 8px;
}

.token-image-editor .tie-wildcard-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  background: #f9e2af;
  color: #1e1e2e;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

/* ── Buttons ───────────────────────────────────────────────── */
.token-image-editor .tie-tool-btn,
.token-image-editor .tie-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  color: #a6adc8;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.token-image-editor .tie-tool-btn:hover,
.token-image-editor .tie-icon-btn:hover {
  background: #313244;
  color: #cdd6f4;
}

.token-image-editor .tie-tool-btn.is-active,
.token-image-editor .tie-icon-btn.is-active {
  background: #45475a;
  border-color: #89b4fa;
  color: #89b4fa;
}

.token-image-editor .tie-tool-btn:disabled,
.token-image-editor .tie-icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

.token-image-editor .tie-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 4px;
  border: 1px solid transparent;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.token-image-editor .tie-btn--primary {
  background: #89b4fa;
  color: #1e1e2e;
  border-color: #89b4fa;
  font-weight: 600;
}

.token-image-editor .tie-btn--primary:hover {
  background: #b4d0fe;
  border-color: #b4d0fe;
}

.token-image-editor .tie-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.token-image-editor .tie-btn--ghost {
  background: transparent;
  color: #cdd6f4;
  border-color: #45475a;
}

.token-image-editor .tie-btn--ghost:hover {
  background: #313244;
}

.token-image-editor .tie-btn--danger {
  background: #f38ba8;
  color: #1e1e2e;
  border-color: #f38ba8;
}

.token-image-editor .tie-btn--danger:hover {
  background: #eb6f92;
  border-color: #eb6f92;
}

.token-image-editor .tie-btn--sm {
  padding: 3px 8px;
  font-size: 12px;
}

/* ── Panel buttons - uniform width and vertical rhythm ─────── */
/* All action buttons inside side panels stretch to full width  */
/* so they're the same size regardless of label length.         */
.token-image-editor .tie-panel .tie-btn {
  display: flex;
  width: 100%;
  justify-content: center;
}

/* Space between a slider/control group and the first button */
.token-image-editor .tie-panel .tie-control + .tie-btn,
.token-image-editor .tie-panel .tie-control + .tie-btn ~ .tie-btn {
  margin-top: 6px;
}

/* Space between consecutive buttons */
.token-image-editor .tie-panel .tie-btn + .tie-btn {
  margin-top: 4px;
}

/* ── Zoom level display ────────────────────────────────────── */
.token-image-editor .tie-zoom-level {
  min-width: 38px;
  text-align: center;
  font-size: 12px;
  color: #a6adc8;
  user-select: none;
}

/* ── Main body (three columns) ─────────────────────────────── */
.token-image-editor .tie-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Side panels ───────────────────────────────────────────── */
.token-image-editor .tie-panel {
  background: #181825;
  overflow-y: auto;
  flex-shrink: 0;
}

.token-image-editor .tie-panel--left {
  width: 200px;
  border-right: 1px solid #313244;
  padding: 8px;
}

.token-image-editor .tie-panel--right {
  width: 245px;
  border-left: 1px solid #313244;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Right panel tabs ─────────────────────────────────────── */

.token-image-editor .tie-rp-tabs {
  display: flex;
  gap: 0;
  padding: 0;
  background: #181825;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
}

.token-image-editor .tie-rp-tab {
  flex: 1;
  padding: 6px 4px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: #a6adc8;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  text-align: center;
}

.token-image-editor .tie-rp-tab:hover {
  background: #313244;
  color: #cdd6f4;
}

.token-image-editor .tie-rp-tab:focus {
  outline: none;
  box-shadow: none;
}

.token-image-editor .tie-rp-tab.is-active {
  color: #89b4fa;
  border-bottom-color: #89b4fa;
}

.token-image-editor .tie-rp-panel {
  display: none;
  flex-direction: column;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.token-image-editor .tie-rp-panel.is-active {
  display: flex;
}

/* ── Mask groups (global masks tab) ───────────────────────── */

.token-image-editor .tie-mask-group {
  border-bottom: 1px solid #313244;
}

.token-image-editor .tie-mask-group__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: #181825;
  font-size: 11px;
  font-weight: 600;
  color: #6c7086;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.token-image-editor .tie-mask-group__thumb {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  background: #313244;
  overflow: hidden;
  margin-right: 6px;
  font-size: 11px;
  color: #a6adc8;
}

.token-image-editor .tie-mask-group__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.token-image-editor .tie-mask-group__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.token-image-editor .tie-mask-group .tie-mask-list {
  padding: 4px 10px 8px;
}

.token-image-editor .tie-panel__heading {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #6c7086;
  font-weight: 600;
}

.token-image-editor .tie-panel__empty {
  color: #6c7086;
  font-size: 12px;
  font-style: italic;
  margin: 0;
  padding: 4px 0;
}

.token-image-editor .tie-panel__section {
  padding: 10px;
  border-bottom: 1px solid #313244;
}

.token-image-editor .tie-panel__section:last-child {
  border-bottom: none;
}

.token-image-editor .tie-panel__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.token-image-editor .tie-panel__header-actions {
  display: flex;
  gap: 2px;
}

/* ── Controls / sliders ────────────────────────────────────── */
.token-image-editor .tie-control {
  margin-bottom: 10px;
}

.token-image-editor .tie-control:last-child {
  margin-bottom: 0;
}

.token-image-editor .tie-control__label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 12px;
  color: #a6adc8;
  margin-bottom: 4px;
}

.token-image-editor .tie-control__value {
  font-size: 11px;
  color: #6c7086;
  font-variant-numeric: tabular-nums;
}

.token-image-editor .tie-control__subheading {
  font-size: 11px;
  font-weight: 600;
  color: #6c7086;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0 0 6px;
}

.token-image-editor .tie-control--section {
  border-top: 1px solid #313244;
  padding-top: 10px;
  margin-top: 10px;
}

/* ── Layer Effects sections ──────────────────────────────── */
.token-image-editor .tie-fx-section + .tie-fx-section {
  border-top: 1px solid #313244;
  padding-top: 10px;
  margin-top: 10px;
}

.token-image-editor .tie-fx-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 600;
  color: #cdd6f4;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.token-image-editor .tie-slider {
  width: 100%;
  height: 4px;
  accent-color: #89b4fa;
  cursor: pointer;
}

.token-image-editor .tie-slider--inline {
  flex: 1;
  width: auto;
}

.token-image-editor .tie-select {
  width: 100%;
  background: #313244;
  border: 1px solid #45475a;
  border-radius: 4px;
  color: #cdd6f4;
  padding: 4px 6px;
  font-size: 12px;
  cursor: pointer;
}

.token-image-editor .tie-select:focus {
  outline: none;
  border-color: #89b4fa;
}

.token-image-editor .tie-color-picker {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  background: none;
  padding: 0;
}

.token-image-editor .tie-tint-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Canvas viewport ───────────────────────────────────────── */
.token-image-editor .tie-canvas-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #11111b;
  /* Checkerboard to show transparency */
  background-image:
    linear-gradient(45deg, #1a1a2e 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a2e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a2e 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a2e 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.token-image-editor .tie-canvas {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.token-image-editor .tie-canvas--overlay {
  pointer-events: none;
  cursor: default;
}

/* Tool-specific pointer-events and cursors */
.token-image-editor.tool-lasso    .tie-canvas--overlay { pointer-events: all; cursor: crosshair; }
.token-image-editor.tool-freehand .tie-canvas--overlay { pointer-events: all; cursor: crosshair; }
.token-image-editor.tool-move      .tie-canvas--overlay   { pointer-events: all; cursor: grab; }
.token-image-editor.tool-move      .tie-canvas--overlay:active { cursor: grabbing; }
.token-image-editor.tool-transform .tie-canvas--overlay   { pointer-events: all; cursor: grab; }
.token-image-editor.tool-transform .tie-canvas--overlay:active { cursor: grabbing; }
.token-image-editor.tool-zoom  .tie-canvas--overlay   { pointer-events: all; cursor: grab; }
.token-image-editor.tool-zoom  .tie-canvas--overlay:active { cursor: grabbing; }
.token-image-editor.tool-mask-paint .tie-canvas--overlay { pointer-events: all; cursor: crosshair; }
.token-image-editor.tool-liquify    .tie-canvas--overlay { pointer-events: all; cursor: crosshair; }
.token-image-editor.tool-erase      .tie-canvas--overlay { pointer-events: all; cursor: crosshair; }
.token-image-editor.tool-clone-heal .tie-canvas--overlay { pointer-events: all; cursor: crosshair; }

/* ── Mini-map ──────────────────────────────────────────────── */
.token-image-editor .tie-minimap {
  position: absolute;
  bottom: 8px;
  right: 8px;
  max-width: 100px;
  max-height: 100px;
  border: 1px solid #45475a;
  border-radius: 4px;
  overflow: hidden;
  background: #11111b;
  opacity: 0.85;
  cursor: pointer;
}

.token-image-editor .tie-minimap canvas {
  display: block;
}

.token-image-editor .tie-minimap__viewport-rect {
  position: absolute;
  border: 1px solid #89b4fa;
  background: rgba(137, 180, 250, 0.1);
  pointer-events: none;
}

/* ── Lasso hint banner ─────────────────────────────────────── */
.token-image-editor .tie-canvas-hint {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(24, 24, 37, 0.85);
  border: 1px solid #45475a;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  color: #f9e2af;
  display: flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
  white-space: nowrap;
}

/* ── Layer list ────────────────────────────────────────────── */
.token-image-editor .tie-layer-list {
  list-style: none;
  margin: 0;
  padding: 0;
  /* Keeps a drop target under the pointer when there are only a row or two.
     The panel itself also listens for drops, this is belt and braces. */
  min-height: 80px;
}

.token-image-editor .tie-layer-list__empty {
  padding: 12px 8px;
  color: #6c7086;
  font-size: 12px;
  font-style: italic;
  text-align: center;
}

.token-image-editor .tie-layer {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 6px;
  cursor: pointer;
  border-bottom: 1px solid #313244;
  transition: background 0.1s;
  user-select: none;
}

.token-image-editor .tie-layer:hover {
  background: #313244;
}

.token-image-editor .tie-layer.is-active {
  background: #1e3a5f;
  border-left: 2px solid #89b4fa;
  padding-left: 4px;
}

.token-image-editor .tie-layer.is-locked {
  opacity: 0.6;
}

/* Drop indicator. Absolutely positioned rather than a border so the row does
   not grow mid-drag and shift the rows under the pointer. --drag-over draws
   above the row, --drag-over-after below it (only used on the last row, for
   dropping to the bottom of the stack). */
.token-image-editor .tie-layer.tie-layer--drag-over::before,
.token-image-editor .tie-layer.tie-layer--drag-over-after::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: #89b4fa;
  pointer-events: none;
}

.token-image-editor .tie-layer.tie-layer--drag-over::before {
  top: -1px;
}

.token-image-editor .tie-layer.tie-layer--drag-over-after::after {
  bottom: -1px;
}

.token-image-editor .tie-layer.is-dragging {
  opacity: 0.4;
}

.token-image-editor .tie-layer__drag-handle:active {
  cursor: grabbing;
}

.token-image-editor .tie-layer__drag-handle {
  color: #45475a;
  cursor: grab;
  font-size: 11px;
  flex-shrink: 0;
}

.token-image-editor .tie-layer__thumb {
  position: relative;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  overflow: hidden;
  background: #313244;
  font-size: 13px;
  color: #89b4fa;
}

.token-image-editor .tie-layer__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Small play-triangle overlay to mark video-backed layers. */
.token-image-editor .tie-layer__thumb-badge {
  position: absolute;
  right: 1px;
  bottom: 1px;
  width: 9px;
  height: 9px;
  padding: 1px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 7px;
  line-height: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.token-image-editor .tie-layer__name {
  flex: 1;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #cdd6f4;
  min-width: 0;
}

.token-image-editor .tie-layer__badge {
  flex-shrink: 0;
  font-size: 10px;
  padding: 1px 4px;
  border-radius: 3px;
  background: #45475a;
  color: #a6adc8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.token-image-editor .tie-layer__badge--dynamic {
  background: #6c3483;
  color: #e8daef;
}

.token-image-editor .tie-color-input {
  width: 40px;
  height: 26px;
  padding: 1px;
  border: 1px solid #585b70;
  border-radius: 3px;
  background: transparent;
  cursor: pointer;
}

.token-image-editor .tie-layer__controls {
  display: flex;
  gap: 1px;
  flex-shrink: 0;
}

.token-image-editor .tie-layer__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 3px;
  color: #6c7086;
  cursor: pointer;
  font-size: 11px;
  transition: color 0.1s, background 0.1s;
}

.token-image-editor .tie-layer__btn:hover {
  background: #45475a;
  color: #cdd6f4;
}

.token-image-editor .tie-layer__btn.is-hidden {
  color: #45475a;
}

.token-image-editor .tie-layer__btn.is-active {
  color: #f9e2af;
}

.token-image-editor .tie-layer__btn--danger:hover {
  background: rgba(243, 139, 168, 0.2);
  color: #f38ba8;
}

/* ── Mask section ──────────────────────────────────────────── */
.token-image-editor .tie-mask-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.token-image-editor .tie-mask-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 12px;
  color: #cdd6f4;
  background: #313244;
  user-select: none;
}

.token-image-editor .tie-mask-item:hover {
  background: #45475a;
}

.token-image-editor .tie-mask-item.is-active {
  background: #1e3a5f;
  border-color: #89b4fa;
  color: #89b4fa;
}

.token-image-editor .tie-mask-item__label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.token-image-editor .tie-mask-list__empty {
  font-size: 11px;
  color: #6c7086;
  padding: 4px 6px;
  font-style: italic;
}

.token-image-editor .tie-mask-preview {
  width: 100%;
  height: 60px;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
  background: #313244;
}

.token-image-editor .tie-mask-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.token-image-editor .tie-hint {
  font-size: 11px;
  color: #6c7086;
  margin: 4px 0 0;
  font-style: italic;
}

/* ── Shortcuts list ──────────────────────────────────────── */
.token-image-editor .tie-shortcut-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.token-image-editor .tie-shortcut-list li {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 11px;
  color: #cdd6f4;
}

.token-image-editor .tie-shortcut-list kbd {
  display: inline-block;
  background: #313244;
  border: 1px solid #45475a;
  border-radius: 3px;
  padding: 1px 4px;
  font-family: inherit;
  font-size: 10px;
  color: #89b4fa;
  white-space: nowrap;
  flex-shrink: 0;
}

.token-image-editor .tie-shortcut-list span {
  color: #a6adc8;
}

/* ── Inline editing (layer rename) ────────────────────────── */
.token-image-editor .tie-layer__name-input {
  flex: 1;
  background: #313244;
  border: 1px solid #89b4fa;
  border-radius: 3px;
  color: #cdd6f4;
  font-size: 12px;
  padding: 1px 4px;
  min-width: 0;
}

.token-image-editor .tie-layer__name-input:focus {
  outline: none;
}

/* ── Layer context menu ───────────────────────────────────── */
.tie-layer-ctx-menu {
  position: fixed;
  z-index: 10000;
  margin: 0;
  padding: 4px 0;
  list-style: none;
  background: #1e1e2e;
  border: 1px solid #45475a;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  min-width: 160px;
}

.tie-layer-ctx-menu li {
  padding: 6px 12px;
  font-size: 12px;
  color: #cdd6f4;
  cursor: pointer;
  white-space: nowrap;
}

.tie-layer-ctx-menu li:hover {
  background: #313244;
  color: #89b4fa;
}

.tie-layer-ctx-menu__danger {
  color: #f38ba8 !important;
}
.tie-layer-ctx-menu__danger:hover {
  background: #45475a !important;
  color: #f38ba8 !important;
}

/* ============================================================
   Frame Browser (.tie-frame-browser)
   ============================================================ */

.tie-frame-browser .window-content {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Layout ──────────────────────────────────────────────────── */
.tie-frame-browser .tie-fb-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #1e1e2e;
  color: #cdd6f4;
  font-family: var(--font-primary, sans-serif);
  font-size: 13px;
}

/* ── Tabs ────────────────────────────────────────────────────── */
.tie-frame-browser .tie-fb-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 8px 0;
  background: #181825;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
}

.tie-frame-browser .tie-fb-tab {
  padding: 5px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  color: #a6adc8;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  position: relative;
  bottom: -1px;
}

.tie-frame-browser .tie-fb-tab:hover {
  background: #313244;
  color: #cdd6f4;
}

.tie-frame-browser .tie-fb-tab.is-active {
  background: #1e1e2e;
  border-color: #313244;
  color: #cdd6f4;
  font-weight: 600;
}

/* ── Panels ──────────────────────────────────────────────────── */
.tie-frame-browser .tie-fb-panels {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.tie-frame-browser .tie-fb-panel {
  display: none;
  height: 100%;
  overflow-y: auto;
  padding: 10px 12px;
}

.tie-frame-browser .tie-fb-panel.is-active {
  display: block;
}

/* ── Custom tab toolbar ──────────────────────────────────────── */
.tie-frame-browser .tie-fb-panel__toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #313244;
}

.tie-frame-browser .tie-fb-empty {
  color: #6c7086;
  font-size: 12px;
  font-style: italic;
  margin: 0;
}

/* ── Subsection headers (OMFG version labels) ────────────────── */
.tie-frame-browser .tie-fb-subsection-header {
  margin: 14px 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #6c7086;
  font-weight: 600;
}

.tie-frame-browser .tie-fb-subsection-header:first-child {
  margin-top: 0;
}

/* ── Frame grid ──────────────────────────────────────────────── */
.tie-frame-browser .tie-fb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 8px;
  margin-bottom: 4px;
}

/* ── Frame item ──────────────────────────────────────────────── */
.tie-frame-browser .tie-fb-frame {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 5px;
  border-radius: 6px;
  border: 1px solid #313244;
  background: #181825;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  user-select: none;
}

.tie-frame-browser .tie-fb-frame:hover {
  border-color: #89b4fa;
  background: #1e3a5f;
  box-shadow: 0 0 0 1px #89b4fa22;
}

.tie-frame-browser .tie-fb-frame:focus-visible {
  outline: 2px solid #89b4fa;
  outline-offset: 2px;
}

/* Checkerboard background inside frame thumbnail (shows transparency) */
.tie-frame-browser .tie-fb-frame__img-wrap {
  width: 72px;
  height: 72px;
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
  background-color: #11111b;
  background-image:
    linear-gradient(45deg, #1a1a2e 25%, transparent 25%),
    linear-gradient(-45deg, #1a1a2e 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #1a1a2e 75%),
    linear-gradient(-45deg, transparent 75%, #1a1a2e 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}

.tie-frame-browser .tie-fb-frame__img-wrap img,
.tie-frame-browser .tie-fb-frame__img-wrap video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.tie-frame-browser .tie-fb-frame__label {
  font-size: 10px;
  color: #a6adc8;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
  max-width: 72px;
}

/* ── Remove button (custom frames only) ──────────────────────── */
.tie-frame-browser .tie-fb-frame__remove {
  position: absolute;
  top: 3px;
  right: 3px;
  display: none;
  width: 18px;
  height: 18px;
  padding: 0;
  align-items: center;
  justify-content: center;
  background: rgba(243, 139, 168, 0.15);
  border: 1px solid rgba(243, 139, 168, 0.4);
  border-radius: 3px;
  color: #f38ba8;
  font-size: 10px;
  cursor: pointer;
  transition: background 0.1s;
}

.tie-frame-browser .tie-fb-frame__favorite {
  position: absolute;
  top: 3px;
  left: 3px;
  display: none;
  width: 18px;
  height: 18px;
  padding: 0;
  align-items: center;
  justify-content: center;
  background: rgba(250, 179, 135, 0.15);
  border: 1px solid rgba(250, 179, 135, 0.4);
  border-radius: 3px;
  color: #fab387;
  font-size: 10px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.tie-frame-browser .tie-fb-frame:hover .tie-fb-frame__remove {
  display: inline-flex;
}

.tie-frame-browser .tie-fb-frame:hover .tie-fb-frame__favorite {
  display: inline-flex;
}

.tie-frame-browser .tie-fb-frame__favorite.is-active {
  display: inline-flex;
  color: #f9e2af;
  border-color: rgba(249, 226, 175, 0.6);
}

.tie-frame-browser .tie-fb-frame__remove:hover {
  background: rgba(243, 139, 168, 0.35);
}

.tie-frame-browser .tie-fb-frame__favorite:hover {
  background: rgba(250, 179, 135, 0.35);
}

/* ── Shared button styles (reused from main editor) ──────────── */
.tie-frame-browser .tie-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 4px;
  border: 1px solid transparent;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.tie-frame-browser .tie-btn--ghost {
  background: transparent;
  color: #cdd6f4;
  border-color: #45475a;
}

.tie-frame-browser .tie-btn--ghost:hover {
  background: #313244;
}

.tie-frame-browser .tie-btn--sm {
  padding: 3px 8px;
  font-size: 12px;
}

/* ============================================================
   Settings App
   ============================================================ */

.tie-settings-app .window-content {
  padding: 0;
  overflow: hidden;
}

.tie-sa-layout {
  display: flex;
  flex-direction: column;
  background: #1e1e2e;
  color: #cdd6f4;
  font-family: var(--font-primary, sans-serif);
  font-size: 13px;
}

/* Hardcode text colors so Foundry's light theme can't override them to black.
   Scoped with .tie-settings-app to win against Foundry's tag-level theme rules. */
.tie-settings-app .tie-sa-layout,
.tie-settings-app .tie-sa-layout input,
.tie-settings-app .tie-sa-layout select,
.tie-settings-app .tie-sa-layout textarea,
.tie-settings-app .tie-sa-layout h1,
.tie-settings-app .tie-sa-layout h2,
.tie-settings-app .tie-sa-layout h3,
.tie-settings-app .tie-sa-layout h4,
.tie-settings-app .tie-sa-layout h5,
.tie-settings-app .tie-sa-section-heading,
.tie-settings-app .tie-sa-divider {
  color: #cdd6f4;
}

/* Preserve the muted palette at a specificity Foundry can't beat */
.tie-settings-app .tie-sa-hint,
.tie-settings-app .tie-sa-license-desc,
.tie-settings-app .tie-sa-license-copy,
.tie-settings-app .tie-sa-license-type {
  color: #a6adc8;
}

.tie-settings-app .tie-sa-label {
  color: #bac2de;
}

/* ── Tabs ───────────────────────────────────────────────────── */

.tie-sa-tabs {
  display: flex;
  gap: 2px;
  padding: 8px 10px 0;
  background: #181825;
  border-bottom: 1px solid #313244;
  flex-shrink: 0;
}

.tie-sa-tab {
  padding: 6px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 4px 4px 0 0;
  color: #a6adc8;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}

.tie-sa-tab:hover {
  background: #313244;
  color: #cdd6f4;
}

.tie-sa-tab.is-active {
  background: #1e1e2e;
  border-color: #313244;
  color: #cdd6f4;
}

/* ── Form & panels ──────────────────────────────────────────── */

.tie-sa-form {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tie-sa-panel {
  display: none;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
  overflow-y: auto;
  max-height: calc(100vh - 200px);
}

.tie-sa-panel.is-active {
  display: flex;
}

/* ── Fields ─────────────────────────────────────────────────── */

.tie-sa-hint {
  margin: 0 0 2px;
  color: #a6adc8;
  font-size: 12px;
  line-height: 1.5;
}

.tie-sa-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tie-sa-label {
  font-size: 12px;
  font-weight: 600;
  color: #bac2de;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tie-sa-field--checkbox {
  gap: 4px;
}

.tie-sa-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #cdd6f4;
  cursor: pointer;
  user-select: none;
}

.tie-sa-checkbox-label input[type="checkbox"] {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  accent-color: #89b4fa;
  cursor: pointer;
}

.tie-sa-file-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.tie-sa-file-row input[type="text"] {
  flex: 1;
  padding: 5px 8px;
  background: #181825;
  border: 1px solid #45475a;
  border-radius: 4px;
  color: #cdd6f4;
  font-size: 13px;
  font-family: inherit;
  min-width: 0;
}

.tie-sa-file-row input[type="text"]:focus {
  outline: none;
  border-color: #89b4fa;
}

.tie-sa-browse-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  padding: 0;
  background: transparent;
  border: 1px solid #45475a;
  border-radius: 4px;
  color: #a6adc8;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}

.tie-sa-browse-btn:hover {
  background: #313244;
  color: #cdd6f4;
}

/* ── Settings select ────────────────────────────────────────── */
.tie-sa-select {
  padding: 5px 8px;
  background: #181825;
  border: 1px solid #45475a;
  border-radius: 4px;
  color: #cdd6f4;
  font-size: 13px;
  width: 100%;
}

.tie-sa-select:focus {
  outline: none;
  border-color: #89b4fa;
}

/* ── Background preview ─────────────────────────────────────── */

.tie-sa-preview {
  margin-top: 4px;
  border: 1px solid #45475a;
  border-radius: 4px;
  overflow: hidden;
  max-height: 120px;
}

.tie-sa-preview img {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: cover;
}

/* ── Licenses panel ─────────────────────────────────────────── */

.tie-sa-license-entry {
  margin-bottom: 8px;
}

.tie-sa-license-name {
  margin: 0 0 4px;
  font-size: 0.95em;
  font-weight: 600;
  color: #cdd6f4;
}

.tie-sa-license-desc {
  margin: 0 0 2px;
  font-size: 0.85em;
  color: #a6adc8;
}

.tie-sa-license-copy {
  margin: 0 0 2px;
  font-size: 0.82em;
  color: #a6adc8;
}

.tie-sa-license-type {
  margin: 0 0 4px;
  font-size: 0.82em;
  color: #a6adc8;
  font-style: italic;
}

.tie-sa-license-entry a {
  font-size: 0.82em;
  color: #89b4fa;
}

/* ── Footer ─────────────────────────────────────────────────── */

.tie-sa-footer {
  display: flex;
  justify-content: flex-end;
  padding: 10px 16px 14px;
  border-top: 1px solid #313244;
  margin-top: 4px;
}

.tie-sa-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 18px;
  background: #89b4fa;
  border: none;
  border-radius: 4px;
  color: #1e1e2e;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.tie-sa-save-btn:hover {
  background: #b4d0ff;
}

/* ── Quick Token dropdown ───────────────────────────────────────── */

.token-image-editor .tie-quick-token {
  position: relative;
}

.token-image-editor .tie-quick-token > summary {
  list-style: none;
  cursor: pointer;
}

.token-image-editor .tie-quick-token > summary::-webkit-details-marker {
  display: none;
}

.token-image-editor .tie-quick-token__caret {
  font-size: 10px;
  margin-left: 2px;
}

.token-image-editor .tie-quick-token__menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #1e1e2e;
  border: 1px solid #45475a;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  padding: 4px 0;
}

.token-image-editor .tie-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: transparent;
  border: none;
  color: #cdd6f4;
  font-size: 12px;
  cursor: pointer;
  width: 100%;
  text-align: left;
}

.token-image-editor .tie-dropdown-item:hover {
  background: #313244;
  color: #89b4fa;
}

/* ── Mode toggle ───────────────────────────────────────────────── */

.token-image-editor .tie-mode-toggle {
  display: inline-flex;
  gap: 0;
  border: 1px solid #45475a;
  border-radius: 4px;
  overflow: hidden;
}

.token-image-editor .tie-mode-toggle .tie-btn {
  border-radius: 0;
  border: none;
  padding: 4px 10px;
  font-size: 12px;
}

.token-image-editor .tie-mode-toggle .tie-btn.is-active {
  background: #45475a;
  color: #89b4fa;
  border-color: #89b4fa;
}

/* ── Avatar aspect ratio toggle ────────────────────────────────── */

.token-image-editor .tie-avatar-aspect {
  display: flex;
  width: 100%;
  border: 1px solid #45475a;
  border-radius: 4px;
  overflow: hidden;
}

.token-image-editor .tie-avatar-aspect button {
  flex: 1;
  margin: 0;
  border: none;
  border-radius: 0;
  padding: 5px 0;
  font-size: 11px;
  font-family: inherit;
  color: #a6adc8;
  background: transparent;
  cursor: pointer;
  text-align: center;
}

.token-image-editor .tie-avatar-aspect button:hover {
  background: #313244;
  color: #cdd6f4;
}

.token-image-editor .tie-avatar-aspect button.is-active {
  background: #45475a;
  color: #89b4fa;
}

/* ── Canvas size inputs ────────────────────────────────────────── */

.token-image-editor .tie-canvas-size {
  display: flex;
  align-items: center;
  gap: 6px;
}

.token-image-editor .tie-canvas-size__field {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.token-image-editor .tie-canvas-size__field label {
  font-size: 10px;
  color: #a6adc8;
  text-transform: uppercase;
}

.token-image-editor .tie-canvas-size__sep {
  color: #6c7086;
  font-size: 14px;
  margin-top: 14px;
}

.token-image-editor .tie-input--sm {
  width: 100%;
  padding: 3px 6px;
  font-size: 12px;
  background: #1e1e2e;
  border: 1px solid #45475a;
  border-radius: 4px;
  color: #cdd6f4;
}

.token-image-editor .tie-input--sm:focus {
  border-color: #89b4fa;
  outline: none;
}

/* ── Add layer dropdown ────────────────────────────────────────── */

.token-image-editor .tie-add-layer-dropdown {
  position: relative;
}

.token-image-editor .tie-add-layer-dropdown__trigger {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #a6adc8;
  font-size: 11px;
  font-weight: 600;
}

.token-image-editor .tie-add-layer-dropdown__trigger:hover {
  background: #313244;
  color: #cdd6f4;
}

.token-image-editor .tie-add-layer-dropdown__trigger::-webkit-details-marker {
  display: none;
}

.token-image-editor .tie-add-layer-dropdown__menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: #1e1e2e;
  border: 1px solid #45475a;
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
  z-index: 1000;
  min-width: 180px;
  display: flex;
  flex-direction: column;
  padding: 4px 0;
}

/* ── Editor lock state (modal SaveDialog open) ────────────────── */

.token-image-editor.is-locked .tie-layout {
  filter: brightness(0.45) saturate(0.6);
  transition: filter 120ms ease;
  pointer-events: none;
}

.token-image-editor .tie-layout {
  transition: filter 120ms ease;
}

/* ── Save dialog ─────────────────────────────────────────────── */

.tie-save-dialog .tie-save-dialog__form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  position: relative;
}

/* Hardcode text color so Foundry's light theme can't override it to black */
.tie-save-dialog .tie-save-dialog__form,
.tie-save-dialog .tie-save-row__title,
.tie-save-dialog .tie-save-row__inputgroup input[type="text"],
.tie-save-dialog input[type="text"],
.tie-save-dialog select,
.tie-save-dialog textarea {
  color: #cdd6f4;
}

.tie-save-dialog .tie-save-row {
  border: 1px solid #45475a;
  border-radius: 6px;
  background: #1e1e2e;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tie-save-dialog .tie-save-row.is-disabled {
  opacity: 0.55;
}

.tie-save-dialog .tie-save-row__header {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.tie-save-dialog .tie-save-row__title {
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.tie-save-dialog .tie-save-row__reason {
  font-size: 11px;
  font-style: italic;
  color: #a6adc8;
  margin-left: auto;
}

.tie-save-dialog .tie-save-row__fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tie-save-dialog .tie-save-row__field {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tie-save-dialog .tie-save-row__label {
  font-size: 11px;
  color: #a6adc8;
}

.tie-save-dialog .tie-save-row__inputgroup {
  display: flex;
  gap: 4px;
}

.tie-save-dialog .tie-save-row__inputgroup input[type="text"] {
  flex: 1;
}

.tie-save-dialog .tie-save-row__note {
  font-size: 11px;
  color: #f9e2af;
  margin: 0;
}

.tie-save-dialog .tie-save-row__preview {
  font-size: 11px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: #11111b;
  border-radius: 4px;
  padding: 6px 8px;
}

.tie-save-dialog .tie-save-row__preview code {
  word-break: break-all;
  font-family: monospace;
  color: #cdd6f4;
}

.tie-save-dialog .tie-save-dialog__footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid #313244;
}

.tie-save-dialog .tie-save-dialog__spacer {
  flex: 1;
}

.tie-save-dialog .tie-save-dialog__busy {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(17, 17, 27, 0.75);
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: #cdd6f4;
  border-radius: 6px;
  gap: 8px;
}

.tie-save-dialog.is-busy .tie-save-dialog__busy {
  display: flex;
}

/* ── Auto Cutout layer picker (DialogV2) ─────────────────────── */
.tie-cutout-layer-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  padding: 8px 0;
  max-height: 280px;
  overflow-y: auto;
}

.tie-cutout-layer-opt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 6px;
  border: 2px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.tie-cutout-layer-opt:has(input:checked) {
  border-color: #89b4fa;
  background: rgba(137, 180, 250, 0.12);
}

.tie-cutout-layer-opt:hover {
  border-color: #585b70;
}

.tie-cutout-layer-opt input[type="radio"] {
  display: none;
}

.tie-cutout-layer-opt__thumb {
  width: 72px;
  height: 72px;
  border-radius: 3px;
  overflow: hidden;
  background-image: linear-gradient(45deg, #313244 25%, transparent 25%),
    linear-gradient(-45deg, #313244 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #313244 75%),
    linear-gradient(-45deg, transparent 75%, #313244 75%);
  background-size: 10px 10px;
  background-position: 0 0, 0 5px, 5px -5px, -5px 0;
  background-color: #1e1e2e;
}

.tie-cutout-layer-opt__thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.tie-cutout-layer-opt__name {
  font-size: 11px;
  color: #a6adc8;
  text-align: center;
  word-break: break-word;
  max-width: 84px;
  line-height: 1.3;
}

/* ── Auto Cutout loading / progress ─────────────────────────── */
.token-image-editor .tie-cutout-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 0;
  color: #a6adc8;
  font-size: 12px;
  text-align: center;
}

.token-image-editor .tie-cutout-download-label {
  margin: 0;
}

.token-image-editor .tie-cutout-progress-bar {
  width: 100%;
  height: 6px;
  background: #313244;
  border-radius: 3px;
  overflow: hidden;
}

.token-image-editor .tie-cutout-progress-fill {
  height: 100%;
  background: #89b4fa;
  border-radius: 3px;
  transition: width 0.15s ease;
  min-width: 4px;
}

.token-image-editor .tie-cutout-download-bytes {
  margin: 0;
  font-size: 11px;
  color: #6c7086;
}

.tie-auto-tokenize .tie-at-mode {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
}

.tie-auto-tokenize .tie-at-modes,
.tie-auto-tokenize .tie-at-options {
  margin: 0 0 10px;
}

.tie-auto-tokenize .tie-at-columns {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.tie-auto-tokenize .tie-at-col-options {
  flex: 1 1 auto;
  min-width: 0;
  /* Cap height so long option lists scroll instead of pushing the Start
     button off-screen. Preview column stays sticky alongside. */
  max-height: calc(100vh - 240px);
  overflow-y: auto;
  padding-right: 8px;
}

.tie-auto-tokenize .tie-at-col-preview {
  flex: 0 0 auto;
  position: sticky;
  top: 0;
}

.tie-auto-tokenize .tie-at-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 12px;
}

.tie-auto-tokenize .tie-at-preview__frame {
  position: relative;
  width: 256px;
  height: 256px;
}

.tie-auto-tokenize .tie-at-preview__img {
  width: 256px;
  height: 256px;
  border-radius: 4px;
  background: #111;
  object-fit: contain;
}

.tie-auto-tokenize .tie-at-preview__loading {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(17, 17, 17, 0.7);
  color: #cdd6f4;
  font-size: 12px;
  border-radius: 4px;
  pointer-events: none;
}

.tie-auto-tokenize .tie-at-preview__loading .fa-spinner {
  font-size: 24px;
}

.tie-auto-tokenize .tie-at-preview.is-loading .tie-at-preview__loading {
  display: flex;
}

.tie-auto-tokenize .tie-at-preview__caption {
  font-size: 11px;
  color: #6c7086;
  margin: 4px 0 0;
}

.tie-auto-tokenize .tie-at-frame__row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tie-auto-tokenize .tie-at-frame__thumb {
  width: 48px;
  height: 48px;
  object-fit: contain;
}
