/* ImageCreator - dark theme
   Mobile-first. Safe-area aware so the composer clears the iPhone home bar. */

:root {
  --bg:        #1a1a1c;
  --bg-2:      #232326;
  --bg-3:      #2c2c30;
  --line:      #3a3a3f;
  --text:      #e6e6e8;
  --text-dim:  #9a9aa2;
  --text-faint:#6e6e76;
  --accent:    #4a9eff;
  --accent-dim:#2f6fbd;
  --danger:    #ff6b5e;
  --ok:        #4ec9b0;
  --radius:    10px;
  --shadow:    0 8px 28px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

/* The [hidden] attribute only implies display:none at low priority, so any
   rule setting display (flex on .setup/.modal/#app) silently overrides it.
   This makes hidden actually hide. Without it every panel renders at once. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

/* ------------------------------- shell ------------------------------- */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  letter-spacing: .2px;
  white-space: nowrap;
}

.logo {
  width: 22px; height: 22px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.7;
  stroke-linejoin: round;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  min-width: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.topbar-controls select {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 8px;
  text-overflow: ellipsis;
}

/* Model names run long ("Google: Nano Banana Pro (Gemini 3 Pro Image)"), so
   give this one room. The open dropdown list sizes to its content in every
   current browser; this width governs the closed control. */
#modelPick {
  min-width: 250px;
  max-width: 420px;
  flex: 1 1 auto;
}

#aspectPick { flex: 0 0 auto; }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 6px 9px;
  font-size: 16px;
  line-height: 1;
  color: var(--text-dim);
}
.icon-btn:hover { background: var(--bg-3); color: var(--text); }

/* ------------------------------ thread ------------------------------- */

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 18px 14px 8px;
  -webkit-overflow-scrolling: touch;
}

.turn { margin-bottom: 22px; }

.turn-user {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.bubble {
  background: var(--accent-dim);
  padding: 9px 13px;
  border-radius: 14px 14px 3px 14px;
  max-width: min(560px, 82%);
  white-space: pre-wrap;
  word-break: break-word;
}

.turn-note {
  font-size: 12px;
  color: var(--text-faint);
  text-align: right;
  margin-bottom: 8px;
}

.turn-image { position: relative; max-width: 560px; }

.turn-image img {
  width: 100%;
  display: block;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  cursor: zoom-in;
  background: var(--bg-2);
}

.rev-tag {
  position: absolute;
  top: 8px; left: 8px;
  background: rgba(0,0,0,.62);
  border-radius: 5px;
  padding: 2px 7px;
  font-size: 11px;
  color: #fff;
  backdrop-filter: blur(3px);
}

.turn-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 8px;
  max-width: 560px;
}

.act-btn {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 11px;
  font-size: 13px;
  color: var(--text-dim);
}
.act-btn:hover { background: #35353a; color: var(--text); }
.act-btn.is-head { border-color: var(--accent); color: var(--accent); }

/* pending + error states */
.turn-pending {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  padding: 14px 0;
  flex-wrap: wrap;
}

.turn-pending .spinner {
  border-color: rgba(255,255,255,.18);
  border-top-color: var(--accent);
}

.pending-clock {
  font-variant-numeric: tabular-nums;
  color: var(--text-faint);
  font-size: 13px;
  min-width: 34px;
}

.turn-error {
  background: #35211f;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 11px 13px;
  color: #ffb4ad;
  max-width: 560px;
  font-size: 14px;
}

/* ---------------------------- empty state ---------------------------- */

.empty {
  text-align: center;
  padding: 46px 20px;
  color: var(--text-dim);
}
.empty-icon {
  width: 52px; height: 52px;
  fill: none; stroke: var(--line); stroke-width: 1.4; stroke-linejoin: round;
  margin-bottom: 14px;
}
.empty h2 { margin: 0 0 8px; font-size: 19px; color: var(--text); font-weight: 600; }
.empty p { margin: 0 auto 20px; max-width: 380px; font-size: 14px; }

.examples { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text-dim);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ----------------------------- composer ------------------------------ */

.composer {
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  padding: 10px 14px;
  flex-shrink: 0;
}

/* Attribution bar. The composer used to carry the bottom safe-area inset;
   now that this sits below it, the inset belongs here instead, or the
   iPhone home bar would leave a gap in the middle of the shell. */
.brandbar {
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  padding: 7px 14px;
  padding-bottom: calc(7px + env(safe-area-inset-bottom));
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.5;
}

.brandbar a {
  color: var(--text-dim);
  text-decoration: none;
  border-bottom: 1px dotted var(--line);
}

.brandbar a:hover { color: var(--accent); border-bottom-color: var(--accent); }

.brandbar-sep { color: var(--line); }

/* Narrow phones: drop the middle separator so it wraps to two clean lines. */
@media (max-width: 380px) {
  .brandbar { gap: 3px 8px; }
  .brandbar > .brandbar-sep { display: none; }
}

.attach-strip { display: flex; gap: 8px; margin-bottom: 9px; flex-wrap: wrap; }

.attach-thumb { position: relative; width: 54px; height: 54px; }
.attach-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--line);
}
.attach-x {
  position: absolute; top: -6px; right: -6px;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff; border: 0;
  font-size: 12px; line-height: 19px;
  padding: 0; text-align: center;
}

