:root {
  --ground: #171719;
  --surface: #131217;
  --raised: #212023;
  --border: #222224;
  --rule: #1b1a1f;
  --control: #3a3a3e;
  --text: #ffffff;
  --muted: #9a9ca2;
  --accent: #4a8ad6;
  --negative: #e5566f;
  --radius-card: 6px;
  --font: "Golos Text", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --panel-height: clamp(300px, 48dvh, 430px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ground);
  color: var(--text);
  font: 400 14px/20px var(--font);
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  height: var(--tg-viewport-stable-height, 100dvh);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 52px;
  padding: 0 16px;
}
.mark { width: 16px; height: 16px; flex: none; margin-right: 6px; }
h1 { margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; }
.bar-space { flex: 1; }

.ghost {
  min-height: 44px;
  padding: 0 10px;
  color: var(--text);
  transition: opacity 120ms;
}
.ghost:active { opacity: .6; }

.primary {
  height: 36px;
  margin-left: 6px;
  padding: 0 16px;
  border-radius: 999px;
  background: var(--text);
  color: #000;
  font-weight: 600;
  white-space: nowrap;
  transition: transform 120ms, opacity 120ms;
}
.primary:active { transform: scale(.97); }
.primary:disabled { background: var(--raised); color: var(--muted); cursor: default; }

.work { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  overflow: hidden;
  touch-action: manipulation;
}
#view { display: block; }
#view.crisp { image-rendering: pixelated; }

.stage-action {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--control);
  border-radius: 50%;
  background: var(--raised);
  color: var(--text);
  transition: transform 120ms;
}
.stage-action svg { width: 20px; height: 20px; }
.stage-action:active { transform: scale(.94); }
.stage-action[aria-pressed="true"] { background: var(--text); border-color: var(--text); color: #000; }

.stage-note {
  max-width: 300px;
  padding: 16px;
  text-align: center;
  font-size: 16px;
  line-height: 24px;
}
.stage-note p { margin: 0 0 16px; }
.stage-note .error { color: var(--negative); }
.stage-note .actions { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stage-note .primary { margin: 0; height: 40px; }

.panel {
  flex: none;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

.panel.open { height: var(--panel-height); }

.tabs-bar {
  flex: none;
  display: flex;
  min-height: 45px;
  border-bottom: 1px solid var(--border);
}
.tabs {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.collapse {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  color: var(--muted);
}
.collapse svg { width: 20px; height: 20px; }
.collapse:active { color: var(--text); }
.tab {
  position: relative;
  align-self: stretch;
  min-height: 44px;
  color: var(--muted);
  white-space: nowrap;
}
.tab[aria-selected="true"] { color: var(--text); }
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: var(--accent);
}

.panel-body {
  flex: 1;
  min-height: 0;
  padding: 12px 16px 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: settings-in 180ms cubic-bezier(.16, 1, .3, 1);
}
.panel-body > * + * { margin-top: 12px; }

@keyframes settings-in {
  from { opacity: 0; transform: translateY(6px); }
}

.styles {
  position: relative;
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px 16px 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
}
.styles::-webkit-scrollbar { display: none; }
.style {
  position: relative;
  flex: none;
  display: block;
  width: 68px;
  text-align: left;
  color: var(--muted);
  transition: opacity 120ms;
}
.style:active { opacity: .7; }
.thumb {
  position: relative;
  width: 68px;
  height: 68px;
  border-radius: var(--radius-card);
  overflow: hidden;
  background: var(--raised);
}
.thumb img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  animation: thumb-in 200ms ease-out;
}
@keyframes thumb-in {
  from { opacity: 0; }
}
.style[aria-pressed="true"] .thumb {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.style > span:not(.label-ghost) {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  line-height: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.style[aria-pressed="true"] { color: var(--text); }

.skeleton { background: var(--raised); }
.ascii .skeleton { background: transparent; }
.ascii-layer {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.label-ghost {
  display: block;
  width: 48px;
  height: 12px;
  margin: 8px 0 2px;
  border-radius: 2px;
}
.tab-ghost {
  flex: none;
  width: 56px;
  height: 12px;
  border-radius: 2px;
}
.stage-ghost {
  width: min(56vw, 240px);
  aspect-ratio: 2 / 3;
  max-height: 100%;
  border-radius: var(--radius-card);
}

.field-label { display: block; margin-bottom: 2px; color: var(--muted); font-size: 12px; line-height: 16px; }

.choices { display: flex; flex-wrap: wrap; gap: 0 16px; }
.choice {
  position: relative;
  min-height: 36px;
  color: var(--muted);
  white-space: nowrap;
}
.choice[aria-pressed="true"] { color: var(--text); }
.choice[aria-pressed="true"]::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 4px;
  height: 1px;
  background: var(--accent);
}

.slider-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: -6px; }
.slider-track {
  position: relative;
  display: flex;
  align-items: center;
  height: 44px;
  cursor: pointer;
  touch-action: none;
}
.slider-track input[type="range"] { pointer-events: none; }
.slider-track input[type="range"]::-webkit-slider-thumb { transition: transform 120ms; }
.slider-track.dragging input[type="range"]::-webkit-slider-thumb { transform: scale(1.2); }
.slider-track.dragging input[type="range"]::-moz-range-thumb { transform: scale(1.2); }
.slider-value { font: 400 13px/20px var(--mono); font-variant-numeric: tabular-nums; }

input[type="range"] {
  --fill: 0%;
  display: block;
  width: 100%;
  height: 32px;
  margin: 0;
  background: none;
  appearance: none;
  -webkit-appearance: none;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(to right, var(--text) var(--fill), var(--control) var(--fill)); /* taste-skill-ignore: жёсткая граница заполнения ползунка, плавного перехода нет */
}
input[type="range"]::-moz-range-track { height: 2px; background: var(--control); }
input[type="range"]::-moz-range-progress { height: 2px; background: var(--text); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -9px;
  border-radius: 50%;
  background: var(--text);
  border: 0;
}
input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--text);
  border: 0;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 44px;
  text-align: left;
}
.toggle i {
  position: relative;
  flex: none;
  width: 36px;
  height: 20px;
  border: 1px solid var(--control);
  border-radius: 999px;
  transition: border-color 120ms;
}
.toggle i::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 120ms, background 120ms;
}
.toggle[aria-checked="true"] i { border-color: var(--accent); }
.toggle[aria-checked="true"] i::after { transform: translateX(16px); background: var(--text); }

