/* Thumbnail Studio — full-height editor layout.
   tool-theme.css supplies the palette variables; everything else lives here. */

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body.__accessbox-thumbnail-editor {
  font-family: "Inter", system-ui, -apple-system, sans-serif;
}

.te-app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

/* ---------- Top bar ---------- */

.te-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 10px 66px;
  border-bottom: 1px solid var(--border, #ded8cd);
  background: rgba(255, 253, 248, .85);
  backdrop-filter: blur(10px);
}

.te-topbar h1 {
  margin: 0 8px 0 0;
  font-size: 1.02rem;
  font-weight: 800;
  letter-spacing: -.03em;
  white-space: nowrap;
}

.te-topbar h1 span { color: var(--ab-accent, #cf2e2e); }

.te-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 11px;
  background: rgba(248, 245, 238, .8);
}

.te-spacer { flex: 1; }

.te-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 32px;
  height: 32px;
  padding: 0 9px;
  border: 0;
  border-radius: 8px;
  color: var(--text, #191918);
  background: transparent;
  font: inherit;
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
}

.te-tool:hover:not(:disabled) { background: rgba(25, 25, 24, .07); }
.te-tool:disabled { opacity: .35; cursor: default; }
.te-tool[aria-pressed="true"] { color: #fff; background: var(--text, #191918); }
.te-tool svg { width: 16px; height: 16px; flex: none; }

.te-zoom-label {
  min-width: 46px;
  color: var(--text-secondary, #626159);
  font-size: .74rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.te-primary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 15px;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: var(--text, #191918);
  font: inherit;
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(25, 25, 24, .16);
}

.te-primary:hover { background: var(--ab-accent, #cf2e2e); }
.te-primary svg { width: 15px; height: 15px; }

/* ---------- Body grid ---------- */

.te-body {
  display: grid;
  /* The panel grows with the viewport: on an ultrawide a fixed 316px column
     leaves every control squeezed into a sliver beside an enormous stage. */
  grid-template-columns: 58px minmax(0, 1fr) clamp(316px, 21vw, 430px);
  min-height: 0;
}

/* ---------- Left rail ---------- */

.te-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 0;
  border-right: 1px solid var(--border, #ded8cd);
  background: rgba(255, 253, 248, .7);
}

.te-rail-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 48px;
  padding: 8px 0 6px;
  border: 0;
  border-radius: 11px;
  color: var(--text, #191918);
  background: transparent;
  font: inherit;
  font-size: .58rem;
  font-weight: 600;
  cursor: pointer;
}

.te-rail-btn:hover { background: rgba(25, 25, 24, .07); }
.te-rail-btn svg { width: 20px; height: 20px; }
.te-rail-sep { width: 30px; height: 1px; margin: 4px 0; background: var(--border, #ded8cd); }

/* ---------- Stage ---------- */

.te-center {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.te-stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 30%, rgba(25, 25, 24, .05), transparent 60%),
    #e9e4da;
  touch-action: none;
}

.te-canvas-wrap {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  box-shadow: 0 18px 60px rgba(35, 30, 22, .28);
}

#mainCanvas {
  display: block;
  width: 1280px;
  height: 720px;
  background:
    repeating-conic-gradient(#d8d3c9 0% 25%, #efece5 0% 50%) 0 0 / 24px 24px;
}

#overlayCanvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.te-stage-hint {
  position: absolute;
  bottom: 10px;
  left: 12px;
  color: #6c6a63;
  font-size: .68rem;
  pointer-events: none;
}

/* Empty-state quick start */
.te-quickstart {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-width: min(420px, 86%);
  padding: 26px 30px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 18px;
  background: rgba(255, 253, 248, .95);
  box-shadow: 0 22px 60px rgba(35, 30, 22, .22);
  text-align: center;
  transform: translate(-50%, -50%);
}

.te-quickstart h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -.03em;
}

.te-quickstart p {
  margin: 0;
  color: var(--text-secondary, #626159);
  font-size: .78rem;
  line-height: 1.5;
}

.te-quickstart-row { display: flex; gap: 7px; margin-top: 6px; }

.te-quickstart-row button {
  padding: 8px 14px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 10px;
  color: var(--text, #191918);
  background: #fff;
  font: inherit;
  font-size: .76rem;
  font-weight: 700;
  cursor: pointer;
}

.te-quickstart-row button:hover { border-color: var(--text, #191918); }

.te-quickstart-row button:first-child {
  color: #fff;
  border-color: var(--text, #191918);
  background: var(--text, #191918);
}

.te-quickstart-row button:first-child:hover { border-color: var(--ab-accent); background: var(--ab-accent, #cf2e2e); }

.te-quickstart > span { color: var(--quiet, #928f85); font-size: .66rem; }
.te-quickstart > .te-hint-touch { display: none; }

@media (hover: none) and (pointer: coarse) {
  .te-quickstart > .te-hint-mouse { display: none; }
  .te-quickstart > .te-hint-touch { display: inline; }
  /* A long press on the canvas is a held finger, not a text selection. */
  .te-stage { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
}

.te-stage.is-dragging::after {
  position: absolute;
  inset: 8px;
  z-index: 4;
  border: 2px dashed var(--ab-accent, #cf2e2e);
  border-radius: 14px;
  background: rgba(207, 46, 46, .06);
  content: "";
  pointer-events: none;
}

/* ---------- Preview strip ---------- */

.te-previews {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 9px 14px;
  border-top: 1px solid var(--border, #ded8cd);
  background: rgba(255, 253, 248, .8);
  overflow-x: auto;
}

.te-previews-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.te-previews-toggle:hover { background: rgba(25, 25, 24, .06); }

.te-previews-toggle strong {
  color: var(--text-secondary, #626159);
  font-size: .64rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.te-previews-toggle span {
  color: var(--quiet, #928f85);
  font-size: .7rem;
  transition: transform .18s;
}

.te-previews.is-collapsed .te-preview-item { display: none; }
.te-previews.is-collapsed { padding-top: 4px; padding-bottom: 4px; }
.te-previews.is-collapsed .te-previews-toggle span { transform: rotate(-90deg); }

.te-preview-item { display: flex; align-items: center; gap: 9px; flex: none; }

.te-preview-thumb { position: relative; flex: none; }

.te-preview-thumb canvas {
  display: block;
  border-radius: 8px;
  background: #111;
}

.te-preview-badge {
  position: absolute;
  right: 4px;
  bottom: 4px;
  padding: 1px 4px;
  border-radius: 3px;
  color: #fff;
  background: rgba(0, 0, 0, .82);
  font-size: .56rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.te-preview-meta { display: flex; flex-direction: column; gap: 4px; }
.te-preview-meta i { width: 120px; height: 8px; border-radius: 4px; background: #d5d0c6; }
.te-preview-meta i + i { width: 74px; background: #e2ddd3; }
.te-preview-meta.small i { width: 78px; height: 6px; }
.te-preview-meta.small i + i { width: 48px; }

/* ---------- Right panel ---------- */

.te-side {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  border-left: 1px solid var(--border, #ded8cd);
  background: rgba(255, 253, 248, .85);
}

.te-props {
  min-height: 0;
  padding: 0 14px 20px;
  overflow-y: auto;
}

/* The name and the tab strip stay put while the sections below them scroll. */
.te-props-top {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 12px 0 10px;
  background: linear-gradient(rgba(255, 253, 248, .97) 78%, rgba(255, 253, 248, 0));
}

.te-props-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.te-props-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 7px;
  background: rgba(226, 221, 211, .8);
  color: var(--text-secondary, #626159);
  font-size: .68rem;
}

.te-tabs { margin-top: 9px; }
.te-tabs button { height: 24px; font-size: .68rem; font-weight: 700; }

.te-props-head h2 {
  flex: 1;
  margin: 0;
  font-size: .86rem;
  font-weight: 800;
  letter-spacing: -.02em;
}

.te-icon-btn {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 8px;
  color: var(--text, #191918);
  background: #fff;
  cursor: pointer;
}

.te-icon-btn:hover { border-color: var(--border-hover, #aaa297); background: #faf7f0; }
.te-icon-btn svg { width: 14px; height: 14px; }
.te-icon-btn.danger:hover { color: #fff; border-color: #c0392b; background: #c0392b; }

.te-section {
  margin-bottom: 8px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 13px;
  background: rgba(255, 255, 255, .75);
}

.te-section > summary {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 12px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-secondary, #626159);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.te-section > summary::-webkit-details-marker { display: none; }
.te-section > summary::after {
  margin-left: auto;
  color: var(--quiet, #928f85);
  content: "▸";
  font-size: .68rem;
  transition: transform .15s;
}
.te-section[open] > summary::after { transform: rotate(90deg); }

.te-section-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 12px 13px;
}

.te-row { display: flex; align-items: center; gap: 8px; min-height: 32px; }
.te-row-split { gap: 8px; }
.te-row-split > .te-seg { flex: 1 1 0; }

.te-row > label {
  flex: none;
  width: 74px;
  color: var(--text-secondary, #626159);
  font-size: .71rem;
  font-weight: 600;
  line-height: 1.25;
}

.te-row-value {
  flex: none;
  min-width: 36px;
  color: var(--quiet, #928f85);
  font-size: .68rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.te-props input[type="range"] {
  flex: 1;
  min-width: 0;
  height: 26px;
  margin: 0;
  accent-color: var(--ab-accent, #cf2e2e);
}

.te-props input[type="color"] {
  width: 34px;
  height: 32px;
  flex: none;
  padding: 2px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

.te-props input[type="color"]:hover { border-color: var(--border-hover, #aaa297); }
.te-props input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.te-props input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 5px; }

.te-props input[type="number"],
.te-props input[type="text"],
.te-props select,
.te-props textarea {
  min-width: 0;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 8px;
  color: var(--text, #191918);
  background: #fff;
  font: inherit;
  font-size: .76rem;
}

.te-props select {
  flex: 1;
  height: 32px;
  padding-right: 26px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8l3.5-3.5' stroke='%23626159' stroke-width='1.4' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 12px;
  appearance: none;
  -webkit-appearance: none;
}

.te-props textarea {
  width: 100%;
  height: auto;
  min-height: 60px;
  padding: 8px 9px;
  resize: vertical;
  line-height: 1.45;
}

.te-props input[type="number"] { width: 100%; }

.te-inline-btn {
  flex: none;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 8px;
  color: var(--text, #191918);
  background: #fff;
  font: inherit;
  font-size: .69rem;
  font-weight: 700;
  cursor: pointer;
}

.te-inline-btn:hover:not(:disabled) { border-color: var(--text, #191918); }
.te-inline-btn:disabled { opacity: .45; cursor: default; }

.te-seg {
  display: flex;
  flex: 1;
  min-width: 0;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 9px;
  background: rgba(245, 242, 234, .95);
}

.te-seg button {
  display: grid;
  place-items: center;
  flex: 1;
  min-width: 0;
  height: 26px;
  padding: 0 4px;
  border: 0;
  border-radius: 6px;
  color: var(--text-secondary, #626159);
  background: transparent;
  font: inherit;
  font-size: .69rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.te-seg button svg { width: 14px; height: 14px; }
.te-seg button:hover { color: var(--text, #191918); }
.te-seg button[aria-disabled="true"],
.te-seg button[aria-disabled="true"]:hover { color: var(--text-secondary, #626159); opacity: .4; cursor: default; }
.te-seg button[aria-pressed="true"] {
  color: var(--text, #191918);
  background: #fff;
  box-shadow: 0 1px 4px rgba(25, 25, 24, .14);
}

.te-mini-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; }
.te-mini-grid.cols3 { grid-template-columns: repeat(3, 1fr); }
.te-mini-grid.cols2 { grid-template-columns: repeat(2, 1fr); }

.te-mini-btn {
  display: grid;
  place-items: center;
  height: 32px;
  padding: 0 4px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 8px;
  color: var(--text, #191918);
  background: #fff;
  font: inherit;
  font-size: .68rem;
  font-weight: 600;
  cursor: pointer;
}

.te-mini-btn:hover { border-color: var(--border-hover, #aaa297); background: #faf7f0; }
.te-mini-btn:active { transform: translateY(1px); }
.te-mini-btn svg { width: 16px; height: 16px; }
.te-mini-btn.is-wide { font-size: .7rem; font-weight: 700; }
.te-mini-btn[aria-pressed="true"] { color: #fff; border-color: var(--text); background: var(--text); }

/* Swatches sit on a fixed 8-column grid so every row fills edge to edge. */
.te-swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.te-swatches button {
  aspect-ratio: 1;
  width: 100%;
  padding: 0;
  border: 1px solid rgba(25, 25, 24, .2);
  border-radius: 6px;
  cursor: pointer;
}

.te-swatches button:hover {
  border-color: var(--text, #191918);
  transform: scale(1.12);
}

/* The saved palette grows one swatch at a time, so it packs from the left. */
.te-swatches.is-loose { display: flex; flex-wrap: wrap; gap: 4px; }
.te-swatches.is-loose button { width: 22px; height: 22px; aspect-ratio: auto; }

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

.te-field-label {
  color: var(--quiet, #928f85);
  font-size: .6rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.te-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  font-size: .73rem;
  font-weight: 600;
}
.te-toggle-row label { flex: 1; min-width: 0; cursor: pointer; }
.te-toggle-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  flex: none;
  margin: 0;
  accent-color: var(--ab-accent, #cf2e2e);
  cursor: pointer;
}

.te-note { margin: 0; color: var(--quiet, #928f85); font-size: .67rem; line-height: 1.5; }

/* Preset chips (text styles, filter looks) */
.te-chiprow { display: flex; flex-wrap: wrap; gap: 4px; }

.te-chip {
  padding: 4px 9px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 99px;
  color: var(--text, #191918);
  background: #fff;
  font: inherit;
  font-size: .66rem;
  font-weight: 700;
  cursor: pointer;
}

.te-chip:hover { border-color: var(--text, #191918); }

/* Labeled slider clusters */
.te-tri { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.te-tri.cols2 { grid-template-columns: repeat(2, 1fr); }
.te-tri > div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.te-tri span { color: var(--quiet, #928f85); font-size: .6rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.te-tri input[type="range"] { width: 100%; }

/* Numeric position grid */
.te-quad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.te-quad label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  color: var(--quiet, #928f85);
  font-size: .58rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.te-quad input[type="number"] { width: 100%; padding: 0 6px; font-size: .72rem; }

/* Sub-card for a cluster that belongs together (the AI cutout controls). */
.te-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 9px 10px 10px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 10px;
  background: rgba(245, 242, 234, .55);
}

.te-block > .te-row { min-height: 28px; }
.te-block > .te-row > label { width: 52px; }

/* Quiet action that would shout as a full-width button. */
.te-text-btn {
  align-self: flex-start;
  padding: 3px 8px;
  border: 0;
  border-radius: 7px;
  color: var(--text-secondary, #626159);
  background: transparent;
  font: inherit;
  font-size: .68rem;
  font-weight: 700;
  cursor: pointer;
}

.te-text-btn:hover { color: var(--text, #191918); background: rgba(226, 221, 211, .7); }
.te-text-btn.is-full {
  align-self: stretch;
  padding: 6px 8px;
  border: 1px solid rgba(222, 216, 205, .9);
  background: rgba(255, 255, 255, .55);
  text-align: center;
}

.te-field-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.te-field-head .te-text-btn { margin: -3px -4px -3px 0; }

.te-tri b { color: var(--text-secondary, #626159); font-weight: 700; font-variant-numeric: tabular-nums; }

.te-mini-grid.cols1 { grid-template-columns: 1fr; }
.te-mini-btn.is-accent { color: #fff; border-color: var(--text); background: var(--text); }
.te-mini-btn.is-accent:hover { border-color: var(--ab-accent); background: var(--ab-accent); }
.te-mini-btn:disabled { opacity: .5; cursor: default; }
.te-mini-btn:disabled:hover { border-color: var(--border, #ded8cd); background: #fff; }
.te-mini-btn.is-accent:disabled:hover { border-color: var(--text); background: var(--text); }

/* Shortcut list in the help popover */
.te-help-pop { width: 268px; }
.te-help-list { display: flex; flex-direction: column; gap: 5px; margin: 0 0 9px; }
.te-help-list > div { display: flex; align-items: baseline; gap: 9px; }
.te-help-list dt {
  flex: none;
  min-width: 84px;
  color: var(--text, #191918);
  font-size: .66rem;
  font-weight: 700;
}
.te-help-list dd { margin: 0; color: var(--text-secondary, #626159); font-size: .69rem; }

.te-swatches .te-grad { border: 1px solid rgba(25, 25, 24, .2); }
.te-swatch-add {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  aspect-ratio: auto !important;
  border: 1px dashed var(--border-hover, #aaa297) !important;
  border-radius: 6px;
  color: var(--text-secondary, #626159);
  background: transparent !important;
  font-size: .8rem;
  line-height: 1;
  cursor: pointer;
}
.te-swatch-add:hover { border-color: var(--text, #191918) !important; color: var(--text, #191918); }

/* Rail button active state + attention flash */
.te-rail-btn[aria-pressed="true"] { color: #fff; background: var(--text, #191918); }
.te-rail-btn[aria-pressed="true"]:hover { background: var(--text, #191918); }

@keyframes te-flash-anim {
  0% { box-shadow: 0 0 0 3px color-mix(in srgb, var(--ab-accent, #cf2e2e) 45%, transparent); }
  100% { box-shadow: 0 0 0 3px transparent; }
}
.te-flash { animation: te-flash-anim .9s ease-out 2; }

.te-wide-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 9px;
  color: var(--text, #191918);
  background: #fff;
  font: inherit;
  font-size: .75rem;
  font-weight: 700;
  cursor: pointer;
}

.te-wide-btn:hover:not(:disabled) { border-color: var(--border-hover, #aaa297); background: #faf7f0; }
.te-wide-btn:disabled { opacity: .5; cursor: default; }
.te-wide-btn svg { width: 14px; height: 14px; }
.te-wide-btn.accent { color: #fff; border-color: var(--text); background: var(--text); }
.te-wide-btn.accent:hover:not(:disabled) { border-color: var(--ab-accent); background: var(--ab-accent); }

/* Font picker button + popover list */
.te-font-btn {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 8px;
  color: var(--text, #191918);
  background: #fff;
  font-size: .95rem;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.te-font-btn:hover { border-color: var(--border-hover, #aaa297); }

/* ---------- Layers panel ---------- */

.te-layers {
  border-top: 1px solid var(--border, #ded8cd);
  padding: 10px 12px 12px;
  background: rgba(248, 245, 238, .75);
}

.te-layers-head {
  display: flex;
  align-items: center;
  margin-bottom: 7px;
  color: var(--text-secondary, #626159);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.te-layers-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: min(260px, 30vh);
  overflow-y: auto;
}

.te-layer-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 7px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
  user-select: none;
}

.te-layer-item:hover { border-color: var(--border, #ded8cd); }
.te-layer-item.is-selected { border-color: var(--text, #191918); box-shadow: 0 1px 6px rgba(25, 25, 24, .12); }
.te-layer-item.is-hidden { opacity: .45; }
.te-layer-item.drag-over-top { box-shadow: 0 -2px 0 var(--ab-accent, #cf2e2e); }
.te-layer-item.drag-over-bottom { box-shadow: 0 2px 0 var(--ab-accent, #cf2e2e); }

.te-layer-icon {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 6px;
  background: rgba(25, 25, 24, .06);
  font-size: .68rem;
}

.te-layer-name {
  flex: 1;
  min-width: 0;
  font-size: .74rem;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.te-layer-item .te-layer-mini {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  border: 0;
  border-radius: 6px;
  color: var(--quiet, #928f85);
  background: transparent;
  cursor: pointer;
}

.te-layer-item .te-layer-mini:hover { color: var(--text, #191918); background: rgba(25, 25, 24, .07); }
.te-layer-item .te-layer-mini svg { width: 13px; height: 13px; }

.te-layers-empty { color: var(--quiet, #928f85); font-size: .72rem; }

/* ---------- Popovers ---------- */

.te-pop {
  position: fixed;
  z-index: 60;
  min-width: 200px;
  max-width: 330px;
  max-height: min(430px, 70vh);
  padding: 10px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 14px;
  background: #fffdf8;
  box-shadow: 0 18px 50px rgba(35, 30, 22, .22);
  overflow-y: auto;
}

.te-pop h3 {
  margin: 2px 2px 8px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--text-secondary, #626159);
}

.te-pop-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }

.te-pop-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 9px 4px 7px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 10px;
  background: #fff;
  font: inherit;
  font-size: .64rem;
  font-weight: 600;
  cursor: pointer;
}

.te-pop-item:hover { border-color: var(--text, #191918); }
.te-pop-item svg { width: 22px; height: 22px; }

.te-sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }

.te-sticker {
  position: relative;
  aspect-ratio: 1;
  padding: 4px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 10px;
  background: repeating-conic-gradient(#e7e2d8 0% 25%, #f7f4ee 0% 50%) 0 0 / 14px 14px;
  cursor: pointer;
  overflow: hidden;
}

.te-sticker:hover { border-color: var(--text, #191918); }

.te-sticker img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.te-sticker-del {
  position: absolute;
  top: 2px;
  right: 2px;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 5px;
  color: #fff;
  background: rgba(25, 25, 24, .72);
  font-size: .62rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
}

.te-sticker:hover .te-sticker-del { opacity: 1; }
.te-sticker-del:hover { background: #c0392b; }

/* With no hover to reveal it, an invisible ✕ still took the tap and deleted
   the sticker, so on touch it is shown, and sized for a finger. */
@media (hover: none) {
  .te-sticker-del { width: 22px; height: 22px; font-size: .72rem; opacity: 1; }
}

/* ---------- Layouts modal ---------- */

/* Doubled class beats the base .te-modal rule that appears later in this file. */
.te-modal.te-layouts-modal {
  display: flex;
  flex-direction: column;
  width: min(920px, 100%);
  max-height: min(680px, calc(100vh - 40px));
  padding: 20px 22px 22px;
}

.te-layouts-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.te-layouts-head h2 {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -.02em;
}

.te-layouts-note {
  margin: 0;
  color: var(--text-secondary, #626159);
  font-size: .74rem;
  line-height: 1.5;
}

.te-layouts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  /* The cards clip their corners (overflow: hidden), which zeroes their minimum
     size — auto rows would collapse to fit the modal instead of scrolling. */
  grid-auto-rows: max-content;
  gap: 12px;
  min-height: 0;
  padding: 2px;
  overflow-y: auto;
}

.te-layout-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 12px;
  background: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}

.te-layout-card:hover {
  border-color: var(--text, #191918);
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(35, 30, 22, .14);
}

.te-layout-card canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #101418;
}

.te-layout-card-meta { display: block; padding: 8px 11px 10px; }
.te-layout-card-meta strong { display: block; font-size: .78rem; }
.te-layout-card-meta span { display: block; color: var(--text-secondary, #626159); font-size: .68rem; line-height: 1.35; }

.te-font-list { display: flex; flex-direction: column; gap: 2px; }
.te-font-list button {
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  font-size: 1.05rem;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.te-font-list button:hover { background: rgba(25, 25, 24, .07); }
.te-font-list button.is-current { background: rgba(207, 46, 46, .1); }

/* Saved projects */
.te-projects-pop { width: 320px; }

.te-save-row { display: flex; gap: 6px; margin-bottom: 10px; }
.te-save-row input {
  flex: 1;
  min-width: 0;
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 8px;
  color: var(--text, #191918);
  background: #fff;
  font: inherit;
  font-size: .78rem;
}

.te-inline-btn.is-primary {
  color: #fff;
  border-color: var(--text, #191918);
  background: var(--text, #191918);
}
.te-inline-btn.is-primary:hover:not(:disabled) { border-color: var(--ab-accent, #cf2e2e); background: var(--ab-accent, #cf2e2e); }

.te-project-list { display: flex; flex-direction: column; gap: 5px; }

.te-project {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 10px;
  background: #fff;
  cursor: pointer;
  text-align: left;
}

.te-project:hover { border-color: var(--text, #191918); }

.te-project img {
  width: 56px;
  height: 31.5px;
  flex: none;
  border-radius: 5px;
  object-fit: cover;
  background: #16181c;
}

.te-project-meta { flex: 1; min-width: 0; }
.te-project-meta strong {
  display: block;
  font-size: .76rem;
  font-weight: 700;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.te-project-meta span { color: var(--quiet, #928f85); font-size: .65rem; }

.te-project-del {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  flex: none;
  border: 0;
  border-radius: 7px;
  color: var(--quiet, #928f85);
  background: transparent;
  font-size: .72rem;
  cursor: pointer;
}
.te-project-del:hover { color: #fff; background: #c0392b; }

.te-pop-footer {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border, #ded8cd);
}
.te-pop-footer .te-inline-btn { flex: 1; }

.te-export-pop { width: 300px; }
.te-export-pop .te-row > label { width: 88px; }
.te-export-size {
  margin: 4px 0 0;
  color: var(--text-secondary, #626159);
  font-size: .72rem;
  font-variant-numeric: tabular-nums;
}
.te-export-size.is-over { color: #c0392b; font-weight: 700; }

/* ---------- Confirm modal ---------- */

.te-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(28, 24, 18, .42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

.te-modal {
  width: min(380px, 100%);
  padding: 22px 24px 18px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 16px;
  background: #fffdf8;
  box-shadow: 0 26px 70px rgba(35, 30, 22, .3);
}

.te-modal h2 {
  margin: 0 0 7px;
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -.02em;
}

.te-modal p {
  margin: 0 0 18px;
  color: var(--text-secondary, #626159);
  font-size: .82rem;
  line-height: 1.55;
}

.te-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.te-modal-btn {
  padding: 8px 16px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 10px;
  color: var(--text, #191918);
  background: #fff;
  font: inherit;
  font-size: .8rem;
  font-weight: 700;
  cursor: pointer;
}

.te-modal-btn:hover { border-color: var(--border-hover, #aaa297); background: #faf7f0; }

.te-modal-btn.is-primary {
  color: #fff;
  border-color: var(--text, #191918);
  background: var(--text, #191918);
}

.te-modal-btn.is-primary:hover { border-color: var(--ab-accent, #cf2e2e); background: var(--ab-accent, #cf2e2e); }

/* Inline layer rename */
.te-layer-rename {
  flex: 1;
  min-width: 0;
  padding: 2px 5px;
  border: 1px solid var(--ab-accent, #cf2e2e);
  border-radius: 6px;
  color: var(--text, #191918);
  background: #fff;
  font: inherit;
  font-size: .74rem;
  font-weight: 600;
}

/* ---------- Toast ---------- */

.te-toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(520px, 90vw);
  padding: 10px 16px;
  border: 1px solid var(--border, #ded8cd);
  border-radius: 12px;
  color: var(--text, #191918);
  background: #fffdf8;
  box-shadow: 0 14px 40px rgba(35, 30, 22, .25);
  font-size: .78rem;
  font-weight: 600;
  transform: translateX(-50%);
  transition: opacity .2s, translate .2s;
}

.te-toast[hidden] { display: none; }

.te-toast .te-spin {
  width: 15px;
  height: 15px;
  flex: none;
  border: 2px solid var(--border, #ded8cd);
  border-top-color: var(--ab-accent, #cf2e2e);
  border-radius: 50%;
  animation: te-rotate .8s linear infinite;
}

@keyframes te-rotate { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */

@media (max-width: 1020px) {
  html, body { overflow: auto; }
  .te-app { height: auto; }
  .te-body { grid-template-columns: 1fr; }
  .te-rail {
    flex-direction: row;
    justify-content: flex-start;
    overflow-x: auto;
    padding: 6px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--border, #ded8cd);
  }
  .te-rail-sep { width: 1px; height: 30px; margin: 0 4px; }
  /* In this auto-height column, flex: 1 resolves to a zero basis and the
     stage collapsed to nothing, so no narrow screen ever showed the canvas.
     It is sized to the 16:9 canvas plus room for the rotate handle. */
  .te-stage { flex: none; height: min(62vh, calc(56.25vw + 72px)); }
  .te-side { max-height: none; border-left: 0; border-top: 1px solid var(--border, #ded8cd); }
  .te-topbar { flex-wrap: wrap; padding-left: 62px; }
}

/* The shortcut list is all keys, which a touch screen has none of. */
@media (max-width: 1020px) and (hover: none) and (pointer: coarse) {
  .te-help-group { display: none; }
}

/* On a phone the top bar wrapped to three rows and pushed the canvas a third
   of the way down the screen. The title and the Projects label go; the home
   button and the folder icon already say both. */
@media (max-width: 520px) {
  .te-topbar { gap: 8px; padding-right: 10px; }
  .te-topbar h1,
  .te-tool-label { display: none; }
  .te-quickstart { padding: 20px 18px; }
  .te-quickstart-row button { padding: 8px 11px; white-space: nowrap; }
}
