:root {
  --bg: #0b0d12;
  --card: #151924;
  --line: #272d3d;
  --text: #eef0f6;
  --muted: #949bb0;
  --accent: #ff4fa3;
  --accent-2: #8b6cff;
  --ok: #37d69a;
  --bad: #ff6b6b;
  --warn: #ffc24b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app { max-width: 640px; margin: 0 auto; }
h1 { font-size: 1.25rem; margin: 0; letter-spacing: .04em; }
h1 span { color: var(--accent); }
h2 { font-size: 1.1rem; margin: 0; }
h3 { font-size: .85rem; font-weight: 600; color: var(--muted); margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.boot { text-align: center; color: var(--muted); padding: 40vh 16px 0; }

button, input, select, textarea { font: inherit; color: inherit; }
button, label.primary, label.secondary { cursor: pointer; }

input:not([type="range"]), select, textarea {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
textarea { resize: vertical; min-height: 120px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
input[type="range"] { width: 100%; height: 36px; accent-color: var(--accent); }

.primary, .secondary {
  display: block;
  width: 100%;
  text-align: center;
  text-decoration: none;
  border-radius: 14px;
  padding: 14px;
  font-weight: 700;
}
.primary { background: linear-gradient(100deg, var(--accent), var(--accent-2)); border: 0; color: #fff; }
.primary:disabled { background: var(--line); color: var(--muted); cursor: default; }
.primary.armed { background: var(--warn); color: #1b1300; }
.secondary { background: var(--card); border: 1px solid var(--line); color: var(--text); padding: 11px; }
.link { background: none; border: 0; color: var(--accent-2); padding: 8px 4px; font-weight: 600; }
.danger { color: var(--bad); }

.auth { display: flex; flex-direction: column; gap: 14px; padding: 12vh 22px 40px; max-width: 420px; margin: 0 auto; }
.auth h1 { font-size: 2rem; text-align: center; }
.auth p { text-align: center; margin: 0; }
.auth label { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
.auth input { color: var(--text); font-size: 1rem; }

header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(11, 13, 18, .94);
  border-bottom: 1px solid var(--line);
}
header h1 { margin-right: auto; }
.pill { background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px; font-size: .85rem; font-variant-numeric: tabular-nums; }

main { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
.panel { display: flex; flex-direction: column; gap: 18px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: 9px 15px; font-size: .9rem; }
.chip.on { border-color: var(--accent); background: rgba(255, 79, 163, .16); font-weight: 700; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 10px; }
.grid > p { grid-column: 1 / -1; }
.thumb {
  position: relative;
  display: block;
  aspect-ratio: 1;
  width: 100%;
  padding: 0;
  overflow: hidden;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: 12px;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.on { border-color: var(--accent); }
.thumb.add { font-size: 2rem; color: var(--muted); border-style: dashed; }
.thumb b { position: absolute; left: 5px; top: 5px; min-width: 22px; height: 22px; border-radius: 99px; background: var(--accent); color: #fff; font-size: .75rem; display: grid; place-items: center; }
.thumb .remove { position: absolute; right: 3px; top: 3px; width: 28px; height: 28px; border: 0; border-radius: 99px; background: rgba(0, 0, 0, .7); color: #fff; line-height: 1; }
figure { margin: 0; min-width: 0; text-align: center; }
figcaption { font-size: .72rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 4px; }

.generate { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 4; }
.generate button { box-shadow: 0 8px 24px rgba(0, 0, 0, .55); }

nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  justify-content: center;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav button { flex: 1; max-width: 160px; background: none; border: 0; padding: 9px 0 8px; font-size: .72rem; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav button span { font-size: 1.25rem; filter: grayscale(1); opacity: .7; }
nav button.on { color: var(--text); font-weight: 700; }
nav button.on span { filter: none; opacity: 1; }

article { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
article p { margin: 6px 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.badge { font-size: .75rem; font-weight: 700; border-radius: 99px; padding: 3px 10px; border: 1px solid currentColor; }
.badge.ok { color: var(--ok); }
.badge.bad { color: var(--bad); }
.badge.wait { color: var(--warn); }
.media { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.media video, .media img { width: 100%; max-height: 70vh; object-fit: contain; border-radius: 12px; background: #000; display: block; }
.prompt { font-size: .85rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.error-text { color: var(--bad); font-size: .85rem; overflow-wrap: anywhere; }
.actions { display: flex; justify-content: space-between; }
.progress { height: 5px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 10px 0; }
.progress i { display: block; width: 35%; height: 100%; background: var(--warn); animation: slide 1.4s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(290%); } }
@media (prefers-reduced-motion: reduce) { .progress i { animation: none; width: 100%; opacity: .6; } }

.overlay { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .65); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: 85vh; overflow-y: auto; background: var(--bg); border-radius: 20px 20px 0 0; border-top: 1px solid var(--line); padding: 14px 16px calc(24px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }

#toast { position: fixed; left: 16px; right: 16px; top: calc(66px + env(safe-area-inset-top)); z-index: 20; max-width: 608px; margin: 0 auto; background: #232a3b; border: 1px solid var(--accent-2); border-radius: 12px; padding: 12px 14px; font-size: .9rem; box-shadow: 0 8px 24px rgba(0, 0, 0, .5); overflow-wrap: anywhere; }
#toast.error { border-color: var(--bad); }