.palettes {
  display: flex;
  gap: 12px;
  margin-left: -16px;
  margin-right: -16px;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.palettes::-webkit-scrollbar { display: none; }
.palette {
  position: relative;
  flex: none;
  width: 72px;
  text-align: left;
  color: var(--muted);
}
.palette .strip { display: flex; height: 32px; overflow: hidden; border-radius: var(--radius-card); }
.palette .strip b { flex: 1; }
.paper-thumb { display: block; width: 100%; height: 100%; object-fit: cover; }
.palette .strip-random {
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--control);
  color: var(--text);
  font: 400 18px/1 var(--mono);
}
.palette span {
  position: relative;
  display: inline-block;
  margin-top: 4px;
  padding-bottom: 3px;
  font-size: 12px;
  line-height: 16px;
  white-space: nowrap;
}
.palette[aria-pressed="true"] { color: var(--text); }
.palette[aria-pressed="true"] span::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: var(--accent);
}

.save-form { display: flex; gap: 8px; }
.save-form input {
  flex: 1;
  min-width: 0;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--control);
  border-radius: var(--radius-card);
  background: none;
  /* Меньше 16 px iPhone при вводе увеличивает страницу. */
  font-size: 16px;
  user-select: text;
  -webkit-user-select: text;
}
.save-form input::placeholder { color: var(--muted); }
.save-form .primary { flex: none; height: 40px; margin: 0; }

.saved-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 12px 8px;
}
.saved-card { position: relative; min-width: 0; }
.saved-card .style { width: 100%; }
.saved-card .thumb { width: 100%; height: auto; aspect-ratio: 1; }
.card-delete {
  position: absolute;
  top: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  width: 36px;
  height: 36px;
  padding: 4px;
}
.card-delete svg {
  width: 18px;
  height: 18px;
  padding: 3px;
  border-radius: 50%;
  background: rgba(0, 0, 0, .65);
  color: var(--text);
}
.card-delete.armed {
  left: 0;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: var(--radius-card);
  background: rgba(0, 0, 0, .78);
  color: #ff8da1;
  font-size: 12px;
}
.card-delete.armed svg { display: none; }

.quiet-action {
  min-height: 36px;
  color: var(--muted);
  font-size: 13px;
}
.quiet-action.armed { color: #ff8da1; }

.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch {
  position: relative;
  display: block;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-card);
  border: 1px solid var(--control);
  overflow: hidden;
  cursor: pointer;
}
.swatch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}
.swatch-action {
  width: 44px;
  height: 44px;
  border: 1px dashed var(--control);
  border-radius: var(--radius-card);
  font: 400 18px/1 var(--mono);
}
.swatch-action:disabled { color: var(--muted); opacity: .5; cursor: default; }

.hint { margin: 0; color: var(--muted); font-size: 13px; line-height: 18px; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  top: 60px;
  z-index: 2;
  padding: 10px 14px;
  border-radius: var(--radius-card);
  background: var(--raised);
  box-shadow: 0 12px 28px rgba(0, 0, 0, .35);
}
.toast.error { color: #ff8da1; }

@media (min-width: 860px) {
  .work { flex-direction: row; }
  .panel, .panel.open { width: 380px; height: auto; border-left: 1px solid var(--border); }
  .toast { left: auto; width: 340px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .panel-body, .thumb img { animation: none; }
}
