/* илюха рисует — общие токены и компоненты для всех экранов */

:root {
  --paper: #FBF6EC;
  --paper-soft: #F3EBDA;
  --ink: #211C18;
  --ink-soft: #71655C;
  --ink-faint: #A0938A;
  --accent: #E0357E;
  --accent-ink: #FFFFFF;
  --accent-soft: rgba(224, 53, 126, 0.13);
  --gold: #CC8A1E;
  --line: rgba(33, 28, 24, 0.13);
  --line-strong: rgba(33, 28, 24, 0.24);
  --shadow-color: 25 30% 10%;
  --hue-teal: #1E8C74;
  --hue-blue: #3E8FD1;
  --hue-violet: #8A5CD1;
  --hue-coral: #E8432E;
  --hue-gold: #CC8A1E;
  --hue-pink: #E0357E;
  --font-display: 'Unbounded', 'Arial Narrow', sans-serif;
  --font-body: 'Golos Text', 'Segoe UI', system-ui, sans-serif;
  /* тема всегда светлая: картины задуманы на светлой «бумаге» */
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  min-height: 100vh;
  position: relative;
  isolation: isolate;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  opacity: 0.05;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

h1, h2, h3 { text-wrap: balance; margin: 0; }
button { font-family: inherit; }
p { margin: 0; }

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

a { color: inherit; text-decoration: none; }

/* shared svg blur filter, defined once in base.html defs, used by placeholder art */
.svg-defs { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- app chrome ---------- */

.app {
  width: 100%;
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: 18px 18px 22px;
  gap: 18px;
}

.header-bar {
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
}

.wordmark span { color: var(--accent); }

.work-count {
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  /* название стало длиннее — подпись справа переносится, а не вылезает за шапку */
  min-width: 0;
  text-align: right;
  text-wrap: balance;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1.5px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s ease;
}

.icon-btn:hover { background: var(--accent-soft); }
.icon-btn svg { width: 17px; height: 17px; }

/* ---------- category picker (главная) ---------- */

.filters-row {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.category-picker { position: relative; flex: 1; min-width: 0; }

.category-trigger {
  width: 100%;
  background: transparent;
  border: 1.5px solid var(--line-strong);
  color: var(--ink);
  border-radius: 999px;
  padding: 12px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

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

.category-trigger .chev {
  width: 16px; height: 16px;
  transition: transform 0.2s ease;
  color: var(--ink-soft);
  flex-shrink: 0;
}

.category-trigger[aria-expanded="true"] .chev { transform: rotate(180deg); }

.category-trigger .label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-sheet {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 6px;
  box-shadow: 0 18px 40px -12px hsl(var(--shadow-color) / 0.35);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.category-sheet[hidden] { display: none; }

.category-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 0.88rem;
  color: var(--ink);
  cursor: pointer;
}

.category-option:hover { background: var(--accent-soft); }

.category-option[aria-selected="true"] {
  color: var(--accent);
  font-weight: 600;
}

.category-option .count {
  font-size: 0.72rem;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.category-option[aria-selected="true"] .count { color: var(--accent); }

.category-option .label-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cat-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  flex-shrink: 0;
  background: var(--dot-color, var(--ink-faint));
}

/* ---------- stage / стопка холстов ---------- */

.stage-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  min-height: 0;
}

.progress-row { display: flex; gap: 4px; }

.progress-seg {
  flex: 1;
  height: 3px;
  border-radius: 3px;
  background: var(--line);
  overflow: hidden;
}

.progress-seg span {
  display: block;
  height: 100%;
  background: var(--accent);
  width: 0%;
}

.progress-seg[data-state="done"] span { width: 100%; opacity: 0.55; }
.progress-seg[data-state="active"] span { width: 100%; }

.stage-frame {
  position: relative;
  aspect-ratio: 1 / 1;
  width: 100%;
}

.stage-frame::before,
.stage-frame::after {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid var(--line);
  border-radius: 22px;
}

.stage-frame::before {
  background: color-mix(in srgb, var(--hue-teal) 16%, var(--paper-soft));
  transform: rotate(-4deg);
  z-index: 1;
}
.stage-frame::after {
  background: color-mix(in srgb, var(--hue-gold) 18%, var(--paper-soft));
  transform: rotate(3deg);
  z-index: 1;
}

.canvas-card {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: var(--paper-soft);
  border: 1px solid var(--line-strong);
  border-radius: 22px;
  padding: 12px;
  box-shadow: 0 18px 34px -16px hsl(var(--shadow-color) / 0.45);
  touch-action: pan-y;
}

.canvas-card.tappable { cursor: pointer; }

.canvas-mat {
  width: 100%;
  height: 100%;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 0 0 1px hsl(var(--shadow-color) / 0.25) inset;
  background: var(--paper);
}

.canvas-mat svg,
.canvas-mat img,
.detail-image svg,
.detail-image img,
.order-thumb svg,
.order-thumb img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.canvas-mat svg,
.canvas-mat img {
  transition: opacity 0.25s ease;
}

/* картину показываем целиком: рамка квадратная, вокруг — поле паспарту со всех
   сторон (object-fit работает внутри padding), тень ложится только под саму картину */
.canvas-mat img {
  object-fit: contain;
  padding: 9%;
  filter: drop-shadow(0 6px 10px hsl(var(--shadow-color) / 0.28));
}

.canvas-mat.swapping svg,
.canvas-mat.swapping img { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .canvas-mat svg, .canvas-mat img { transition: none; }
}

/* ---------- плашка «философия» раздела (главная) ---------- */

.philosophy {
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: 20px;
  flex-shrink: 0;
}

.philosophy summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
}

.philosophy summary::-webkit-details-marker { display: none; }

.philosophy-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.philosophy .chev {
  width: 16px; height: 16px;
  color: var(--ink-soft);
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.philosophy[open] .chev { transform: rotate(180deg); }

.philosophy-text {
  padding: 0 16px 16px;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.philosophy-text p + p { margin-top: 0.7em; }

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

/* ---------- пустое состояние (нет картин в разделе) ---------- */

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding: 24px;
  color: var(--ink-soft);
}

.empty-state strong { color: var(--ink); font-family: var(--font-display); font-size: 1rem; }
.empty-state p { font-size: 0.85rem; max-width: 24ch; }

/* ---------- кнопки навигации / действия ---------- */

.nav-row { display: flex; gap: 10px; flex-shrink: 0; }

.pill-btn {
  flex: 1;
  height: 52px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, filter 0.15s ease;
  border: 1.5px solid transparent;
}

.pill-btn:active { transform: scale(0.97); }
.pill-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.pill-btn.outline {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink);
}
.pill-btn.outline:hover { background: var(--paper-soft); }

.pill-btn.solid {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.pill-btn.solid:hover { filter: brightness(1.06); }

/* во всю ширину — в колонке flex: 1 съедал высоту кнопки */
.pill-btn.wide { width: 100%; flex: none; }
.pill-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- экран описания картины ---------- */

.detail-image {
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  box-shadow: 0 18px 34px -16px hsl(var(--shadow-color) / 0.45);
  flex-shrink: 0;
}

/* с фото рамка повторяет пропорции картины (размеры берутся из width/height у img) */
.detail-image.has-photo {
  aspect-ratio: auto;
  background: var(--paper);
}

.detail-image.has-photo img {
  height: auto;
  max-height: min(60dvh, 480px);
  object-fit: contain;
}

.detail-card {
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.detail-eyebrow {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.detail-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: -0.01em;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.detail-meta span b { color: var(--ink); font-weight: 600; }

.detail-desc {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.detail-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
  margin-top: auto;
}

.price-tag {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.price-tag small {
  display: block;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 0.68rem;
  color: var(--ink-faint);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- экран оформления заказа ---------- */

.order-card {
  background: var(--paper-soft);
  border: 1px solid var(--line);
  border-radius: 26px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.order-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px;
}

.order-thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--line);
}

.order-summary-text { min-width: 0; flex: 1; }

.order-summary-title {
  font-weight: 600;
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order-summary-meta {
  font-size: 0.76rem;
  color: var(--ink-faint);
}

.order-summary-price {
  font-weight: 700;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  color: var(--gold);
  flex-shrink: 0;
}

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

.field label {
  font-size: 0.76rem;
  color: var(--ink-soft);
  font-weight: 500;
}

.field input,
.field textarea {
  font-family: var(--font-body);
  font-size: 0.92rem;
  color: var(--ink);
  background: var(--paper);
  border: 1.5px solid var(--line-strong);
  border-radius: 14px;
  padding: 11px 13px;
  outline: none;
  transition: border-color 0.15s ease;
  resize: none;
}

.field input:focus,
.field textarea:focus { border-color: var(--accent); }

.field textarea { min-height: 72px; font-family: var(--font-body); }

.field.has-error input,
.field.has-error textarea { border-color: var(--hue-coral); }

.field-error {
  font-size: 0.78rem;
  color: var(--hue-coral);
}

.form-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---------- состояние "спасибо" ---------- */

.success-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 10px;
  padding: 24px;
}

.success-panel .icon-circle {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 6px;
}

.success-panel .icon-circle svg { width: 26px; height: 26px; }

/* в колонке flex: 1 растягивал кнопку на всю высоту панели */
.success-panel .pill-btn { flex: none; padding: 0 28px; margin-top: 8px; }

.success-panel h2 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.1rem;
}

.success-panel p {
  font-size: 0.88rem;
  color: var(--ink-soft);
  line-height: 1.5;
  max-width: 26ch;
}

/* ---------- панель текущей картины (главная, только десктоп) ---------- */

.painting-info { display: none; }

.painting-info-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: -0.01em;
}

/* ---------- десктоп ---------- */

@media (min-width: 960px) {
  .app {
    max-width: 1240px;
    padding: 28px 40px 40px;
    gap: 24px 40px;
  }

  .wordmark { font-size: 1.3rem; }
  .work-count { font-size: 0.8rem; }

  /* главная: сцена слева, колонка с фильтрами и описанием справа */
  .app--home {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    grid-template-rows: auto auto auto auto auto 1fr;
    grid-template-areas:
      "header  header"
      "stage   filters"
      "stage   info"
      "stage   nav"
      "stage   philo"
      "stage   .";
    align-items: start;
  }

  .app--home .header-bar { grid-area: header; }
  .app--home .filters-row { grid-area: filters; flex-direction: column; }
  .app--home .painting-info { grid-area: info; }
  .app--home .nav-row { grid-area: nav; }
  .app--home .philosophy { grid-area: philo; }

  .app--home .stage-wrap,
  .app--home .empty-state {
    grid-area: stage;
    align-self: center;
  }

  /* сцена квадратная и целиком влезает по высоте окна */
  .app--home .stage-wrap {
    justify-self: center;
    width: min(100%, max(380px, calc(100dvh - 190px)));
  }

  .app--home .empty-state { min-height: 60dvh; }
  .app--home .empty-state p { max-width: 32ch; }

  .painting-info {
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--paper-soft);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 20px;
  }

  .painting-info .pill-btn { flex: 0 0 auto; height: 44px; padding: 0 22px; }

  /* карточка картины: фото слева, описание справа */
  .app--detail {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    grid-template-rows: auto 1fr;
    align-items: start;
  }

  .app--detail .header-bar { grid-column: 1 / -1; }

  .app--detail .detail-image {
    justify-self: center;
    width: min(100%, calc(100dvh - 150px));
  }

  .app--detail .detail-image.has-photo { width: 100%; }

  .app--detail .detail-image.has-photo img { max-height: calc(100dvh - 150px); }

  .app--detail .detail-card {
    flex: none;
    overflow: visible;
    padding: 24px;
    gap: 16px;
  }

  .app--detail .detail-title { font-size: 1.6rem; }
  .app--detail .detail-desc { font-size: 0.95rem; }

  /* заказ и «спасибо» — узкая колонка по центру */
  .app--narrow { max-width: 560px; }

  .app--narrow .order-card { flex: none; overflow: visible; padding: 24px; }
}
