
:root {
  --bg: #0a0a0b;
  --bg-2: #111114;
  --card: #17171b;
  --line: rgba(255,255,255,.08);
  --text: #f3efe6;
  --muted: #9a958b;
  --gold: #e8d5b5;
  --gold-2: #c4a982;
  --danger: #e88a8a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --dock-h: 0px;
  --kb: 0px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
html { height: 100%; }
body {
  font-family: "SF Pro HK", "SF Pro Text", "PingFang HK", "Noto Sans HK", "Noto Sans CJK HK", "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button, input, textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
}
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
textarea, input[type="text"] { font-size: 16px; } /* prevent iOS zoom */

#app {
  min-height: 100dvh;
  padding-top: calc(12px + var(--safe-top));
  padding-bottom: calc(var(--dock-h) + var(--kb) + 12px);
}

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 16px 12px;
  background: linear-gradient(to bottom, var(--bg) 70%, transparent);
}

.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 36px; height: 36px; border-radius: 10px; }
.brand-text h1 { margin: 0; font-size: 20px; letter-spacing: 0.04em; font-weight: 650; }
.tag { margin: 0; color: var(--muted); font-size: 12px; }

.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  width: max-content;
  max-width: 100%;
}
.tab {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 14px;
}
.tab.is-active { background: #2a2a30; color: var(--text); }

.install-banner {
  margin: 0 16px 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #1c1c22;
  border: 1px solid var(--line);
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}
.install-banner p { margin: 0; font-size: 13px; color: var(--muted); }
.text-btn { color: var(--gold); font-size: 13px; white-space: nowrap; min-height: 44px; }

.stage { padding: 4px 16px 24px; }
.view { animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.lead, .footnote, .muted, .hint { color: var(--muted); line-height: 1.55; }
.lead { margin: 0 0 18px; font-size: 15px; }
.footnote { margin: 28px 0 8px; font-size: 12px; }
.section-title { margin: 0 0 12px; font-size: 15px; font-weight: 620; letter-spacing: .02em; }
.view-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

.templates {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
@media (min-width: 720px) {
  .templates { grid-template-columns: repeat(3, 1fr); }
  .wall { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}
.tmpl {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  min-height: 120px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid var(--line);
  text-align: left;
  overflow: hidden;
  min-height: 132px;
}
.tmpl::before {
  content: "";
  position: absolute; inset: 0;
  background: var(--grad, linear-gradient(160deg, #2a2420, #121214 70%));
  opacity: .95;
}
.tmpl > * { position: relative; }
.tmpl h3 { margin: 0 0 4px; font-size: 15px; font-weight: 620; }
.tmpl p { margin: 0; font-size: 12px; color: #d8d2c6; }

.wall {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  background: #1a1a1e;
  padding: 0;
}
.tile img, .tile .ph {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.tile.is-wide { grid-column: span 2; aspect-ratio: 16/9; }
.tile.is-tall { aspect-ratio: 3/4; }
.tile.is-busy .ph {
  background: linear-gradient(110deg, #1a1a1e 30%, #2a2a32 50%, #1a1a1e 70%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.tile-err { color: var(--muted); font-size: 12px; padding: 12px; }

.empty {
  padding: 28px 8px;
  color: var(--muted);
  text-align: center;
}

.model-card, .model-item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  margin-bottom: 12px;
}
.model-card.is-locked { border-color: rgba(232, 213, 181, .45); }
.model-card h3, .model-item h3 { margin: 0 0 6px; font-size: 16px; }
.lock-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(232, 213, 181, .15);
  color: var(--gold);
  font-size: 11px;
  vertical-align: middle;
}
.photo-grid, .thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.photo-grid img, .thumbs img, .photo-cell img {
  width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; display: block;
}
.photo-cell { position: relative; padding: 0; }
.photo-cell .kind, .photo-cell .rm {
  position: absolute; left: 6px; bottom: 6px;
  font-size: 10px; padding: 2px 6px; border-radius: 999px;
  background: rgba(0,0,0,.6);
}
.photo-cell .rm { left: auto; right: 6px; bottom: auto; top: 6px; min-height: 24px; }

.composer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  padding: 8px 12px calc(10px + var(--safe-bottom));
  background: linear-gradient(to top, var(--bg) 55%, transparent);
  transform: translateY(calc(-1 * var(--kb)));
}
.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: #1b1b20;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 6px;
  box-shadow: 0 10px 40px rgba(0,0,0,.45);
}
#prompt {
  flex: 1;
  resize: none;
  border: 0;
  outline: none;
  max-height: 120px;
  line-height: 1.4;
  padding: 8px 4px;
  background: transparent;
}
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border-radius: 50%;
  color: var(--text);
}
.icon-btn.send {
  background: var(--gold);
  color: #1a140c;
}
.icon-btn.send:disabled { opacity: .45; }

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.seg {
  display: flex;
  background: #1b1b20;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px;
  flex: none;
}
.seg-btn, .chip, .btn {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
  flex: none;
}
.seg-btn.is-on, .chip.is-on { background: #2d2d34; color: var(--text); }
.chip {
  background: #1b1b20;
  border: 1px solid var(--line);
  color: var(--text);
}

.lock-bar, .attach-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0 4px 8px;
  overflow-x: auto;
}
.lock-pill, .attach-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  background: #1b1b20;
  border: 1px solid rgba(232, 213, 181, .35);
  border-radius: 999px;
  font-size: 13px;
  color: var(--gold);
  flex: none;
}
.lock-pill img, .attach-pill img {
  width: 28px; height: 28px; border-radius: 50%; object-fit: cover;
}
.lock-pill .go, .attach-pill button { color: var(--muted); min-height: 32px; padding: 0 4px; }

.btn {
  background: #23232a;
  border: 1px solid var(--line);
  color: var(--text);
}
.btn.primary { background: var(--gold); color: #1a140c; border-color: transparent; font-weight: 620; }
.btn.ghost { background: transparent; }
.btn.danger-ghost { color: var(--danger); background: transparent; }
.btn-row, .sheet-actions, .detail-actions {
  display: flex; flex-wrap: wrap; gap: 8px;
}

.sheet {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px 12px calc(12px + var(--safe-bottom));
}
.sheet-card {
  width: min(560px, 100%);
  background: #16161a;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 16px;
  max-height: min(86dvh, 760px);
  overflow: auto;
}
.sheet-card.tall { max-height: 90dvh; }
.sheet-title { margin: 0 0 12px; font-size: 16px; font-weight: 650; }
.aspect-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.aspect-opt {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 6px;
  border-radius: 12px;
  border: 1px solid var(--line);
  color: var(--muted);
  min-height: 64px;
}
.aspect-opt.is-on { border-color: var(--gold); color: var(--text); }
.aspect-shape {
  border: 1.5px solid currentColor;
  border-radius: 2px;
}

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.field input, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  background: #101014;
  border: 1px solid var(--line);
  color: var(--text);
  outline: none;
}
.kind-row { display: flex; gap: 6px; margin-bottom: 10px; }
.hint { font-size: 13px; margin: 0 0 10px; }

.detail {
  position: fixed; inset: 0; z-index: 40;
  background: #000;
  display: flex; flex-direction: column;
  padding: calc(8px + var(--safe-top)) 0 calc(12px + var(--safe-bottom));
}
.detail img {
  flex: 1;
  width: 100%;
  object-fit: contain;
  background: #000;
  min-height: 0;
}
.close-detail {
  position: absolute; top: calc(8px + var(--safe-top)); left: 8px;
  z-index: 2;
  background: rgba(0,0,0,.45);
  font-size: 24px;
}
.detail-meta { padding: 12px 16px 0; }
.detail-prompt { margin: 0 0 10px; color: var(--muted); font-size: 14px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + var(--kb) + 12px);
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(92vw, 420px);
  background: #2a2a30;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  box-shadow: 0 8px 30px rgba(0,0,0,.4);
}

.hidden, [hidden] { display: none !important; }

@media (min-width: 900px) {
  .top { flex-direction: row; align-items: center; justify-content: space-between; padding-inline: 28px; }
  .stage { padding-inline: 28px; max-width: 1200px; margin: 0 auto; }
  .composer { left: 50%; right: auto; width: min(720px, calc(100% - 32px)); transform: translate(-50%, calc(-1 * var(--kb))); }
  .toast { left: 50%; }
}
