@font-face {
  font-family: "Anton";
  src: url("/fonts/anton.woff2") format("woff2");
  font-display: swap;
}

:root {
  --bg: #0c0c10;
  --surface: #15151c;
  --surface-2: #1d1d26;
  --surface-3: #262631;
  --line: #2a2a35;
  --text: #ececf1;
  --muted: #8d8d9c;
  --accent: #ff7a1a;
  --gradient: linear-gradient(135deg, #ffb21f, #ff7a1a 45%, #ff4d6d);
  --focus: #7aa2ff;
  --radius: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text); text-decoration-color: var(--muted); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--accent); }
h2 { font-size: 13px; font-weight: 600; margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }

button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Header ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px;
}
.brand { display: flex; align-items: center; gap: 9px; text-decoration: none; }
.brand span { font-size: 21px; font-weight: 800; letter-spacing: -.04em; }
.perks { display: flex; gap: 6px; list-style: none; margin: 0; padding: 0; }
.perks li { font-size: 12px; color: var(--muted); padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-areas: "editor panel" "templates templates";
  gap: 20px;
  max-width: 1240px;
  margin: 0 auto;
  padding: 0 16px 16px;
}
.editor { grid-area: editor; min-width: 0; }
.panel { grid-area: panel; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.templates { grid-area: templates; }

/* ---------- Stage ---------- */

.stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 360px;
  background:
    radial-gradient(circle at 1px 1px, rgba(255,255,255,.06) 1px, transparent 0) 0 0 / 18px 18px,
    var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  overflow: hidden;
}
#stage {
  display: block;
  max-width: 100%;
  max-height: 72vh;
  border-radius: 6px;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Sits exactly over the text box on the canvas while typing. */
.inline-editor {
  position: absolute;
  margin: 0;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  resize: none;
  overflow: hidden;
  text-align: center;
  line-height: 1.12;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  transform-origin: 0 0;
  caret-color: var(--accent);
  paint-order: stroke fill;
  -webkit-text-stroke-width: 0;
}
.inline-editor[hidden] { display: none; }

.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.empty[hidden] { display: none; }
.drop-hint {
  position: absolute;
  inset: 10px;
  display: none;
  place-items: center;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: rgba(12,12,16,.85);
  font-weight: 700;
  font-size: 18px;
}
.stage.over .drop-hint { display: grid; }

.choice {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  background: rgba(21,21,28,.96);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
  white-space: nowrap;
}
.choice[hidden] { display: none; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 9px 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--gradient); color: #fff; font-size: 15px; padding: 12px 18px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.subtle { background: var(--surface-2); border-color: var(--line); }
.btn.subtle:hover { background: var(--surface-3); }
.btn.accent { background: var(--accent); color: #fff; }
.btn[hidden] { display: none; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: none;
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.on { color: var(--accent); background: rgba(255,122,26,.12); }
.icon-btn svg { width: 17px; height: 17px; }

/* ---------- Panel ---------- */

.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 4px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.tool:hover { background: var(--surface-2); }
.tool.on { border-color: var(--accent); color: var(--accent); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.caption-field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.caption-field[hidden] { display: none; }
.caption-field textarea {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 16px;
  resize: vertical;
}

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 1px; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 180px;
  padding: 5px 10px 5px 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
.chip.on { border-color: var(--accent); background: rgba(255,122,26,.1); }
.chip b { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface-3); font-size: 11px; flex: 0 0 auto; }
.chip canvas { width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .ph { color: var(--muted); }

.props {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.props.idle { color: var(--muted); font-size: 13px; }
.props-row { display: flex; align-items: center; gap: 8px; }
.props-row .spacer { flex: 1; }
.props-row canvas { width: 34px; height: 34px; border-radius: 10px; }
.props label { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); }
.props label span { width: 52px; flex: 0 0 auto; }
.props input[type="range"] { flex: 1; min-width: 60px; accent-color: var(--accent); }
.props select {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  font-size: 13px;
}
.swatch {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: none;
  cursor: pointer;
  flex: 0 0 auto;
}
.swatch::-webkit-color-swatch-wrapper { padding: 4px; }
.swatch::-webkit-color-swatch { border: 0; border-radius: 6px; }
.swatch::-moz-color-swatch { border: 0; border-radius: 6px; }

.actions { display: flex; gap: 8px; }
.actions .primary { flex: 1; }
.muted { color: var(--muted); font-size: 12px; margin: 0; }

/* ---------- Templates ---------- */

.templates {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.templates-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.templates input[type="search"] {
  flex: 1;
  max-width: 320px;
  min-width: 0;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
}
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(124px, 1fr)); gap: 12px; }
.tpl {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
  cursor: pointer;
}
.tpl img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 12px;
  background: var(--surface-2);
  border: 2px solid transparent;
  transition: border-color .15s, transform .15s;
}
.tpl:hover img { transform: translateY(-2px); }
.tpl:hover, .tpl.active { color: var(--text); }
.tpl.active img { border-color: var(--accent); }
.tpl span { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; padding: 0 2px; }
.more { display: flex; width: 100%; margin-top: 14px; }

/* ---------- Footer & toast ---------- */

.foot { max-width: 1240px; margin: 0 auto; padding: 8px 16px 32px; color: var(--muted); font-size: 12px; }
.foot p { margin: 4px 0; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 16px;
  border-radius: 999px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 20;
  white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Phones ---------- */

@media (max-width: 900px) {
  .top { padding: 12px 14px; }
  .perks { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "editor" "panel" "templates"; gap: 12px; padding: 0 12px 12px; }
  .stage { min-height: 220px; padding: 10px; border-radius: 14px; }
  #stage { max-height: 58vh; }
  .tool { padding: 10px 4px 8px; }

  /* Download stays in reach at the bottom of the screen. */
  .actions {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
    background: rgba(12,12,16,.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
  }
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
  body.typing .actions { display: none; }
  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }

  .templates { padding: 12px; }
  .grid { grid-template-columns: repeat(3, 1fr); gap: 10px; }
  .choice { left: 10px; right: 10px; transform: none; flex-wrap: wrap; border-radius: 14px; white-space: normal; }
}
