@font-face {
  font-family: "Noto Sans";
  font-style: normal;
  font-weight: 500;
  font-display: block;
  src: url("/static/fonts/noto-sans-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "Noto Sans";
  font-style: normal;
  font-weight: 500;
  font-display: block;
  src: url("/static/fonts/noto-sans-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "Arimo";
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url("/static/fonts/arimo-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

@font-face {
  font-family: "Arimo";
  font-style: normal;
  font-weight: 400;
  font-display: block;
  src: url("/static/fonts/arimo-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --bg: #f3f4f6;
  --panel: #ffffff;
  --border: #d8dbe0;
  --text: #16181d;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --danger: #dc2626;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.topbar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.btn:hover:not(:disabled) {
  background: #f8f9fb;
  border-color: #c3c8d0;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 0;
}

.palette {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px;
  background: var(--panel);
  border-right: 1px solid var(--border);
}

.palette h2 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.palette .hint {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  overflow-y: auto;
  padding-bottom: 8px;
}

.thumb {
  appearance: none;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  aspect-ratio: 1;
  cursor: grab;
}

.thumb:hover {
  border-color: var(--accent);
}

.thumb:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.thumb:active {
  cursor: grabbing;
}

.thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.workspace {
  min-width: 0;
  min-height: 0;
  display: flex;
  padding: 16px;
  /* At the minimum scale the stage can be wider than the window: let the
     workspace scroll instead of hiding the right edge. */
  overflow: auto;
}

.stage-wrap {
  position: relative;
  overflow: hidden;
  margin: auto;
}

.stage {
  position: relative;
  width: 1200px;
  height: 900px;
  transform-origin: top left;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08), 0 8px 24px rgba(16, 24, 40, 0.1);
  --s: 1;
}

.stage.drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
}

#bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  user-select: none;
  pointer-events: none;
}

#items {
  position: absolute;
  inset: 0;
  overflow: hidden;
  /* Own stacking context: item z-indices stay below the title and the overlay,
     which is also what the exported PNG draws (images, then the title). */
  z-index: 0;
}

.item {
  position: absolute;
  top: 0;
  left: 0;
  touch-action: none;
  cursor: grab;
  will-change: transform;
  outline: none;
}

.item:focus-visible {
  outline: calc(2px / var(--s)) solid var(--accent);
  outline-offset: calc(2px / var(--s));
}

.item:active {
  cursor: grabbing;
}

.item img {
  display: block;
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
}

#title {
  position: absolute;
  left: 64px;
  top: 92px;
  min-width: 260px;
  font: 500 26px "Noto Sans", Arimo, Arial, Helvetica, sans-serif;
  line-height: 26px;
  color: #000;
  white-space: pre;
  overflow: hidden;
  outline: none;
  cursor: text;
  caret-color: #000;
  z-index: 1;
}

#title:focus {
  background: rgba(37, 99, 235, 0.06);
  outline: 1px dashed rgba(37, 99, 235, 0.5);
  outline-offset: 3px;
}

#title:empty::before {
  content: "Заголовок";
  color: #c7cbd2;
  pointer-events: none;
}

#title:focus:empty::before {
  content: "";
}

#overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.selection {
  position: absolute;
  top: 0;
  left: 0;
  outline: calc(1px / var(--s)) solid var(--accent);
  outline-offset: calc(1px / var(--s));
}

.selection .handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: calc(18px / var(--s));
  height: calc(18px / var(--s));
  background: var(--accent);
  border: calc(2px / var(--s)) solid #fff;
  border-radius: calc(3px / var(--s));
  cursor: nwse-resize;
  pointer-events: auto;
  touch-action: none;
}

.selection .handle:focus-visible {
  outline: calc(2px / var(--s)) solid #fff;
  outline-offset: calc(2px / var(--s));
}

.selection .remove {
  position: absolute;
  right: 0;
  top: 0;
  transform: translate(50%, -50%);
  width: calc(22px / var(--s));
  height: calc(22px / var(--s));
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font: 600 calc(15px / var(--s)) / 1 system-ui, sans-serif;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.selection .remove:hover {
  background: #b91c1c;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #16181d;
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.25);
  z-index: 10;
}
