/*
 * Tool chrome.
 *
 * Deliberately neutral dark grey: the poster is the only saturated thing on
 * screen, so a colour judgement made here is a judgement about the poster and
 * not about the app around it. Same reason photo editors are grey.
 */

:root {
  --bg: #0d0f12;
  --panel: #14171c;
  --panel-2: #1a1e24;
  --line: #262b33;
  --text: #e8ebf0;
  --muted: #8f98a6;
  --accent: #54c8e8;      /* Rain Zhang brand cyan, from the logo artwork */
  --accent-ink: #10102e;
  --danger: #e05252;
  --r: 8px;
  --top-h: 68px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
        'PingFang SC', 'Noto Sans SC', sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ------------------------------------------------------------------ top -- */

.top {
  height: var(--top-h);
  flex: none;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 11px; }
.brand__mark {
  width: 30px; height: 30px; border-radius: 7px;
  background: linear-gradient(140deg, var(--accent), #1e1545);
}
.brand strong { display: block; font-size: 14px; letter-spacing: .01em; }
.brand small { display: block; font-size: 11px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; }

.tabs { display: flex; gap: 6px; margin-left: 8px; }
.tab {
  display: flex; flex-direction: column; align-items: flex-start; gap: 1px;
  padding: 7px 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  transition: background .15s, color .15s, border-color .15s;
}
.tab strong { font-size: 13px; font-weight: 600; }
.tab small { font-size: 10px; opacity: .8; }
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.is-active {
  background: var(--panel-2);
  border-color: var(--accent);
  color: var(--text);
}

.actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.scale { display: flex; align-items: center; gap: 6px; }
.scale > span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; }
.scale select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  padding: 7px 8px; font: inherit; font-size: 12px;
}

button { font: inherit; cursor: pointer; }

.primary, .ghost {
  border-radius: var(--r);
  padding: 9px 15px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  transition: background .15s, border-color .15s, opacity .15s;
}
.ghost:hover { background: #232830; }
.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
}
.primary:hover { filter: brightness(1.07); }
button:disabled { opacity: .5; cursor: progress; }
.ghost.sm { padding: 6px 10px; font-size: 12px; }

/* --------------------------------------------------------------- layout -- */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 392px 1fr;
}

