/* Uses Telegram's theme colors when opened inside Telegram, with neutral fallbacks in a browser. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg-2: var(--tg-theme-secondary-bg-color, #f2f2f5);
  --text: var(--tg-theme-text-color, #141414);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --radius: 14px;
  color-scheme: light dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column;
  padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.app.in-telegram { padding-bottom: 16px; }

/* --- preview ------------------------------------------------------------ */
.stage { position: sticky; top: 0; z-index: 2; background: var(--bg-2); padding: 12px 0 10px;
  display: flex; justify-content: center; }
.canvas { position: relative; height: min(46vh, 520px); aspect-ratio: 4 / 5; border-radius: 6px;
  overflow: hidden; background: var(--line); box-shadow: 0 6px 24px rgb(0 0 0 / 0.18); }
.canvas { touch-action: none; user-select: none; -webkit-user-select: none; }
.canvas .layer { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#preview { transition: opacity .15s; pointer-events: none; }
.canvas.loading #preview { opacity: .8; }
.loader { position: absolute; top: 10px; right: 10px; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgb(255 255 255 / .5); border-top-color: #fff; animation: spin .7s linear infinite;
  filter: drop-shadow(0 0 2px rgb(0 0 0 / .5)); }
@keyframes spin { to { transform: rotate(360deg); } }
.warning { position: absolute; inset: auto 8px 8px 8px; padding: 10px 12px; border-radius: 10px;
  background: var(--danger); color: #fff; font-size: 13px; font-weight: 600; }

/* --- slide strip --------------------------------------------------------- */
.slides { display: flex; gap: 8px; overflow-x: auto; padding: 10px 14px; scrollbar-width: none;
  border-bottom: 1px solid var(--line); }
.slides::-webkit-scrollbar { display: none; }
.slide-chip { flex: 0 0 auto; width: 64px; height: 80px; border-radius: 8px; border: 2px solid transparent;
  background: var(--bg-2); display: flex; flex-direction: column; justify-content: space-between;
  padding: 6px; text-align: left; font-size: 10px; line-height: 1.2; overflow: hidden; }
.slide-chip b { font-size: 12px; }
.slide-chip span { color: var(--hint); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.slide-chip[aria-current="true"] { border-color: var(--btn); }
.slide-chip.bad { border-color: var(--danger); }
.slide-chip.add { align-items: center; justify-content: center; font-size: 26px; color: var(--link);
  border: 2px dashed var(--line); background: none; }

/* --- tabs + panels ------------------------------------------------------- */
.tabs { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; padding: 10px 14px 0; }
.tabs button { border: 0; background: none; padding: 10px 0; border-radius: 10px; color: var(--hint); font-weight: 600; }
.tabs button[aria-selected="true"] { background: var(--bg-2); color: var(--text); }
.panel { padding: 14px; }
.panel h3 { margin: 4px 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--hint); }
.panel h3 + * { margin-bottom: 18px; }

.field { display: block; margin-bottom: 18px; }
.field-label { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 8px; }
.field-label output { color: var(--hint); font-weight: 500; }
textarea { width: 100%; resize: vertical; min-height: 110px; padding: 12px; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--bg-2); color: var(--text); font: inherit; font-size: 16px; }
textarea:focus { outline: 2px solid var(--btn); outline-offset: -1px; }
.counter { display: block; text-align: right; font-size: 12px; color: var(--hint); margin-top: 4px; }
.counter.over { color: var(--danger); }
input[type="range"] { width: 100%; accent-color: var(--btn); }

.row { display: flex; gap: 8px; align-items: center; }
.spacer { flex: 1; }
.chip { border: 1px solid var(--line); background: var(--bg-2); border-radius: 999px; padding: 7px 12px; font-size: 13px; }
.chip:disabled { opacity: .4; }
.chip.danger { color: var(--danger); }

.styles { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.style-card { border: 2px solid transparent; border-radius: var(--radius); padding: 0; background: none; text-align: center; }
.style-card .sample { aspect-ratio: 4 / 5; border-radius: 10px; display: flex; flex-direction: column;
  justify-content: center; padding: 10px; font-weight: 700; font-size: 20px; text-align: left; box-shadow: inset 0 0 0 1px var(--line); }
.style-card .sample i { display: block; width: 28px; height: 4px; border-radius: 2px; margin-bottom: 8px; }
.style-card small { display: block; padding: 6px 0 2px; font-size: 12px; }
.style-card[aria-pressed="true"] { border-color: var(--btn); }

.swatches { display: flex; gap: 14px; flex-wrap: wrap; }
.swatch { width: 44px; height: 44px; border-radius: 50%; border: 0; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .15);
  outline: 3px solid transparent; outline-offset: 3px; }
.swatch[aria-pressed="true"] { outline-color: var(--btn); }

.toggles { list-style: none; margin: 0; padding: 0; border-radius: var(--radius); background: var(--bg-2); }
.toggles li + li { border-top: 1px solid var(--line); }
.toggles label { display: flex; align-items: center; justify-content: space-between; padding: 13px 14px; cursor: pointer; }
.switch { appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative; transition: background .15s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .3); transition: transform .15s; }
.switch:checked { background: var(--btn); }
.switch:checked::after { transform: translateX(18px); }
.hint { color: var(--hint); font-size: 13px; margin: 12px 2px 0; }
.hint.tip { margin-top: -8px; margin-bottom: 14px; }

