:root {
  color-scheme: light;
  --paper: #f5f0e6;
  --surface: #fffdf8;
  --surface-2: #ece6da;
  --ink: #201a14;
  --muted: #766d63;
  --line: #d4cbbd;
  --accent: #bd4d10;
  --accent-dark: #8e3309;
  --success: #39754d;
  --danger: #a33c32;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "Avenir Next", "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--paper); color: var(--ink); }
body { font-size: 15px; line-height: 1.55; -webkit-tap-highlight-color: transparent; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }

.app { min-height: 100dvh; padding-bottom: calc(86px + var(--safe-bottom)); }
.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: calc(62px + var(--safe-top));
  padding: calc(10px + var(--safe-top)) 18px 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(18px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { width: 38px; height: 38px; border-radius: 10px; }
.brand div { display: grid; line-height: 1.15; }
.brand strong { font-size: 18px; }
.brand span { margin-top: 4px; color: var(--muted); font-size: 11px; letter-spacing: .13em; }

main { width: min(100%, 720px); margin: 0 auto; }
.screen { display: none; padding: 24px 14px 18px; }
.screen.is-active { display: block; }
.screen-heading { margin: 4px 4px 24px; }
.screen-heading p, .step { margin: 0 0 5px; color: var(--accent-dark); font: 700 11px/1.2 ui-monospace, SFMono-Regular, monospace; letter-spacing: .16em; }
.screen-heading h1 { margin: 0; font: 700 30px/1.15 Georgia, "Songti SC", serif; }
.screen-heading > span, .library-heading span { display: block; margin-top: 8px; color: var(--muted); font-size: 13px; }

.panel {
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
}
.compact-panel { padding: 14px; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 15px; }
.panel-heading h2 { margin: 0; font-size: 21px; }
.counter { color: var(--muted); font: 600 12px ui-monospace, monospace; }
label { display: block; margin-bottom: 7px; color: var(--muted); font-size: 13px; font-weight: 600; }
.inline-control { display: grid; grid-template-columns: 1fr 48px; gap: 9px; }
select, input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0;
  background: #fff;
}
select, input { min-height: 48px; padding: 0 12px; }
textarea { resize: vertical; padding: 13px; line-height: 1.65; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.image-drop {
  display: grid;
  min-height: 132px;
  place-items: center;
  align-content: center;
  margin: 0;
  padding: 18px;
  border: 1px dashed #a99f91;
  color: var(--ink);
  text-align: center;
}
.image-drop.small { min-height: 104px; }
.image-drop strong { margin: 3px 0; }
.image-drop small { color: var(--muted); font-weight: 400; }
.add-mark { font-size: 26px; font-weight: 300; }
.image-strip { display: flex; gap: 9px; overflow-x: auto; margin-top: 12px; padding-bottom: 4px; }
.image-card { position: relative; flex: 0 0 92px; }
.image-card img { display: block; width: 92px; height: 92px; object-fit: cover; border: 1px solid var(--line); }
.remove-image {
  position: absolute; top: 4px; right: 4px;
  display: grid; width: 25px; height: 25px; place-items: center;
  border: 0; border-radius: 50%; background: rgba(20,17,14,.82); color: white;
}

.prompt-actions { display: grid; grid-template-columns: 1fr 1.35fr; gap: 9px; margin-top: 12px; }
.primary-button, .secondary-button, .danger-button, .quiet-button, .icon-button {
  min-height: 48px; padding: 0 15px; border: 1px solid var(--ink); border-radius: 0; font-weight: 700;
}
.primary-button { background: var(--ink); color: white; }
.secondary-button, .quiet-button, .icon-button { background: transparent; }
.danger-button { border-color: var(--danger); background: transparent; color: var(--danger); }
.icon-button { padding: 0; font-size: 28px; font-weight: 300; }
.text-button { padding: 2px 0; border: 0; border-bottom: 1px solid currentColor; background: transparent; }
.hint { margin: 11px 0 0; color: var(--muted); font-size: 12px; }

.asset-tabs { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 12px; border: 1px solid var(--line); }
.asset-tabs button { min-height: 42px; border: 0; border-right: 1px solid var(--line); background: transparent; }
.asset-tabs button:last-child { border-right: 0; }
.asset-tabs button.is-active { background: var(--ink); color: white; }
.asset-grid, .output-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 12px; }
.asset-card, .output-card { position: relative; border: 1px solid var(--line); background: #fff; }
.asset-card img, .output-card img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.asset-card footer, .output-card footer { padding: 9px; }
.asset-card button { width: 100%; min-height: 36px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--accent-dark); }
.output-card { padding: 0; text-align: left; }
.output-card footer { display: grid; gap: 3px; }
.output-card small { color: var(--muted); }

.repair-list { display: grid; border: 1px solid var(--line); }
.repair-list button { min-height: 62px; padding: 0 16px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; font-weight: 700; }
.repair-list button:last-child { border-bottom: 0; }
.repair-list button:active { background: var(--surface-2); }
.library-toolbar { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.save-output-button { display: grid; place-items: center; margin: 0; color: var(--ink); text-align: center; }
.search-input { margin-top: 10px; }
.empty-state { padding: 48px 0; color: var(--muted); text-align: center; }

.bottom-nav {
  position: fixed; z-index: 30; left: 0; right: 0; bottom: 0;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(68px + var(--safe-bottom));
  padding: 5px 8px var(--safe-bottom);
  border-top: 1px solid var(--line);
  background: rgba(255,253,248,.94);
  backdrop-filter: blur(18px);
}

.connection-heading { align-items: center; }
.connection-status {
  padding: 4px 8px;
  border: 1px solid var(--success);
  color: var(--success);
  font-size: 11px;
  font-weight: 700;
}
.connection-status.is-offline { border-color: var(--muted); color: var(--muted); }
.execution-switch { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); }
.execution-switch button {
  min-height: 66px;
  padding: 10px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  font-weight: 700;
}
.execution-switch button:last-child { border-right: 0; }
.execution-switch button small { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; font-weight: 500; }
.execution-switch button.is-active { background: var(--ink); color: #fff; }
.execution-switch button.is-active small { color: #d8d0c5; }
.connection-button { margin-top: 12px; }
.render-steps { display: grid; border: 1px solid var(--line); }
.render-steps button {
  display: grid;
  grid-template-columns: 38px 1fr;
  min-height: 72px;
  padding: 12px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
}
.render-steps button:last-child { border-bottom: 0; }
.render-steps span { grid-row: 1 / 3; color: var(--accent-dark); font: 700 12px ui-monospace, monospace; }
.render-steps strong { font-size: 16px; }
.render-steps small { color: var(--muted); }
.full-button { width: 100%; margin-top: 12px; }
.bottom-nav button { display: grid; place-items: center; align-content: center; gap: 1px; border: 0; background: transparent; color: var(--muted); font-size: 11px; }
.bottom-nav button span { font-size: 21px; line-height: 1; }
.bottom-nav button.is-active { color: var(--accent-dark); font-weight: 700; }

dialog { width: min(calc(100% - 28px), 620px); padding: 0; border: 1px solid var(--line); border-radius: 0; background: var(--surface); }
dialog::backdrop { background: rgba(20,16,12,.42); backdrop-filter: blur(4px); }
dialog form, .detail-copy { padding: 20px; }
dialog h2 { margin: 0 0 18px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.output-detail img { display: block; width: 100%; max-height: 48dvh; object-fit: contain; background: var(--surface-2); }
.detail-copy > span { display: block; margin-bottom: 10px; color: var(--muted); font-size: 12px; }
.toast {
  position: fixed; z-index: 60; left: 50%; bottom: calc(82px + var(--safe-bottom));
  max-width: calc(100% - 36px); padding: 10px 14px;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: white; font-size: 13px; transition: .2s ease;
}
.toast.is-visible { transform: translate(-50%, 0); opacity: 1; }

@media (min-width: 680px) {
  .screen { padding-left: 24px; padding-right: 24px; }
  .asset-grid, .output-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