.composer-row { display: flex; align-items: flex-end; gap: 8px; }

#promptBox {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  resize: none;
  max-height: 156px;
  overflow-y: auto;
  line-height: 1.45;
}
#promptBox:focus { outline: none; border-color: var(--accent); }

.send-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  padding: 10px 18px;
  font-weight: 600;
  min-width: 78px;
  display: flex; align-items: center; justify-content: center;
}
.send-btn:disabled { background: var(--bg-3); color: var(--text-faint); }

.spinner {
  width: 15px; height: 15px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.composer-meta {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-faint);
}
.spacer { flex: 1; }

.meta-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--text-dim);
}
.meta-btn:disabled { opacity: .38; cursor: not-allowed; }
.meta-btn:not(:disabled):hover { border-color: var(--accent); color: var(--accent); }

.meta-tag { color: var(--text-faint); }
.meta-tag.cost { font-variant-numeric: tabular-nums; }

/* ------------------------------ setup -------------------------------- */

.setup {
  position: fixed; inset: 0;
  overflow-y: auto;
  background: var(--bg);
  padding: 26px 16px;
  display: flex; justify-content: center; align-items: flex-start;
}

.setup-card {
  width: 100%; max-width: 520px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 26px;
}
.setup-card h1 { margin: 0 0 6px; font-size: 22px; }
.lede { color: var(--text-dim); margin: 0 0 20px; }

.why {
  background: var(--bg-3);
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  padding: 12px 14px;
  margin-bottom: 20px;
}
.why strong { display: block; margin-bottom: 5px; font-size: 14px; }
.why p { margin: 0; font-size: 13.5px; color: var(--text-dim); }

.steps { margin: 0 0 20px; padding-left: 20px; }
.steps li { margin-bottom: 11px; }
.steps span { margin-right: 7px; }

.field { display: block; margin-bottom: 13px; }
.field span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}
.field input:focus { outline: none; border-color: var(--accent); }

.primary-btn {
  background: var(--accent); color: #fff;
  border: 0; border-radius: 8px;
  padding: 11px 20px; font-weight: 600;
}
.primary-btn:disabled { background: var(--bg-3); color: var(--text-faint); }
.primary-btn.full { width: 100%; margin-bottom: 14px; }

.secondary-btn {
  background: var(--bg-3); color: var(--text-dim);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 9px 15px;
}
.secondary-btn:hover { color: var(--text); }

.danger-btn {
  background: transparent; color: var(--danger);
  border: 1px solid var(--danger); border-radius: 8px;
  padding: 9px 15px;
}

.btn-row { display: flex; gap: 9px; flex-wrap: wrap; }

.key-result {
  margin-top: 13px;
  padding: 11px 13px;
  border-radius: 8px;
  font-size: 13.5px;
}
.key-result.ok  { background: #1c3229; border: 1px solid var(--ok);     color: #a8e6d6; }
.key-result.bad { background: #35211f; border: 1px solid var(--danger); color: #ffb4ad; }

.fineprint { font-size: 12px; color: var(--text-faint); margin: 16px 0 0; }

/* ------------------------------ modals ------------------------------- */

.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.62);
  display: flex; justify-content: center; align-items: flex-start;
  padding: 26px 16px;
  overflow-y: auto;
  z-index: 40;
}
.modal-card {
  width: 100%; max-width: 480px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.modal-head { display: flex; align-items: center; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 17px; flex: 1; }

.modal hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

.setting-line { margin-bottom: 11px; }
.setting-line strong { font-size: 14px; }
.hint { margin: 4px 0 0; font-size: 12.5px; color: var(--text-faint); }

.thread-list { display: flex; flex-direction: column; gap: 7px; }
.thread-item {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
  width: 100%;
}
.thread-item:hover { border-color: var(--accent); }
.thread-item.active { border-color: var(--accent); }
.thread-item img {
  width: 38px; height: 38px; object-fit: cover;
  border-radius: 5px; flex-shrink: 0; background: var(--bg);
}
.ti-body { flex: 1; min-width: 0; }
.ti-title {
  font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ti-meta { font-size: 11.5px; color: var(--text-faint); }
.ti-del { background: transparent; border: 0; color: var(--text-faint); padding: 4px 6px; }
.ti-del:hover { color: var(--danger); }

/* ----------------------------- lightbox ------------------------------ */

.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.93);
  display: flex; align-items: center; justify-content: center;
  z-index: 60;
  padding: 20px;
}
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox-close {
  position: absolute;
  top: calc(14px + env(safe-area-inset-top)); right: 16px;
  background: rgba(255,255,255,.12);
  border: 0; border-radius: 50%;
  width: 38px; height: 38px;
  color: #fff; font-size: 17px;
}

/* ------------------------------ toast -------------------------------- */

.toast {
  position: fixed;
  bottom: calc(84px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--bg-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 17px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  z-index: 80;
  max-width: 90vw;
  text-align: center;
}
.toast.bad { border-color: var(--danger); color: #ffb4ad; }

/* ----------------------------- desktop ------------------------------- */

@media (min-width: 720px) {
  .thread { padding: 24px 28px 10px; }
  .composer { padding: 12px 28px; padding-bottom: 14px; }
  .turn-image, .turn-actions, .turn-error { max-width: 600px; }
}
