:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1b1b1b);
  --hint: var(--tg-theme-hint-color, #6b6b6b);
  --line: color-mix(in srgb, var(--text) 18%, transparent);
  --button: var(--tg-theme-button-color, #1b1b1b);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  color-scheme: light dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}

[hidden] { display: none !important; }

#form { display: flex; flex-direction: column; gap: 20px; }

h2 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 400;
  color: var(--hint);
}

.hint { margin: 6px 0 0; font-size: 13px; color: var(--hint); }
.error { margin: 0; font-size: 15px; color: #d0021b; }

#sheet { margin: 0; line-height: 0; }
#plate { width: 100%; height: auto; border: 1px solid var(--line); }

dl { margin: 0; }
dt { font-size: 13px; color: var(--hint); }
dd { margin: 0 0 10px; }

textarea {
  display: block;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 17px;
  resize: vertical;
}

textarea:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--button);
  outline-offset: 1px;
}

button { font: inherit; color: inherit; cursor: pointer; }

.segments { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); }

.segments button {
  min-height: 44px;
  border: 0;
  border-left: 1px solid var(--line);
  background: transparent;
}

.segments button:first-child { border-left: 0; }
.segments [aria-checked="true"] { background: var(--text); color: var(--bg); }
.segments button:disabled { opacity: .5; cursor: default; }

#buy p { margin: 0 0 8px; }
#buy .hint { margin: 6px 0 0; }

.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }

.thumb {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.thumb img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border: 1px solid var(--line);
}

.thumb span {
  display: -webkit-box;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.3;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.more {
  width: 100%;
  min-height: 44px;
  margin-top: 12px;
  border: 1px solid var(--line);
  background: transparent;
}

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

.palettes button {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: stretch;
  min-height: 44px;
  padding: 0 0 6px;
  border: 0;
  background: transparent;
  font-size: 12px;
  line-height: 1.2;
  text-align: left;
}

.swatch {
  display: block;
  position: relative;
  height: 48px;
  border: 1px solid var(--line);
  overflow: hidden;
}

.swatch i { position: absolute; display: block; border-radius: 50%; }
.swatch .main { left: 8px; top: 8px; width: 30px; height: 30px; }
.swatch .accent { right: 6px; bottom: 6px; width: 18px; height: 18px; }
.palettes [aria-checked="true"] .swatch { outline: 2px solid var(--text); outline-offset: 1px; }

.custom { display: flex; align-items: center; gap: 10px; margin-top: 12px; min-height: 44px; }
.custom input { width: 44px; height: 44px; padding: 0; border: 1px solid var(--line); background: none; }
.custom .hint { margin: 0; }

.primary {
  width: 100%;
  min-height: 50px;
  border: 0;
  background: var(--button);
  color: var(--button-text);
  font-weight: 500;
}

.primary:disabled { opacity: .5; cursor: default; }

#stages { margin: 0; padding: 0; list-style: none; }

#stages li {
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  color: var(--hint);
}

#stages li.past { color: var(--text); }
#stages li.past::after { content: " · готово"; color: var(--hint); }
#stages li.now { color: var(--text); font-weight: 500; }