.segmented { display: flex; background: var(--bg-2); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.segmented button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 9px 4px; font-size: 14px; color: var(--hint); }
.segmented button[aria-checked="true"] { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgb(0 0 0 / .15); }

/* --- bottom bar (browser only; in Telegram the native MainButton is used) --- */
.actions { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 10px; justify-content: center;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.actions button { border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 600; }
.actions .primary { flex: 1; max-width: 360px; background: var(--btn); color: var(--btn-text); }
.actions .primary:disabled { opacity: .6; }
.actions .ghost { background: var(--bg-2); }
.in-telegram .actions { position: static; border: 0; padding-top: 0; }
.in-telegram .actions .primary { display: none; }

.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgb(20 20 20 / .92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; z-index: 10; }

/* --- formatting toolbar --------------------------------------------------- */
.format-bar { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.fmt { height: 34px; min-width: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg-2); padding: 0 10px; font-size: 14px; }
.fmt.italic { font-style: italic; font-weight: 700; font-family: Georgia, serif; }
.fmt-sep { width: 1px; height: 22px; background: var(--line); }
.fmt-group { display: flex; gap: 6px; flex-wrap: wrap; }
.fmt.color { display: inline-flex; align-items: center; gap: 6px; }
.fmt.color i { width: 14px; height: 14px; border-radius: 50%; display: inline-block; box-shadow: inset 0 0 0 1px rgb(0 0 0 / .15); }

/* --- photo -------------------------------------------------------------- */
.canvas .photo { inset: auto; height: auto; max-width: none; pointer-events: none; -webkit-user-drag: none; }
.canvas.has-photo { cursor: grab; }
.canvas.dragging { cursor: grabbing; }
.guides { position: absolute; pointer-events: none; border: 1px dashed rgb(255 255 255 / .85);
  box-shadow: 0 0 0 1px rgb(0 0 0 / .35); border-radius: 2px; }
.big-add { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 26px 12px;
  border: 2px dashed var(--line); border-radius: var(--radius); background: none; color: var(--link); font-weight: 600; }
.big-add-icon { font-size: 30px; line-height: 1; }
.row.wrap { flex-wrap: wrap; }
.gesture-hint { margin: 0 2px 14px; }
.slide-chip .cam { float: right; font-size: 11px; }

/* --- text box --------------------------------------------------------------- */
.textbox { position: absolute; border: 1.5px dashed rgb(255 255 255 / .9); box-shadow: 0 0 0 1px rgb(0 0 0 / .35);
  cursor: move; touch-action: none; z-index: 3; }
.textbox .handle { position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 4px rgb(0 0 0 / .5); touch-action: none; }
.textbox .handle::after { content: ""; position: absolute; inset: -10px; }  /* bigger touch target */
.textbox [data-h="nw"] { left: -9px; top: -9px; cursor: nwse-resize; }
.textbox [data-h="ne"] { right: -9px; top: -9px; cursor: nesw-resize; }
.textbox [data-h="sw"] { left: -9px; bottom: -9px; cursor: nesw-resize; }
.textbox [data-h="se"] { right: -9px; bottom: -9px; cursor: nwse-resize; }
#gradient-tools { margin-top: 18px; }
#gradient-tools .swatches { margin-bottom: 14px; }
