:root {
  --brand: #0f5c6e;
  --brand-dark: #0a4453;
  --brand-soft: #e6f0f2;
  --text: #14201f;
  --muted: #67777d;
  --faint: #91a0a6;
  --line: #dce3e5;
  --line-soft: #e9eef0;
  --bg: #eef1f2;
  --card: #ffffff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 1px 2px rgb(20 32 31 / 0.05);
  --shadow-lift: 0 12px 32px -12px rgb(20 32 31 / 0.28);
  --content: 1200px;
}

* {
  box-sizing: border-box;
}

/* Правила ниже задают display: flex и grid, которые перебивают атрибут
   hidden. Возвращаем ему силу. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    400 15px/1.45 "Golos Text",
    system-ui,
    -apple-system,
    sans-serif;
  -webkit-text-size-adjust: 100%;
}

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

/* ─── шапка ─────────────────────────────────────────────────────────────── */

.top {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.top .wrap {
  max-width: var(--content);
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  height: 24px;
  width: auto;
}

.tabs {
  display: flex;
  gap: 3px;
  background: var(--bg);
  padding: 3px;
  border-radius: var(--radius-sm);
}

.tabs button {
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  color: var(--muted);
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 7px;
  transition:
    background 0.12s,
    color 0.12s;
}

.tabs button:hover {
  color: var(--text);
}

.tabs button.on {
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-card);
}

.count {
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: 20px;
  background: var(--brand);
  color: #fff;
  font-size: 11.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.count:empty {
  display: none;
}

/* ─── раскладка ─────────────────────────────────────────────────────────── */

main {
  padding: 24px 20px 40px;
}

.view {
  display: flex;
  gap: 28px;
  align-items: flex-start;
  justify-content: center;
  max-width: var(--content);
  margin: 0 auto;
}

.view[hidden] {
  display: none;
}

.panel {
  flex: 0 0 372px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-card);
}

/* Ширина колонки равна ширине кадра: подпись, панель инструментов и кнопки
   встают по одной сетке, а не разъезжаются по пустой колонке. */
.stage {
  flex: 0 1 auto;
  min-width: 0;
  width: min(100%, calc((100vh - 290px) * 0.8));
  position: sticky;
  top: 84px;
}

.stage-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 10px;
}

.stage-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.badge {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 3px 10px;
}

/* ─── форма ─────────────────────────────────────────────────────────────── */

.field {
  margin-bottom: 15px;
}

.field:last-child {
  margin-bottom: 0;
}

.field > label,
.legend {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition:
    border-color 0.12s,
    box-shadow 0.12s;
}

input[type="text"]:hover,
input[type="number"]:hover {
  border-color: #c9d3d6;
}

input::placeholder {
  color: var(--faint);
}

textarea {
  resize: vertical;
  min-height: 62px;
  line-height: 1.3;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgb(15 92 110 / 0.13);
  outline: none;
}

.hint-inline {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 5px;
  min-height: 17px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
}

.segmented button {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  transition:
    background 0.12s,
    border-color 0.12s,
    color 0.12s;
}

.segmented button:hover {
  border-color: #c2ced2;
  color: var(--text);
}

.segmented button.on {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ─── предпросмотр ──────────────────────────────────────────────────────── */

.frame {
  position: relative;
  background: #1b2225;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 5;
  box-shadow: var(--shadow-lift);
  width: 100%;
  transition: outline-color 0.12s;
}

.frame.over {
  outline: 3px dashed var(--brand);
  outline-offset: -8px;
}

#preview {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#preview.dragging {
  cursor: grabbing;
}

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  color: #d5dee1;
  background: rgb(20 28 31 / 0.86);
  padding: 24px;
}

.empty b {
  font-size: 17px;
  font-weight: 700;
}

.empty span {
  font-size: 13.5px;
  color: #97a6ab;
}

.empty button {
  margin-top: 12px;
}

/* ─── кнопки ────────────────────────────────────────────────────────────── */

