:root {
  --bg: #fff;
  --ink: #111;
  --muted: #858580;
  --line: #deded8;
  --soft: #f3f3ef;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
html { -webkit-text-size-adjust: 100%; }
body {
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button, label, select { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

/* Immediate tactile feedback for touch and pointer controls. */
button:not(:disabled), .photo-picker, .row-action, .choice-option, .choice-primary, .plain-action, .top-action {
  transition: transform 90ms ease, opacity 90ms ease, filter 90ms ease;
  transform-origin: center;
}
button:not(:disabled):active, .photo-picker:active, .photo-picker.is-pressed, .row-action:active, .choice-option:active, .choice-primary:active, .plain-action:active, .top-action:active {
  transform: scale(.96);
  opacity: .72;
  filter: brightness(.90);
}
button:focus-visible, .photo-picker:focus-within, .row-action:focus-visible, .choice-option:focus-visible, .choice-primary:focus-visible, .plain-action:focus-visible, .top-action:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  button:not(:disabled), .photo-picker, .row-action, .choice-option, .choice-primary, .plain-action, .top-action { transition: none; }
}

.is-hidden { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: calc(56px + env(safe-area-inset-top, 0px));
  padding: env(safe-area-inset-top, 0px) 16px 0;
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  background: var(--bg);
}
.brand {
  grid-column: 2;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  white-space: nowrap;
}
.top-action {
  height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  line-height: 1;
}
.back-action { grid-column: 1; text-align: left; font-size: 32px; font-weight: 300; }
.more-action { grid-column: 3; text-align: right; font-size: 14px; letter-spacing: 1px; }

.app-shell { width: 100%; max-width: 620px; margin: 0 auto; }
/* Home is full-bleed like the launch intro. The editor keeps its 620px work area. */
.start-view {
  position: fixed;
  inset: 0;
  z-index: 1;
  width: 100%;
  min-height: 100dvh;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg);
}
body.home-mode .topbar {
  position: fixed;
  inset: 0 0 auto 0;
  width: 100%;
  max-width: none;
  z-index: 20;
  background: transparent;
}
body.home-mode.home-theme-dark .topbar { color: #fff; }
body.home-mode.home-theme-light .topbar { color: #111; }
.start-content { width: min(360px, 100%); display: grid; gap: 32px; }
.start-copy { display: grid; gap: 8px; }
.start-copy strong { font-size: clamp(25px, 7vw, 34px); line-height: 1.02; letter-spacing: -.045em; font-weight: 650; max-width: 300px; }
.start-copy span { color: var(--muted); font-size: 12px; line-height: 1.5; max-width: 300px; }
.start-status { min-height: 18px; margin: -18px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.main-background { position:absolute; inset:0; width:100%; height:100%; object-fit:cover; object-position:center; z-index:0; }
.start-content { position:absolute; z-index:1; left:0; right:0; bottom:0; width:auto; min-height:0; display:flex; flex-direction:column; gap:24px; padding:0 24px calc(28px + env(safe-area-inset-bottom,0px)); }
.start-copy { align-items:flex-start; text-align:left; }
.start-view.has-background .start-copy strong,.start-view.has-background .start-copy span,.start-view.has-background .start-status { color:var(--main-fg,#fff); }
.start-view.has-background .photo-picker { background:var(--main-fg,#fff); color:var(--main-bg,#111); border-color:var(--main-fg,#fff); }
.start-view.has-background.theme-dark { --main-fg:#fff; --main-bg:#111; }
.start-view.has-background.theme-light { --main-fg:#111; --main-bg:#fff; }

.photo-picker {
  width: 100%;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #111;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  border: 0;
  -webkit-appearance: none;
  appearance: none;
  touch-action: manipulation;
}

.edit-view { height: calc(100dvh - 56px); min-height: 0; padding-bottom: calc(94px + var(--safe-bottom)); overflow: hidden; display: flex; flex-direction: column; }
.preview-stage {
  height: auto;
  min-height: 0;
  max-height: none;
  flex: 1 1 auto;
  padding: 20px 18px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.preview-stage canvas { display: block; max-width: 100%; max-height: 100%; width: auto; height: auto; }
.rendering { position: absolute; font-size: 11px; letter-spacing: .08em; color: var(--muted); }

.frame-section { flex: 0 0 clamp(184px, 24.5dvh, 206px); border-top: 1px solid var(--line); overflow: hidden; }
.section-label-row { padding: 12px 18px 0; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.section-label { font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.section-label-row > span { color: var(--muted); font-size: 9px; letter-spacing: .05em; white-space: nowrap; }
.frame-rail {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 8px 18px 8px;
  scroll-snap-type: x proximity;
  scrollbar-width: none;
}
.frame-rail::-webkit-scrollbar { display: none; }
.frame-chip {
  flex: 0 0 104px;
  position: relative;
  padding: 0 0 8px;
  border: 0;
  background: transparent;
  text-align: left;
  scroll-snap-align: start;
}
.frame-thumb-shell {
  width: 104px;
  height: 132px;
  margin-bottom: 8px;
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: #fff;
}
.frame-thumb-shell.is-landscape { height: 92px; margin-top: 20px; margin-bottom: 20px; }
.frame-thumb-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  outline: 0;
  background: #fff;
}
.frame-chip span {
  display: block;
  overflow: hidden;
  color: #777;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .08em;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.frame-chip.active span { color: #111; font-weight: 700; }
.frame-chip.active::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: #111; }

.save-area {
  position: fixed;
  z-index: 15;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 6px 18px calc(4px + var(--safe-bottom));
  background: rgba(255, 255, 255, .98);
  pointer-events: none;
}
.export-actions { pointer-events: auto; width: min(584px, 100%); margin: 0 auto; display: grid; grid-template-columns: .42fr 1fr; gap: 8px; }
.save-btn,.share-btn { height: 52px; border: 0; font-size: 14px; font-weight: 600; }
.save-btn { background: #111; color: #fff; }
.share-btn { background: #efefec; color: #111; }
.save-btn:disabled,.share-btn:disabled { opacity: .25; cursor: default; }
.status-text { height: 14px; margin: 3px 0 0; text-align: center; color: var(--muted); font-size: 10px; }

.sheet-backdrop { position: fixed; inset: 0; z-index: 29; background: rgba(0, 0, 0, .18); }
.sheet, .choice-sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(620px, 100%);
  max-height: 82dvh;
  overflow: auto;
  background: #fff;
  border-top: 1px solid #d3d3ce;
  padding: 8px 20px calc(20px + var(--safe-bottom));
}
.sheet { z-index: 30; }
.choice-sheet { z-index: 31; }
.sheet-handle { width: 34px; height: 3px; margin: 2px auto 16px; background: #c8c8c2; }
.sheet-head, .choice-head { height: 50px; border-bottom: 1px solid var(--line); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head strong { font-size: 16px; font-weight: 600; }
.plain-action { padding: 10px 0; border: 0; background: transparent; color: #666; font-size: 12px; }

.settings-list { border-top: 1px solid var(--line); }
.settings-row {
  min-height: 66px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
}
div.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.settings-copy { min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.settings-copy span, .setting-select-row > span { color: var(--muted); font-size: 12px; }
.settings-copy strong { overflow: hidden; font-size: 14px; font-weight: 500; white-space: nowrap; text-overflow: ellipsis; }
.row-action { min-width: 54px; height: 34px; padding: 0; border: 0; background: transparent; text-align: right; font-size: 12px; font-weight: 600; }
.setting-select-row { display: grid; grid-template-columns: 1fr minmax(110px, 50%); align-items: center; gap: 18px; }
.setting-select-row select { width: 100%; border: 0; background: transparent; outline: none; text-align: right; text-align-last: right; font-size: 13px; }

.meta-detail { padding: 5px 0 12px; border-bottom: 1px solid var(--line); }
.meta-detail > div { display: grid; grid-template-columns: 78px minmax(0, 1fr); gap: 12px; padding: 6px 0; }
.meta-detail span, .sheet-foot { color: var(--muted); font-size: 9px; letter-spacing: .10em; }
.meta-detail b { overflow: hidden; text-align: right; font-size: 11px; font-weight: 500; white-space: nowrap; text-overflow: ellipsis; }

.custom-size-row {
  display: grid;
  grid-template-columns: 1fr 18px 1fr;
  gap: 8px;
  align-items: end;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.custom-size-row label { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: center; color: var(--muted); font-size: 11px; }
.custom-size-row input { width: 100%; height: 36px; border: 0; border-bottom: 1px solid #bfbfba; border-radius: 0; background: transparent; outline: none; text-align: right; color: var(--ink); font-size: 13px; }
.custom-size-x { padding-bottom: 8px; text-align: center; color: var(--muted); font-size: 12px; }
.sheet-foot { display: flex; justify-content: space-between; padding-top: 18px; }
.sheet-foot a { color: inherit; text-decoration: none; }

.choice-head { display: grid; grid-template-columns: 44px 1fr 44px; align-items: center; }
.choice-head button { padding: 0; border: 0; background: transparent; text-align: left; font-size: 30px; font-weight: 300; }
.choice-head strong { text-align: center; font-size: 14px; font-weight: 600; }
.choice-body { padding-top: 4px; }
.choice-option {
  width: 100%;
  min-height: 54px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  font-size: 14px;
}
.choice-option small { color: var(--muted); font-size: 10px; font-weight: 400; }
.choice-option.active { font-weight: 600; }
.choice-option.active::after { content: "✓"; font-size: 13px; }
.choice-more { color: #555; }
.choice-input { width: 100%; height: 48px; margin: 18px 0 12px; border: 0; border-bottom: 1px solid #111; border-radius: 0; background: transparent; outline: none; font-size: 16px; }
.choice-primary { width: 100%; height: 48px; border: 0; background: #111; color: #fff; font-size: 13px; font-weight: 600; }


/* Keep the home UI out of view until remote launch settings are resolved.
   This prevents the main screen from flashing before an enabled intro image. */
.boot-pending body { background: #fff; }
.boot-pending .topbar,
.boot-pending .app-shell { visibility: hidden !important; }

.app-intro { position: fixed; inset: 0; z-index: 9999; display: flex; align-items: center; justify-content: center; background: #fff; opacity: 1; transition: opacity .22s ease; }
.app-intro.is-leaving { opacity: 0; pointer-events: none; }
.app-intro img { display: block; width: 100%; height: 100%; object-fit: cover; object-position: center; }

@media (min-width: 700px) {
  .topbar { max-width: 620px; margin: auto; }
  .edit-view { border-left: 1px solid #e8e8e3; border-right: 1px solid #e8e8e3; }
  .save-area { width: 620px; left: 50%; right: auto; transform: translateX(-50%); }
}
@media (max-height: 700px) { .preview-stage { padding-top: 12px; padding-bottom: 10px; } }
@media (prefers-reduced-motion: reduce) { 
/* Keep the home UI out of view until remote launch settings are resolved.
   This prevents the main screen from flashing before an enabled intro image. */
.boot-pending body { background: #fff; }
.boot-pending .topbar,
.boot-pending .app-shell { visibility: hidden !important; }

.app-intro { transition: none; } }