.panel {
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 4px 0 80px;
}
.panel::-webkit-scrollbar { width: 10px; }
.panel::-webkit-scrollbar-thumb { background: #2a3038; border-radius: 6px; border: 3px solid var(--panel); }

/* --------------------------------------------------------------- groups -- */

.grp { border-bottom: 1px solid var(--line); }
.grp[hidden] { display: none; }

.grp__head {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 15px 18px 13px;
  background: none; border: 0;
  color: var(--text);
  font-size: 12px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
}
.chev {
  width: 8px; height: 8px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
  transition: transform .18s;
}
.grp.is-collapsed .chev { transform: rotate(-135deg) translateY(-2px); }
.grp.is-collapsed .grid,
.grp.is-collapsed .grp__note { display: none; }

.grp__note {
  margin: -6px 18px 10px;
  font-size: 11.5px;
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 12px;
  padding: 2px 18px 20px;
}
.span2 { grid-column: 1 / -1; }

.f { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.f__label {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 11px; color: var(--muted);
  letter-spacing: .05em; text-transform: uppercase;
}
.f__count { font-size: 10px; opacity: .7; font-variant-numeric: tabular-nums; }
.f__hint { margin: 1px 0 0; font-size: 11px; color: #6f7887; line-height: 1.4; }

.input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--text);
  padding: 9px 11px;
  font: inherit;
  font-size: 13px;
  transition: border-color .15s, background .15s;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  background: #1e232a;
}
textarea.input { resize: vertical; line-height: 1.5; }
::placeholder { color: #59616e; }

.divider {
  display: flex; align-items: center; gap: 10px;
  margin-top: 4px;
  font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: #6f7887;
}
.divider::after {
  content: ''; flex: 1; height: 1px; background: var(--line);
}

/* ------------------------------------------------------- choice widgets -- */

.seg { display: flex; gap: 0; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.seg__btn {
  flex: 1; padding: 9px 6px;
  background: var(--panel-2); border: 0; color: var(--muted);
  font-size: 12px; font-weight: 550;
  transition: background .15s, color .15s;
}
.seg__btn + .seg__btn { border-left: 1px solid var(--line); }
.seg__btn:hover { color: var(--text); }
.seg__btn.is-active { background: var(--accent); color: var(--accent-ink); }

/* Only two colourways exist, so they get room to be labelled rather than
   crammed into anonymous chips. */
.swatches { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.swatch {
  display: flex; flex-direction: column; gap: 0;
  border: 1.5px solid var(--line); border-radius: var(--r);
  overflow: hidden; padding: 0; background: var(--panel-2);
  transition: border-color .15s, transform .12s;
}
.swatch__strip { display: flex; height: 34px; }
.swatch__strip i { flex: 1; }
.swatch__label {
  padding: 6px 4px; font-size: 11px; color: var(--muted);
  letter-spacing: .04em;
}
.swatch:hover { transform: translateY(-1px); }
.swatch.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(84,200,232,.22); }
.swatch.is-active .swatch__label { color: var(--text); }

/* --------------------------------------------------------------- images -- */

.imgfield { display: flex; flex-direction: column; gap: 7px; }
.imgfield__preview {
  position: relative;
  height: 76px;
  border: 1.5px dashed var(--line);
  border-radius: var(--r);
  background: var(--panel-2);
  display: grid; place-items: center;
  cursor: pointer;
  overflow: hidden;
  transition: border-color .15s;
}
/* Transparency checker behind logo previews: the bundled mark is white, but
   an uploaded dark PNG would vanish against a flat dark tile. */
.imgfield__preview:not([data-empty]) {
  background:
    repeating-conic-gradient(#5a636e 0% 25%, #434b55 0% 50%) 0 0 / 16px 16px;
  border-style: solid;
}
.imgfield__img {
  position: absolute; inset: 7px;
  background: center / contain no-repeat;
}
.imgfield__preview[data-empty] .imgfield__img { display: none; }
.imgfield__preview:hover { border-color: var(--accent); }
.imgfield__preview span { font-size: 11px; color: var(--muted); }
.imgfield__preview:not([data-empty]) span { display: none; }
.imgfield__actions { display: flex; gap: 6px; }
.imgfield.is-drop .imgfield__preview,
.photo.is-drop .photo__thumb { border-color: var(--accent); background-color: #232a33; }

/* Hero spans a 2×2 block; the eight gallery slots flow around it. Row height
   comes from the small cells' aspect-ratio, which gives the hero a definite
   height to fill. */
.photos { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.photo { position: relative; min-width: 0; }
.photo--hero { grid-column: span 2; grid-row: span 2; }

.photo__thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1.5px dashed var(--line);
  border-radius: 6px;
  background: var(--panel-2) center / cover no-repeat;
  display: grid; place-items: center;
  cursor: pointer;
  transition: border-color .15s;
}
.photo--hero .photo__thumb { aspect-ratio: auto; height: 100%; border-radius: var(--r); }
.photo__thumb:hover { border-color: var(--accent); }
.photo__thumb b { font-size: 17px; font-weight: 300; color: #59616e; }
.photo--hero .photo__thumb b { font-size: 26px; }
.photo__thumb:not([data-empty]) b { display: none; }
.photo__thumb:not([data-empty]) { border-style: solid; border-color: #2f3641; }

.photo__cap {
  position: absolute; left: 7px; bottom: 6px;
  padding: 2px 7px; border-radius: 4px;
  background: rgba(13,15,18,.72);
  font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: #cfd5de;
}
.photo__x {
  position: absolute; top: 4px; right: 4px;
  width: 19px; height: 19px; line-height: 1;
  border: 0; border-radius: 50%;
  background: rgba(13,15,18,.82); color: #fff;
  font-size: 14px; display: none; padding: 0;
}
.photo.is-filled .photo__x { display: block; }
.photo__x:hover { background: var(--danger); }

/* ---------------------------------------------------------------- stage -- */

.stage {
  min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px;
  padding: 22px;
  background:
    radial-gradient(1200px 600px at 50% -10%, #171b21 0%, var(--bg) 70%);
  overflow: auto;
}
.stage__frame {
  display: flex;
  max-height: 100%;
  min-height: 0;
}
#poster {
  display: block;
  max-height: calc(100vh - var(--top-h) - 110px);
  max-width: 100%;
  width: auto; height: auto;
  border-radius: 3px;
  box-shadow: 0 24px 60px rgba(0,0,0,.55), 0 2px 8px rgba(0,0,0,.4);
  touch-action: none;   /* the stage owns drag gestures */
}
.stage__hint, .stage__meta {
  margin: 0; font-size: 11.5px; color: var(--muted); text-align: center;
}
.stage__meta { color: #666f7d; font-variant-numeric: tabular-nums; }
.stage__note {
  margin: 0; max-width: 60ch; text-align: center;
  padding: 7px 14px; border-radius: 999px;
  background: rgba(84,200,232,.12);
  border: 1px solid rgba(84,200,232,.35);
  color: #a9dff0; font-size: 12px;
}

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

.toast {
  position: fixed; left: 50%; bottom: 26px;
  transform: translate(-50%, 14px);
  padding: 11px 20px;
  background: #1f242c; color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 12px 34px rgba(0,0,0,.5);
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-err { border-color: var(--danger); color: #ffd7d7; }

/* --------------------------------------------------------------- narrow -- */

@media (max-width: 1080px) {
  .layout { grid-template-columns: 340px 1fr; }
  .tabs .tab small { display: none; }
}

/* ============================================================== mobile == */
/*
 * The desktop split becomes a fixed preview over a scrolling form.
 *
 * Stacking the panel above the canvas (the naive responsive fallback) means
 * every edit is made blind — you type, then scroll past a long form to see
 * what changed. Pinning the poster keeps the feedback loop intact, which is
 * the entire point of the tool.
 */
@media (max-width: 860px) {
  body { height: 100dvh; overflow: hidden; }

  .top {
    height: auto;
    min-height: 54px;
    gap: 10px;
    padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top, 0px));
    flex-wrap: nowrap;
  }
  .brand { flex: none; }
  .brand small { display: none; }
  .brand__mark { width: 26px; height: 26px; border-radius: 6px; }
  .brand strong { font-size: 13px; white-space: nowrap; }

  .grp__head { padding: 13px 14px 11px; }
  .grp__note { margin: -4px 14px 9px; font-size: 11px; line-height: 1.45; }

  .tabs {
    margin-left: auto;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 7px 11px; white-space: nowrap; }
  .tab strong { font-size: 12px; }

  /* Preview on top, fixed height; form scrolls underneath. */
  .layout { display: flex; flex-direction: column; }

  .stage {
    order: -1;
    flex: none;
    height: 42dvh;
    min-height: 220px;
    padding: 10px 10px 6px;
    gap: 6px;
    overflow: hidden;
  }
  .stage__frame { flex: 1; min-height: 0; }
  #poster { max-height: 100%; max-width: 100%; box-shadow: 0 8px 22px rgba(0,0,0,.5); }
  .stage__hint, .stage__meta { display: none; }
  .stage__note { font-size: 11px; padding: 5px 12px; }

  .panel {
    flex: 1;
    min-height: 0;
    border-right: 0;
    border-top: 1px solid var(--line);
    /* Clear the fixed action bar. */
    padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
  .grid { padding: 2px 12px 18px; gap: 11px; }

  /* 16px minimum: anything smaller and iOS Safari zooms the viewport on
     focus, which throws the whole layout off and never zooms back out. */
  .input { font-size: 16px; padding: 10px 11px; }

  /* Primary action stays under the thumb instead of scrolling away. */
  .actions {
    position: fixed;
    z-index: 20;
    left: 0; right: 0; bottom: 0;
    margin-left: 0;
    gap: 5px;
    padding: 9px 8px;
    padding-bottom: calc(9px + env(safe-area-inset-bottom, 0px));
    background: rgba(20, 23, 28, .95);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .actions::-webkit-scrollbar { display: none; }
  .actions .ghost, .actions .primary {
    min-height: 44px;           /* comfortable tap target */
    flex: none;
    padding: 0 10px;
    white-space: nowrap;
  }
  /* Swap to the compact label from data-short. */
  .actions [data-short] { font-size: 0; }
  .actions [data-short]::after {
    content: attr(data-short);
    font-size: 12.5px;
    font-weight: inherit;
  }
  /* Everything else is fixed-width so the primary action takes the remainder
     and is never the thing that gets clipped. */
  #download { flex: 1; min-width: 84px; padding: 0 8px; }

  .scale > span { display: none; }
  .scale { flex: none; }
  .scale select { min-height: 44px; width: 88px; font-size: 14px; padding: 0 5px; }

  .photos { gap: 5px; }
  .toast { bottom: calc(78px + env(safe-area-inset-bottom, 0px)); }
}

/* Very narrow phones: the wordmark yields to the template tabs, which are
   the only header control that actually does anything. */
@media (max-width: 440px) {
  .brand > div { display: none; }
  .tabs { margin-left: 4px; }
}

@media (max-width: 400px) {
  .stage { height: 38dvh; }
  .tab { padding: 7px 9px; }
  .grid { grid-template-columns: 1fr 1fr; gap: 9px; }
}