button {
  font: inherit;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  justify-content: space-between;
  margin: 12px 0 0;
  padding: 7px 8px 7px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.tool-buttons {
  display: flex;
  gap: 2px;
  flex: none;
}

/* Главное действие занимает всю строку, второстепенные — под ним.
   Три кнопки в ряд не помещаются в ширину кадра ни на одном экране. */
.actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 14px;
}

.actions .primary {
  grid-column: 1 / -1;
}

.zoom {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

.zoom input {
  flex: 1 1 auto;
  min-width: 80px;
  max-width: 200px;
  accent-color: var(--brand);
}

.actions button,
.empty button,
.tile-actions button,
.tools button {
  font-weight: 600;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  cursor: pointer;
  transition:
    background 0.12s,
    border-color 0.12s,
    color 0.12s;
}

.actions button:hover,
.empty button:hover {
  border-color: #c2ced2;
}

.tools button {
  padding: 7px 12px;
  font-size: 13.5px;
}

.primary {
  background: var(--brand) !important;
  border-color: var(--brand) !important;
  color: #fff !important;
}

.primary:hover:not(:disabled) {
  background: var(--brand-dark) !important;
  border-color: var(--brand-dark) !important;
}

.ghost {
  background: transparent !important;
  border-color: transparent !important;
  color: var(--muted) !important;
}

.ghost:hover:not(:disabled) {
  color: var(--text) !important;
  background: var(--bg) !important;
}

button:disabled {
  opacity: 0.55;
  cursor: progress;
}

.note {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  min-height: 20px;
  margin: 12px 0 0;
}

.note:not(:empty) {
  color: var(--brand);
  font-weight: 600;
}

/* ─── сетка ─────────────────────────────────────────────────────────────── */

#view-grid {
  flex-direction: column;
  align-items: center;
  max-width: 720px;
}

.grid-head {
  width: 100%;
  margin-bottom: 14px;
}

.grid-head h1 {
  font-size: 19px;
  font-weight: 700;
  margin: 0 0 2px;
}

.grid-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

/* Без фона и тени у контейнера: иначе пустые ячейки последнего ряда
   выглядят как незаполненные плитки. */
.tiles {
  display: grid;
  /* minmax(0, …): иначе колонка растягивается под ширину кнопок на плитке
     и сетка вылезает за экран телефона. */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 2px;
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
}

.tile {
  position: relative;
  aspect-ratio: 4 / 5;
  background: #1b2225;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

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

.tile.drag {
  opacity: 0.3;
  cursor: grabbing;
}

.tile.target::after {
  content: "";
  position: absolute;
  inset: 0;
  outline: 3px solid var(--brand);
  outline-offset: -3px;
}

.tile-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 50%;
  background: rgb(20 28 31 / 0.55);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition:
    opacity 0.14s,
    background 0.12s;
}

.tile:hover .tile-remove,
.tile-remove:focus-visible {
  opacity: 1;
}

.tile-remove:hover {
  background: #c0392b;
}

.hint {
  color: var(--muted);
  text-align: center;
  padding: 48px 20px;
  margin: 0;
}

/* ─── телефон ───────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  main {
    padding: 14px 12px 28px;
  }

  .top .wrap {
    padding: 10px 12px;
  }

  .view {
    flex-direction: column;
    gap: 16px;
  }

  .panel {
    flex: none;
    width: 100%;
    order: 2;
  }

  .stage {
    order: 1;
    width: 100%;
    position: static;
  }

  .frame,
  .tools {
    width: 100%;
  }

  .frame {
    max-height: 56vh;
  }

  /* На узком экране ползунок и кнопки не встают в одну строку. */
  .zoom {
    flex: 1 0 100%;
  }

  .zoom input {
    max-width: none;
  }

  .tools {
    justify-content: center;
  }

  /* На тач-экране наведения нет — крестик виден сразу. */
  .tile-remove {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
