/* NAI 生成器 mobile — layout and theme following the official NovelAI mobile page (novelai.net/image at
 * phone width; measurements in docs/ref-measure). Colours: page #13152C, bars and panels #191B31, lines and
 * buttons #22253F, inputs #0E0F21, accent #F5F3C2. Fonts: Source Sans Pro, Eczar for titles and numbers. */
:root {
  --bg: #13152c; --panel: #191b31; --line: #22253f; --input: #0e0f21; --accent: #f5f3c2; --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.7); --faint: rgba(255, 255, 255, 0.5); --error: #ff7878; --warning: #f5c26b;
  --top: calc(46px + var(--safe-area-inset-top, env(safe-area-inset-top))); --bottom: calc(60px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom)));
  --peek: 56px;
  --sans: "Source Sans Pro", -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  --serif: Eczar, Georgia, serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--sans); font-size: 16px; overflow: hidden;
  overscroll-behavior: none; -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: 0.5; }
input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
a { color: inherit; }

/* Icons: the official SVGs as masks, coloured by currentColor. */
.ic { display: inline-block; width: 16px; height: 16px; flex: none; background-color: currentColor;
  -webkit-mask: var(--i) center / contain no-repeat; mask: var(--i) center / contain no-repeat; }
.ic-logo { --i: url(../media/pen-tip-light.svg); width: 16px; height: 18px; }
.ic-anla { --i: url(../media/anla.svg); width: 10px; height: 10px; }
.ic-plus { --i: url(../media/plus.svg); width: 14px; height: 14px; }
.ic-menu { --i: url(../media/hamburger_alt.svg); }
.ic-settings { --i: url(../media/settings.svg); width: 18px; height: 18px; }
.ic-history { --i: url(../media/history.svg); width: 18px; height: 18px; }
.ic-cross { --i: url(../media/cross.svg); width: 14px; height: 14px; }
.ic-small-cross { --i: url(../media/small_cross.svg); width: 10px; height: 10px; }
.ic-check { --i: url(../media/check.svg); width: 10px; height: 10px; }
.ic-arrow-up { --i: url(../media/directional_arrow_up.svg); width: 12px; height: 6px; }
.ic-arrow-down { --i: url(../media/directional_arrow_down.svg); width: 12px; height: 6px; }
.ic-dice { --i: url(../media/dice_alt.svg); }
.ic-unfold { --i: url(../media/detatch_up.svg); }
.ic-sparkles { --i: url(../media/sparkles.svg); }
.ic-variations { --i: url(../media/variations.svg); }
.ic-upscale { --i: url(../media/upscale.svg); }
.ic-pen { --i: url(../media/pen.svg); }
.ic-dots { --i: url(../media/dotdotdot.svg); }
.ic-pin { --i: url(../media/pin.svg); }
.ic-clipboard { --i: url(../media/clipboard.svg); }
.ic-save { --i: url(../media/save.svg); }
.ic-easel { --i: url(../media/easel.svg); }
.ic-seed { --i: url(../media/seed.svg); width: 14px; height: 14px; }
.ic-lock { --i: url(../media/lock.svg); width: 14px; height: 14px; }
.ic-trash { --i: url(../media/trash.svg); width: 14px; height: 14px; }
.ic-landscape { --i: url(../media/res_landscape.svg); }
.ic-portrait { --i: url(../media/res_portrait.svg); }
.ic-square { --i: url(../media/res_square.svg); }
.ic-person { --i: url(../media/person.svg); }
.ic-help { --i: url(../media/help.svg); }
.ic-explore { --i: url(../media/explore.svg); width: 20px; height: 20px; }
.ic-book { --i: url(../media/book-open.svg); width: 20px; height: 20px; }
.ic-discord { --i: url(../media/discord.svg); width: 20px; height: 20px; }
.ic-text { --i: url(../media/text.svg); width: 20px; height: 20px; }
.ic-lang { --i: url(../media/lang_en.svg); width: 20px; height: 20px; }
.ic-key { --i: url(../media/lock.svg); width: 18px; height: 18px; }
.ic-running { --i: url(../media/running.svg); width: 20px; height: 20px; }
.ic-chevron { --i: url(../media/small_arrow.svg); width: 10px; height: 10px; }
.ic-fur { --i: url(../media/sakura.svg); width: 14px; height: 14px; }
.ic-reload { --i: url(../media/redo.svg); }
.ic-fold { --i: url(../media/unfold.svg); width: 14px; height: 14px; }
.ic-img2img { --i: url(../media/img2img.svg); width: 18px; height: 18px; }
.ic-vibe { --i: url(../media/vibe_transfer.svg); width: 18px; height: 18px; }
.ic-precise { --i: url(../media/precise_reference.svg); width: 18px; height: 18px; }
.ic-import { --i: url(../media/import.svg); width: 18px; height: 18px; }
.ic-inpaint { --i: url(../media/inpaint.svg); }
.ic-arrow-left { --i: url(../media/small_chevron_left.svg); }
.ic-precise-style { --i: url(../media/precise_reference_style.svg); }
.ic-precise-style-char { --i: url(../media/precise_reference_style_and_character.svg); }
.ic-tool-bg-removal { --i: url(../media/wand_sparkles.svg); width: 20px; height: 20px; }
.ic-tool-lineart { --i: url(../media/pen.svg); width: 20px; height: 20px; }
.ic-tool-sketch { --i: url(../media/pen-tip-light.svg); width: 20px; height: 20px; }
.ic-tool-colorize { --i: url(../media/dropper.svg); width: 20px; height: 20px; }
.ic-tool-emotion { --i: url(../media/speech-bubble.svg); width: 20px; height: 20px; }
.ic-tool-declutter { --i: url(../media/eraser.svg); width: 20px; height: 20px; }
.ic-tool-pixel-snap { --i: url(../media/select.svg); width: 20px; height: 20px; }
.ic-export { --i: url(../media/export.svg); width: 18px; height: 18px; }

/* ---------- app frame ---------- */
#app { position: fixed; inset: 0; display: block; }
.topbar { position: absolute; left: 0; right: 0; top: 0; height: var(--top); padding: var(--safe-area-inset-top, env(safe-area-inset-top)) 10px 0;
  background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; z-index: 20; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 28px; border-radius: 4px; background: var(--line); }
.icon-btn.flat { background: transparent; }
.topbar .logo { background: transparent; }
.anlas { display: flex; height: 31px; }
.anlas-balance { display: flex; align-items: center; gap: 2px; padding: 4px 12px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px 0 0 8px; color: var(--accent); font: 600 14px/1 var(--serif); }
.anlas-balance .ic { color: var(--accent); }
.anlas-balance.is-loading { opacity: 0.6; }
.anlas-buy { display: flex; align-items: center; padding: 4px 14px; background: var(--line); border-radius: 0 8px 8px 0; color: var(--text); }

#stage { position: absolute; left: 0; right: 0; top: var(--top); bottom: calc(var(--bottom) + var(--peek)); overflow: hidden; }
.bottombar { position: absolute; left: 0; right: 0; bottom: 0; height: var(--bottom); padding: 10px 10px var(--safe-area-inset-bottom, env(safe-area-inset-bottom));
  background: var(--panel); display: flex; gap: 8px; z-index: 40; }
.bottombar .icon-btn { width: 48px; height: 40px; }
.generate { flex: 1; height: 40px; display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 4px 12px;
  border-radius: 4px; background: var(--accent); color: var(--bg); font-weight: 700; }
.generate .cost { display: flex; align-items: center; gap: 4px; height: 24px; padding: 0 8px; border-radius: 4px; background: var(--bg); color: var(--accent); font-weight: 600; }
.generate .cost .ic { color: var(--accent); }
.generate:disabled { opacity: 0.55; }
.generate.is-busy { opacity: 0.55; }

/* ---------- welcome ---------- */
#welcome { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 24px; text-align: center; }
#welcome h1 { font: 700 20px/1.5 var(--serif); color: var(--accent); }
#welcome p { color: var(--muted); font-size: 15px; line-height: 1.5; }
#welcome .welcome-key { margin-top: 12px; }
#welcome.has-gallery { justify-content: flex-start; overflow-y: auto; overflow-x: hidden; padding: 20px 20px 24px; gap: 8px; }
#welcome.has-gallery h1 { margin-top: 8px; }
.qs { width: 100%; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.qs h2 { font: 700 20px/1.5 var(--serif); color: var(--accent); }
.qs-hint { margin-top: 12px; opacity: 0.7; }
.qs-grid { width: 100%; display: flex; gap: 8px; align-items: flex-start; margin-top: 16px; }
.qs-column { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.qs-tile { position: relative; width: 100%; padding: 0; border: 0; border-radius: 8px; overflow: hidden; background: rgba(255, 255, 255, 0.06); cursor: pointer; }
.qs-tile img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.25s; }
.qs-tile.is-loaded img { opacity: 1; }
.qs-tile.is-empty { display: none; }

/* ---------- viewer: toolbar, progress, image area, actions ---------- */
#viewer { position: absolute; inset: 0; }
.image-toolbar { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 0;
  height: 38px; padding: 0 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; z-index: 5; }
.image-toolbar .tb { display: flex; align-items: center; gap: 6px; height: 36px; padding: 0 12px; }
.image-toolbar .tb-cost { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 3px; background: var(--line); font-size: 14px; font-weight: 600; }
.progress { position: absolute; left: 12px; right: 12px; top: 52px; height: 10px; padding: 3px 4px; border-radius: 999px; background: rgba(19, 21, 44, 0.75);
  z-index: 6; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
.progress.is-active { opacity: 1; }
.progress-track { position: relative; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.progress-fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 2px; background: var(--accent); }
.progress.is-queued .progress-fill { width: 35% !important; animation: queue-slide 1.4s ease-in-out infinite; }
@keyframes queue-slide { 0% { left: -35%; } 100% { left: 100%; } }
#view-area { position: absolute; left: 0; right: 0; top: 56px; bottom: 54px; overflow: hidden; touch-action: pan-y; }
.view-single { position: absolute; inset: 0; display: flex; }
.view-strip { position: absolute; top: 0; bottom: 0; left: 0; display: flex; will-change: transform; }
.view-slide { flex: none; height: 100%; display: flex; align-items: center; justify-content: center; padding: 8px 24px; }
.view-slide img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  background-color: var(--bg); background-image: linear-gradient(45deg, #171930 25%, transparent 25%, transparent 75%, #171930 75%), linear-gradient(45deg, #171930 25%, transparent 25%, transparent 75%, #171930 75%);
  background-size: 16px 16px; background-position: 0 0, 8px 8px; }
.view-grid { position: absolute; inset: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(var(--cols, 2), 1fr); gap: 20px 18px; padding: 8px 24px;
  align-content: center; }
.view-grid .cell { position: relative; aspect-ratio: var(--ratio, 2 / 3); border-radius: 8px; overflow: hidden; background: #191b31; border: 1px solid var(--line); }
.view-grid .cell img { width: 100%; height: 100%; object-fit: contain; display: block; }
.view-grid .cell .stream { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.view-grid .cell .stream-blur { position: absolute; inset: 0; backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px); }
.dots { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 6px; }
.dots i { width: 10px; height: 10px; border-radius: 50%; background: rgba(255, 255, 255, 0.6); animation: dot 1.2s infinite ease-in-out; }
.dots i:nth-child(2) { animation-delay: 0.2s; } .dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot { 0%, 80%, 100% { opacity: 0.15; } 40% { opacity: 1; } }
.image-actions { position: absolute; left: 12px; right: 12px; bottom: 8px; height: 38px; display: flex; justify-content: space-between; gap: 8px; z-index: 5; }
.image-actions .group { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.image-actions button { width: 40px; height: 36px; display: flex; align-items: center; justify-content: center; }
.image-actions button.is-on { color: var(--accent); }
.pin-strip { position: absolute; top: 46px; left: 50%; transform: translateX(-50%); }

/* ---------- prompt drawer ---------- */
.drawer { position: absolute; left: 0; right: 0; bottom: var(--bottom); height: calc(100% - var(--top) - var(--bottom)); z-index: 30;
  transform: translateY(calc(100% - var(--peek))); transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  background: var(--panel); border-top: 1px solid var(--line); border-radius: 8px 8px 0 0; box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
  display: flex; flex-direction: column; touch-action: none; }
.drawer::before { content: ''; position: absolute; left: 0; right: 0; top: -60px; height: 60px; pointer-events: none;
  background: linear-gradient(rgba(19, 21, 44, 0), var(--bg)); opacity: 1; transition: opacity 0.2s; }
.drawer[data-state="half"] { transform: translateY(var(--half-offset, 30%)); }
.drawer[data-state="full"] { transform: translateY(0); }
.drawer[data-state="half"]::before, .drawer[data-state="full"]::before { opacity: 0; }
.drawer.is-dragging { transition: none; }
.drawer-scrim { position: absolute; left: 0; right: 0; top: var(--top); bottom: var(--bottom); background: #000; opacity: 0; pointer-events: none; transition: opacity 0.28s; z-index: 25; }
.drawer-scrim.is-on { opacity: 0.45; pointer-events: auto; }
.drawer-grip { flex: none; height: 21px; display: flex; justify-content: center; padding-top: 9px; }
.drawer-grip i { width: 36px; height: 4px; border-radius: 2px; background: var(--line); }
.drawer-peek { flex: none; height: 30px; display: flex; align-items: center; gap: 12px; padding: 0 18px 6px; font-size: 14px; }
.drawer-peek span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.drawer-peek span.is-empty { color: var(--muted); }
.drawer[data-state="half"] .drawer-peek, .drawer[data-state="full"] .drawer-peek { display: none; }
.drawer-tabs { flex: none; display: none; justify-content: center; border-bottom: 1px solid rgba(255, 255, 255, 0.08); padding: 0 8px; }
.drawer[data-state="half"] .drawer-tabs, .drawer[data-state="full"] .drawer-tabs { display: flex; }
.drawer-tabs button { display: flex; align-items: center; gap: 6px; padding: 8px 12px 10px; font-size: 14px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.drawer-tabs button.is-active { color: var(--text); border-bottom-color: var(--accent); }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 15px; padding: 2px 6px; border-radius: 8px;
  background: var(--line); font-size: 11.2px; font-weight: 600; line-height: 1; }
.drawer-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 13px 24px; touch-action: pan-y; overscroll-behavior: contain; }
.drawer[data-state="collapsed"] .drawer-body { visibility: hidden; }
.tab-page { display: flex; flex-direction: column; gap: 16px; }

/* prompt box */
.prompt-box { background: var(--input); border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; }
.prompt-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 0; }
.seg-tabs { display: flex; gap: 8px; }
.seg-tabs button { padding: 2px 5px; border-radius: 4px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg-tabs button.is-active { background: var(--line); color: var(--text); }
.prompt-tools { display: flex; gap: 10px; }
.prompt-tools button { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; }
.prompt-field .nai-prompt-field { min-height: 106px; max-height: 42vh; overflow-y: auto; padding: 5px 12px; font-size: 16px; line-height: 1.625rem; overscroll-behavior: contain; }
.character .prompt-field .nai-prompt-field { min-height: 52px; max-height: 32vh; }
.drawer[data-state="full"] .prompt-field .nai-prompt-field { max-height: 55vh; }
.prompt-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 12px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 20px; padding: 0 10px; border-radius: 10px; background: var(--panel); font-size: 12px; font-weight: 600; color: var(--muted); }
.chip.is-on { color: var(--text); }
.chip.is-on .ic { color: var(--accent); }
.select-chip { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 10px; border-radius: 10px; background: var(--panel); font-size: 14px; }
.token-bar { position: relative; margin: 10px 12px 14px; height: 4px; border-radius: 3px; background: var(--panel); overflow: hidden; display: flex; }
.token-bar i { display: block; height: 100%; width: 0; transition: width 0.2s; }
.token-bar .token-bar-other { background: rgba(255, 255, 255, 0.45); }
.token-bar .token-bar-own { background: var(--text); min-width: 3px; border-radius: 0 3px 3px 0; }
.token-bar.over-limit .token-bar-own, .token-bar.over-limit .token-bar-other { background: var(--error); }
.random-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 0; font-weight: 600; }
.random-head div { display: flex; gap: 6px; }
.random-head button { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.card-head { display: flex; align-items: flex-start; gap: 10px; }
.card-head > div { flex: 1; min-width: 0; }
.card-title { font-weight: 600; font-size: 16px; }
.card-sub { font-size: 14px; color: var(--muted); line-height: 1.5; }
.square-btn { width: 44px; height: 40px; border-radius: 4px; background: var(--line); display: flex; align-items: center; justify-content: center; flex: none; }
.placeholder-note { color: var(--faint); font-size: 13px; text-align: center; padding: 24px 12px; }

/* ---------- full-screen panels (settings, history, menu) ---------- */
.panel { position: absolute; left: 0; right: 0; top: 0; bottom: var(--bottom); background: var(--panel); z-index: 35; display: flex; flex-direction: column;
  padding-top: var(--safe-area-inset-top, env(safe-area-inset-top)); animation: panel-in 0.2s ease-out; }
@keyframes panel-in { from { opacity: 0; transform: translateY(12px); } }
.panel-head { flex: none; height: 54px; display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 12px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); }
.panel-head h2 { font: 700 18px/1.5 var(--serif); }
.panel-head .close { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; margin-right: -8px; }
.panel-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 16px; overscroll-behavior: contain; }
.panel.menu { z-index: 45; bottom: 0; background: var(--bg); }

/* settings controls */
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field-box { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 4px 4px 4px 12px; border: 1px solid var(--line); border-radius: 8px; }
.field-box > span { font-size: 16px; }
.pill-select { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px 0 11px; border-radius: 4px; background: var(--line); font-size: 14px; font-weight: 600; }
.section-label { margin: 24px 0 6px; font-size: 14px; color: var(--muted); }
.section-label:first-child { margin-top: 0; }
.label-row { display: flex; align-items: center; justify-content: space-between; margin: 12px 0 8px; }
.label { font-size: 16px; font-weight: 600; }
.size-box { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 8px; border-radius: 4px; background: var(--line); }
.size-box input { width: 50px; border: none; outline: none; background: transparent; font-size: 16px; text-align: center; -moz-appearance: textfield; }
.size-box button { padding: 0 2px; color: var(--muted); }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.dropdown { display: inline-flex; align-items: center; justify-content: space-between; gap: 8px; height: 40px; padding: 0 12px; border-radius: 8px;
  background: var(--line); border: 1px solid var(--line); font-weight: 600; font-size: 16px; min-width: 114px; }
.segmented { display: flex; flex: 1; height: 40px; padding: 4px; gap: 4px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.segmented button { flex: 1; border-radius: 4px; font-size: 16px; font-weight: 600; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.segmented button.is-active { background: var(--line); color: var(--text); }
.slider-row { display: flex; align-items: center; gap: 8px; }
.num { width: 56px; height: 28px; padding: 0 4px; border: 1px solid var(--line); border-radius: 4px; background: var(--input); text-align: center; font-size: 16px; font-weight: 600; outline: none; }
input[type=range] { flex: 1; -webkit-appearance: none; appearance: none; height: 28px; background: transparent; padding-left: 10px; }
input[type=range]::-webkit-slider-runnable-track { height: 14px; border-radius: 4px; background: var(--input); }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 24px; margin-top: -5px; border-radius: 3px; background: var(--line); border: 1px solid #3a3d63; }
.seed-row { display: flex; gap: 3px; }
.seed-row input { width: 118px; height: 36px; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; background: var(--input); outline: none; font-size: 14px; }
.seed-row button { width: 32px; height: 36px; border-radius: 3px; background: var(--line); display: flex; align-items: center; justify-content: center; }
.two-col { display: grid; grid-template-columns: auto 1fr; gap: 0 20px; }
.toggle-chip { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border: 1px solid var(--line); border-radius: 4px; font-size: 13px; color: var(--muted); }
.toggle-chip.is-on { color: var(--text); border-color: var(--accent); }
.disclosure { display: inline-flex; align-items: center; gap: 8px; margin-top: 20px; font-size: 14px; font-weight: 600; color: var(--muted); }
.disclosure .ic { transition: transform 0.2s; }
.disclosure.is-open .ic { transform: rotate(90deg); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }
.switch-row small { display: block; color: var(--faint); font-size: 13px; margin-top: 2px; }
.switch { position: relative; flex: none; width: 36px; height: 20px; border-radius: 10px; background: var(--input); border: 1px solid var(--line); }
.switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 3px; background: var(--line); transition: transform 0.2s, background 0.2s; }
.switch.is-on { background: var(--accent); }
.switch.is-on::after { transform: translateX(16px); background: var(--bg); }

/* option sheet (dropdown lists open as a sheet near the control, like the official react-select menus) */
.sheet-scrim { position: fixed; inset: 0; z-index: 60; }
.sheet { position: fixed; z-index: 61; min-width: 160px; max-height: 60vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 4px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45); padding: 4px 0; }
.sheet .group-label { padding: 10px 12px 4px; font-size: 11px; font-weight: 600; color: var(--faint); text-transform: uppercase; letter-spacing: 0.04em; }
.sheet .option { display: block; width: 100%; text-align: left; padding: 8px 12px; font-size: 15px; }
.sheet .option.is-selected { color: var(--accent); background: rgba(255, 255, 255, 0.04); }
.sheet .option b { display: block; font: 700 14px/1.4 var(--serif); }
.sheet .option small { display: block; font-size: 13px; color: var(--muted); line-height: 1.4; margin-top: 2px; }

/* history */
.history-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 8px 8px 8px 10px; }
.history-item { position: relative; aspect-ratio: 1; border-radius: 3px; border: 2px solid transparent; background: var(--input) center / contain no-repeat; overflow: hidden; }
.history-item.is-selected { box-shadow: 0 0 0 2px rgba(245, 243, 194, 0.75), 0 0 8px rgba(245, 243, 194, 0.45); }
.history-item .count { position: absolute; right: 4px; bottom: 4px; min-width: 28px; height: 28px; padding: 0 4px; border-radius: 3px; background: rgba(25, 27, 49, 0.7);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 16px; }
.history-item.is-generating { display: flex; align-items: center; justify-content: center; }
.history-empty { padding: 40px 16px; text-align: center; color: var(--faint); }
.panel-foot { flex: none; display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.panel-foot button { width: 38px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: 3px; }
.panel-foot button.is-on { background: var(--line); color: var(--accent); }

/* menu */
.menu-body { padding: 0 20px 24px; }
.menu-card { display: flex; align-items: center; gap: 15px; padding: 20px 0; border-bottom: 1px solid var(--line); }
.menu-card .avatar { width: 60px; height: 60px; border-radius: 50%; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.menu-card .avatar .ic { width: 26px; height: 30px; color: var(--accent); }
.menu-card h3 { font: 700 22px/1.5 var(--serif); color: var(--accent); }
.menu-card p { font-weight: 600; }
.menu-section { padding: 10px 0; font-size: 14px; font-weight: 600; margin-top: 10px; }
.menu-item { width: 100%; height: 44px; display: flex; align-items: center; gap: 15px; padding: 0 20px; margin-bottom: 10px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 5px; font-weight: 600; text-decoration: none; text-align: left; }
.menu-item .ic { width: 20px; height: 20px; }
.menu-item .value { margin-left: auto; color: var(--muted); font-weight: 400; font-size: 14px; }
.ip-line { display: block; width: 100%; text-align: left; margin-top: 8px; font-size: 13px; color: var(--muted); }
.ip-line.is-error { color: var(--error); }
.menu-version { margin-top: 18px; font-size: 13px; color: var(--faint); }

/* modal dialogs (API key, confirm) */
.modal-scrim { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 20px; position: relative; }
.modal h2 { font: 700 20px/1.4 var(--serif); color: var(--accent); margin-bottom: 8px; padding-right: 28px; }
.modal p { font-size: 14px; line-height: 1.5; color: var(--muted); margin-bottom: 12px; }
.modal .close { position: absolute; top: 12px; right: 12px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.text-input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; background: var(--input); outline: none; font-size: 15px; }
.text-input:focus { border-color: #3a3d63; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.btn { flex: 1; height: 42px; border-radius: 4px; background: var(--line); font-weight: 700; }
.btn.primary { background: var(--accent); color: var(--bg); }
.btn.danger { background: var(--error); color: var(--bg); }
.status-line { min-height: 20px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.status-line.is-ok { color: #9be29b; } .status-line.is-error { color: var(--error); }

/* image info sheet */
.info-list { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; }
.info-list dt { color: var(--muted); }
.info-list dd { word-break: break-word; }
.info-prompt { margin-top: 12px; padding: 10px; background: var(--input); border-radius: 4px; font-size: 14px; line-height: 1.5; max-height: 30vh; overflow-y: auto; user-select: text; -webkit-user-select: text; }

/* ---------- M2: characters, positions, chunks, tag suggestions, import ---------- */
.light-btn { display: block; width: auto; flex: none; height: auto; padding: 2px 10px; margin-top: 10px; border-radius: 3px; background: var(--line); font-weight: 600; font-size: 14px; }
.characters { display: flex; flex-direction: column; gap: 10px; }
.characters:empty { display: none; }
.character { background: var(--input); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.character.is-disabled { opacity: 0.55; }
.character-head { display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); }
.character-icon { width: 16px; height: 16px; display: flex; flex: none; }
.character-icon svg { width: 100%; height: 100%; }
.character.is-random .character-icon { color: var(--accent); }
.character-name { flex: 1; min-width: 0; height: 26px; border: none; outline: none; background: transparent; font-size: 16px; font-weight: 600; }
.character-name::placeholder { color: var(--muted); }
.character-actions { display: flex; }
.character-actions button { width: 34px; height: 30px; display: flex; align-items: center; justify-content: center; }
.character-body { padding-top: 10px; }
.character-tabs { padding: 0 12px; }
.character-summary { display: block; width: 100%; text-align: left; padding: 10px 12px; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.position-row { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.position-row > span { font-size: 14px; color: var(--muted); }
.position-toggle { flex: 1; display: flex; padding: 4px; gap: 4px; border: 1px solid var(--line); border-radius: 8px; }
.position-toggle button { flex: 1; height: 30px; border-radius: 4px; font-weight: 600; font-size: 15px; color: var(--muted); }
.position-toggle button[data-position="edit"] { flex: none; width: 34px; display: flex; align-items: center; justify-content: center; }
.position-toggle button.is-active { background: var(--line); color: var(--text); }
.position-toggle button.is-editing { color: var(--accent); }
.position-warning { margin-top: 8px; font-size: 13px; color: var(--error); line-height: 1.4; }
.position-editor { position: absolute; inset: 0; z-index: 12; background: var(--bg); display: flex; flex-direction: column; }
.position-selector { flex: none; display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; padding: 8px 12px; }
.position-chip { display: flex; align-items: center; gap: 3px; height: 30px; padding: 0 10px; border-radius: 4px; background: var(--panel); border: 1px solid var(--line); font-weight: 600; }
.position-chip svg { width: 14px; height: 14px; }
.position-chip.is-selected { background: #fff; color: var(--bg); }
.position-chip.is-disabled { opacity: 0.4; }
.position-stage-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px 12px; }
.position-stage { position: relative; background: var(--input); border: 1px solid var(--line); touch-action: none; }
.position-guides { position: absolute; inset: 0; width: 100%; height: 100%; stroke: rgba(255, 255, 255, 0.25); stroke-width: 0.4; vector-effect: non-scaling-stroke; pointer-events: none; }
.position-cells { position: absolute; inset: 0; display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(5, 1fr); }
.position-cell { border: 1px solid rgba(255, 255, 255, 0.06); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.position-cell:not(:empty) { background: rgba(245, 243, 194, 0.12); }
.position-cell.is-selected { background: rgba(245, 243, 194, 0.35); color: var(--accent); }
.position-cell.is-warning { background: rgba(255, 120, 120, 0.3); color: var(--error); }
.position-marker { position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%; background: #fff; color: var(--bg); display: flex; align-items: center; justify-content: center;
  font-weight: 700; box-shadow: 0 0 0 2px rgba(19, 21, 44, 0.6); pointer-events: none; }
.position-marker.is-selected { background: var(--accent); box-shadow: 0 0 0 3px rgba(245, 243, 194, 0.35); }
.position-foot { flex: none; display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 12px; }
.position-done { flex: none; padding: 0 18px; }
.position-guide-wrap { position: relative; }
.position-guide-button.is-on { color: var(--accent); }
.position-guide-pop { position: absolute; bottom: 48px; left: 0; display: flex; padding: 4px; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.position-guide-pop button { padding: 6px 12px; border-radius: 4px; font-weight: 600; color: var(--muted); }
.position-guide-pop button.is-active { background: var(--line); color: var(--text); }
.prompt-settings { padding-top: 12px; border-top: 1px solid var(--line); }
.section-chip { display: inline-block; padding: 2px 8px; border-radius: 3px; background: var(--line); font-size: 14px; margin-bottom: 4px; }
.prompt-settings .switch-row span { font-weight: 600; }

.chunk-head { display: flex; align-items: center; justify-content: space-between; }
.chunk-tools { display: flex; gap: 4px; }
.chunk-tools button { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; }
.chunk-list { display: flex; flex-direction: column; gap: 10px; }
.chunk-empty { color: var(--muted); font-size: 13px; padding: 8px 0 16px; }
.chunk-pills { display: flex; flex-wrap: wrap; gap: 6px; }
.chunk-pill { max-width: 100%; display: inline-flex; flex-direction: column; align-items: flex-start; gap: 1px; padding: 6px 10px; border-radius: 6px; text-align: left;
  background: color-mix(in srgb, var(--chunk-color) 22%, transparent); border: 1px solid color-mix(in srgb, var(--chunk-color) 60%, transparent); -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.chunk-label { font-weight: 600; font-size: 14px; }
.chunk-text { font-size: 12px; color: var(--muted); max-width: 260px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chunk-category { border: 1px solid var(--line); border-radius: 6px; padding: 6px; }
.chunk-category-head { width: 100%; display: flex; align-items: center; gap: 8px; padding: 4px; font-weight: 600; border-left: 3px solid var(--chunk-color); }
.chunk-category-head .ic.is-open { transform: rotate(90deg); }
.chunk-category-name { flex: 1; text-align: left; }
.chunk-edit { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; }
.chunk-category .chunk-pills { padding: 6px 4px 2px; }
.chunk-delete-all { margin-top: 8px; height: 46px; flex: none; width: 100%; }
.chunk-form { display: flex; flex-direction: column; gap: 6px; }
.chunk-form-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.chunk-form-head .close { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.chunk-field-label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.chunk-content { height: 90px; padding: 8px 12px; resize: vertical; line-height: 1.5; }
.chunk-hue { width: 100%; padding: 0; height: 24px; }
input.chunk-hue::-webkit-slider-runnable-track { height: 14px; border-radius: 7px; background: linear-gradient(90deg, #f00, #ff0, #0f0, #0ff, #00f, #f0f, #f00); }
.chunk-hex { display: flex; align-items: center; gap: 8px; }
.chunk-swatch { width: 32px; height: 32px; border-radius: 4px; flex: none; border: 1px solid var(--line); }

.tag-suggest { position: fixed; z-index: 55; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); padding: 8px 10px 10px; }
.tag-suggest-head { display: flex; align-items: center; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.tag-suggest-head .close { width: 28px; height: 24px; display: flex; align-items: center; justify-content: center; }
.tag-suggest-list { display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
.tag-suggest-list::-webkit-scrollbar { display: none; }
.tag-chip { flex: none; display: grid; grid-template-columns: auto auto; align-items: center; column-gap: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); font-size: 15px; }
.tag-chip i { width: 8px; height: 8px; border-radius: 50%; }
.tag-chip small { grid-column: 1 / -1; font-size: 12px; color: var(--muted); text-align: left; }
.tag-suggest-empty { padding: 6px; color: var(--muted); font-size: 14px; }
.spinner { display: inline-block; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--text); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.import-dialog { max-height: calc(100vh - 32px); overflow-y: auto; }
.import-dialog h2 { font-size: 18px; }
.import-preview { display: flex; justify-content: center; padding: 8px; background: var(--input); border-radius: 6px; }
.import-preview img { max-height: 180px; max-width: 100%; border-radius: 4px; }
.import-uses { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 14px 0; }
.import-use { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 4px; background: var(--accent); color: var(--bg); font-weight: 700; }
.import-meta-head { white-space: pre-line; color: var(--text) !important; font-weight: 600; }
.import-meta { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; }
.import-checks { display: flex; flex-direction: column; gap: 6px; }
.import-check { display: flex; align-items: center; gap: 10px; text-align: left; font-size: 15px; }
.import-check.is-indented { margin-left: 18px; }
.import-check .box { width: 22px; height: 22px; border-radius: 3px; background: var(--input); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.import-check .box.is-on { background: var(--accent); color: var(--bg); }
.import-side { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; max-width: 150px; }
.import-go { flex: none; height: 38px; padding: 0 12px; }
.import-help { font-size: 12px !important; margin: 0 !important; }

/* ---------- M3: references, tools, Director Tools ---------- */
.generate.is-invalid .cost { color: var(--muted); }
.ref-card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.ref-head { display: flex; align-items: center; gap: 12px; padding: 12px; min-height: 64px; }
.ref-kind { width: 22px; height: 22px; }
.ref-title { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.ref-title small { color: var(--muted); font-size: 13px; }
.ref-actions { display: flex; gap: 6px; align-items: center; }
.ref-actions.push, .ref-btn.push { margin-left: auto; }
.ref-btn { height: 28px; min-width: 40px; padding: 0 10px; border-radius: 4px; background: var(--line); display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 14px; font-weight: 600; }
.ref-btn.wide { padding: 0 12px; }
.ref-thumb { width: 60px; height: 88px; object-fit: contain; border-radius: 4px; background: var(--input); align-self: flex-start; }
.ref-body { padding: 4px 12px 12px; border-top: 1px solid var(--line); }
.ref-slider { margin-top: 10px; }
.ref-slider .label { font-size: 15px; font-weight: 600; margin-bottom: 6px; }
.ref-slider .label .value { color: var(--muted); font-weight: 400; margin-left: 6px; }
.ref-section { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 12px; background: var(--panel); }
.ref-section-head { display: flex; align-items: center; gap: 10px; }
.ref-section-head .ic { width: 18px; height: 18px; }
.ref-count { color: var(--muted); }
.ref-sub { color: var(--muted); font-size: 13px; margin-top: 4px; margin-left: 28px; }
.ref-normalize { margin: 10px 0 4px; }
.ref-item { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); margin-top: 10px; }
.ref-item.is-disabled { opacity: 0.5; }
.ref-item-side { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.ref-item-thumb { width: 84px; height: 84px; border-radius: 6px; background: var(--input) center / contain no-repeat; }
.ref-item-thumb.tall { height: 154px; width: 100px; }
.ref-item-tools { display: flex; gap: 4px; }
.ref-item-tools .ref-btn { min-width: 36px; padding: 0 8px; }
.ref-item-main { flex: 1; min-width: 0; }
.ref-item-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ref-item-name { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-type { width: 100%; }
.ref-type span { display: inline-flex; align-items: center; gap: 8px; }
.ref-note { font-size: 13px; color: var(--muted); margin-top: 8px; }
.ref-note .ic { margin: 0 2px; }
.image-toolbar .tb:disabled { opacity: 0.4; }
.tool-panel { position: absolute; left: 12px; right: 12px; bottom: 54px; z-index: 8; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35); padding: 12px 14px 14px; }
.tool-panel-head { display: flex; align-items: center; gap: 8px; font: 700 18px/1.4 var(--serif); }
.tool-panel-head .close { margin-left: auto; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.tool-panel-body .label { margin: 10px 0 6px; font-weight: 600; }
.tool-segment { height: 36px; }
.tool-link { margin-top: 10px; color: var(--muted); font-weight: 600; }
.tool-note { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.tool-prompt { height: 64px; padding: 8px 12px; resize: none; }
.tool-level { display: flex; align-items: center; gap: 10px; }
.tool-level span { min-width: 100px; text-align: center; }
.director { position: absolute; inset: 0; z-index: 9; background: var(--bg); display: flex; flex-direction: column; padding: 8px 8px 0; }
.director-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; background: #0e0f21; border-radius: 6px; border: 1px solid var(--line); }
.director-image { max-width: 100%; max-height: 100%; object-fit: contain; }
.director-empty { color: var(--muted); }
.director-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; }
.director-row .group { display: flex; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; }
.director-row .group button { width: 40px; height: 36px; display: flex; align-items: center; justify-content: center; }
.director-options { background: var(--panel); border: 1px solid var(--line); border-radius: 8px 8px 0 0; }
.director-options-toggle { width: 100%; height: 26px; display: flex; align-items: center; justify-content: center; }
.director-options.is-open .director-options-toggle .ic { transform: rotate(180deg); }
.director-options-body { display: none; padding: 0 12px 12px; max-height: 40vh; overflow-y: auto; }
.director-options.is-open .director-options-body { display: block; }
.director-options-body .label { margin: 10px 0 6px; font-weight: 600; }
.director-tool-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px 8px; }
.director-tool { width: 44px; height: 40px; border-radius: 4px; background: var(--line); display: flex; align-items: center; justify-content: center; }
.director-tool-name { font-weight: 600; }
.pin-thumb { position: absolute; left: 12px; top: 60px; width: 56px; height: 56px; z-index: 6; border-radius: 6px; border: 2px solid var(--accent); background: var(--input) center / cover no-repeat; }

/* ---------- M4: canvas editor ---------- */
.ic-ed-pen { --i: url(../media/pen.svg); }
.ic-ed-eraser { --i: url(../media/eraser.svg); }
.ic-ed-select { --i: url(../media/select.svg); }
.ic-ed-dropper { --i: url(../media/dropper.svg); }
.ic-ed-trash { --i: url(../media/trash.svg); }
.ic-ed-resize { --i: url(../media/resize.svg); }
.ic-ed-undo { --i: url(../media/undo.svg); }
.ic-ed-redo { --i: url(../media/redo.svg); }
.ic-ed-dots { --i: url(../media/dotdotdot.svg); }
.ic-ed-download { --i: url(../media/detatch_down.svg); }
.ic-ed-close { --i: url(../media/cross.svg); }
.ic-ed-layers { --i: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M12%203%202%208l10%205%2010-5-10-5z%22/%3E%3Cpath%20d%3D%22m2%2013%2010%205%2010-5%22/%3E%3C/svg%3E"); }
.ic-ed-palette { --i: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Ccircle%20cx%3D%2213.5%22%20cy%3D%226.5%22%20r%3D%221%22/%3E%3Ccircle%20cx%3D%2217.5%22%20cy%3D%2210.5%22%20r%3D%221%22/%3E%3Ccircle%20cx%3D%228.5%22%20cy%3D%227.5%22%20r%3D%221%22/%3E%3Ccircle%20cx%3D%226.5%22%20cy%3D%2212.5%22%20r%3D%221%22/%3E%3Cpath%20d%3D%22M12%202a10%2010%200%200%200%200%2020c.9%200%201.7-.7%201.7-1.7%200-.4-.2-.8-.4-1.1-.3-.3-.4-.7-.4-1.1%200-.9.7-1.7%201.7-1.7H16a6%206%200%200%200%206-6C22%206%2017.5%202%2012%202z%22/%3E%3C/svg%3E"); }
.ic-ed-adjust { --i: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M4%2021v-7M4%2010V3M12%2021v-9M12%208V3M20%2021v-5M20%2012V3M1%2014h6M9%208h6M17%2016h6%22/%3E%3C/svg%3E"); }
.ic-ed-fill { --i: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22m19%2011-8-8-8.6%208.6a2%202%200%200%200%200%202.8l5.2%205.2c.8.8%202%20.8%202.8%200L19%2011z%22/%3E%3Cpath%20d%3D%22m5%202%205%205M2%2013h15M22%2020a2%202%200%201%201-4%200c0-1.6%201.7-2.4%202-4%20.3%201.6%202%202.4%202%204z%22/%3E%3C/svg%3E"); }
.ic-ed-lasso { --i: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M7%2022a5%205%200%200%201-2-4%22/%3E%3Cpath%20d%3D%22M3.3%2014A6.8%206.8%200%200%201%202%2010c0-4.4%204.5-8%2010-8s10%203.6%2010%208-4.5%208-10%208a12%2012%200%200%201-5-1%22/%3E%3Ccircle%20cx%3D%225%22%20cy%3D%2216%22%20r%3D%222%22/%3E%3C/svg%3E"); }
.ic-ed-blur { --i: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M12%202.7s-6%206.3-6%2011a6%206%200%200%200%2012%200c0-4.7-6-11-6-11z%22/%3E%3C/svg%3E"); }
.ic-ed-clone { --i: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M5%2022h14M19.3%2014.3A2.5%202.5%200%200%200%2017%2013H7a2.5%202.5%200%200%200-2.3%201.3L4%2018h16l-.7-3.7zM15%2013V9a3%203%200%201%200-6%200v4%22/%3E%3C/svg%3E"); }
.ic-ed-invert { --i: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Ccircle%20cx%3D%2212%22%20cy%3D%2212%22%20r%3D%229%22/%3E%3Cpath%20d%3D%22M12%203v18%22%20/%3E%3Cpath%20d%3D%22M12%203a9%209%200%200%201%200%2018z%22%20fill%3D%22black%22/%3E%3C/svg%3E"); }
.ic-ed-pressure { --i: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20stroke%3D%22black%22%20stroke-width%3D%222%22%20stroke-linecap%3D%22round%22%20stroke-linejoin%3D%22round%22%3E%3Cpath%20d%3D%22M3%2017c3-6%206-9%209-9s3%204%206%204%203-2%203-2%22/%3E%3C/svg%3E"); }

.ed-host { position: fixed; inset: 0; z-index: 80; background: #0e0f21; touch-action: none; user-select: none; -webkit-user-select: none; }
.ed-stage { position: absolute; inset: 0; overflow: hidden; touch-action: none;
  background-color: #0e0f21; }
.ed-view { position: absolute; left: 0; top: 0; transform-origin: 0 0; image-rendering: auto;
  background-image: linear-gradient(45deg, #a0a0a0 25%, transparent 25%, transparent 75%, #a0a0a0 75%), linear-gradient(45deg, #a0a0a0 25%, transparent 25%, transparent 75%, #a0a0a0 75%);
  background-color: #fff; background-size: 16px 16px; background-position: 0 0, 8px 8px; }
.ed-overlay { position: absolute; left: 0; top: 0; pointer-events: none; }
.ed { position: absolute; inset: 0; pointer-events: none; padding: var(--safe-area-inset-top, env(safe-area-inset-top)) 0 var(--safe-area-inset-bottom, env(safe-area-inset-bottom)); }
.ed > * { pointer-events: auto; }
.ed .ic { width: 16px; height: 16px; }
.ed-top { position: absolute; left: 10px; top: calc(10px + var(--safe-area-inset-top, env(safe-area-inset-top))); display: flex; flex-direction: column; gap: 10px; max-width: calc(100% - 20px); }
.ed-top-actions { display: flex; width: max-content; background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 1px; }
.ed-top-actions button { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: var(--bg); border: 1px solid var(--line); border-radius: 3px; }
.ed-top-actions .ed-save { width: auto; padding: 5px 12px; background: var(--accent); color: var(--panel); font-weight: 600; border: none; border-radius: 0; }
.ed-panel { display: flex; width: max-content; max-width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 3px; }
.ed-panel-head { width: 82px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 10px 6px; font-size: 14px; border-right: 1px solid var(--line); text-align: center; }
.ed-panel-body { display: flex; flex-direction: column; gap: 6px; padding: 8px 10px; width: 210px; }
.ed-panel-body[hidden] { display: none; }
.ed-panel:has(.ed-panel-body[hidden]) .ed-panel-head { border-right: none; }
.ed-slider-head { font-size: 14px; font-weight: 600; }
.ed-slider input[type=range] { width: 100%; height: 22px; padding: 0; }
.ed-slider input[type=range]::-webkit-slider-runnable-track { height: 12px; }
.ed-slider input[type=range]::-webkit-slider-thumb { height: 20px; margin-top: -4px; }
.ed-color-wrap { position: relative; }
.ed-swatch { width: 46px; height: 40px; border-radius: 3px; border: 1px solid var(--line); }
.ed-color-input { position: absolute; left: 0; top: 0; width: 46px; height: 40px; opacity: 0; pointer-events: none; }
.ed-shapes { display: flex; gap: 6px; }
.ed-shape { width: 34px; height: 34px; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.ed-shape.is-on { border-color: var(--accent); background: var(--line); }
.ed-shape::after { content: ''; width: 14px; height: 14px; background: #fff; }
.ed-shape-round::after { border-radius: 50%; }
.ed-shape-soft::after { border-radius: 50%; background: radial-gradient(#fff 20%, transparent 72%); }
.ed-pressure::after { display: none; }
.ed-hint { text-align: left; font-size: 13px; color: var(--muted); }
.ed-square { font-size: 14px; }
.ed-layers-button { position: absolute; right: 10px; bottom: calc(70px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom))); width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; gap: 2px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 3px; font-size: 12px; font-weight: 600; }
.ed-delete-sel { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(70px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom))); flex: none; padding: 0 16px; height: 36px; }
.ed-bar { position: absolute; left: 10px; right: 10px; bottom: calc(10px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom))); height: 50px; display: flex; align-items: center; gap: 0; padding: 3px; background: var(--panel); border: 1px solid var(--line); border-radius: 3px; }
.ed-bar button { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 3px; flex: none; }
.ed-bar button.is-on { background: var(--line); color: var(--accent); }
.ed-bar button:disabled { opacity: 0.35; }
.ed-flex { flex: 1; }
.ed-sep { width: 1px; height: 30px; background: var(--line); margin: 0 4px; }
.ed-pop { position: absolute; bottom: calc(68px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom))); left: 10px; z-index: 2; background: var(--panel); border: 1px solid var(--line); border-radius: 3px; padding: 10px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); max-width: calc(100% - 20px); }
.ed-tools-pop { display: flex; gap: 4px; flex-wrap: wrap; padding: 4px; }
.ed-tool { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; border-radius: 3px; }
.ed-tool.is-on { background: var(--line); color: var(--accent); }
.ed-palette { width: 270px; }
.ed-pop-label { font-size: 12px; margin: 4px 0 8px; }
.ed-pop-title { font: 700 16px/1.4 var(--serif); margin-bottom: 6px; }
.ed-colors { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.ed-color { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; }
.ed-color.is-on { border-color: var(--accent); }
.ed-patterns { display: flex; gap: 4px; flex-wrap: wrap; }
.ed-pattern { width: 32px; height: 32px; border-radius: 3px; border: 1px solid var(--line); background-color: var(--bg); }
.ed-pattern.is-on { border-color: var(--accent); background-color: var(--line); }
.ed-pattern-solid { background-image: linear-gradient(#fff, #fff); background-size: 14px 14px; background-repeat: no-repeat; background-position: center; }
.ed-pattern-diagonal { background-image: repeating-linear-gradient(45deg, #fff 0 2px, transparent 2px 6px); }
.ed-pattern-dense { background-image: repeating-linear-gradient(45deg, #fff 0 3px, transparent 3px 4px); }
.ed-pattern-dots { background-image: radial-gradient(#fff 1.5px, transparent 2px); background-size: 6px 6px; }
.ed-pattern-grid { background-image: linear-gradient(#fff 1px, transparent 1px), linear-gradient(90deg, #fff 1px, transparent 1px); background-size: 6px 6px; }
.ed-pattern-checker { background-image: conic-gradient(#fff 25%, transparent 0 50%, #fff 0 75%, transparent 0); background-size: 8px 8px; }
.ed-pattern-outline { box-shadow: inset 0 0 0 4px var(--bg), inset 0 0 0 6px #fff; }
.ed-layers { right: 10px; left: auto !important; bottom: calc(122px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom))); display: flex; flex-direction: column; gap: 8px; }
.ed-layer { display: flex; align-items: center; gap: 8px; }
.ed-layer-thumb { width: 52px; height: 72px; border-radius: 3px; border: 2px solid var(--line); background: #fff center / contain no-repeat; }
.ed-layer-eye { width: 32px; height: 28px; border-radius: 3px; background: var(--line); display: flex; align-items: center; justify-content: center; }
.ed-hsv { left: 10px; right: 10px; width: auto; }
.ed-modal-scrim { position: absolute; inset: 0; z-index: 5; background: rgba(0, 0, 0, 0.55); display: flex; align-items: flex-start; justify-content: center; padding-top: 20px; }
.ed-modal { width: calc(100% - 40px); max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; padding: 14px; }
.ed-modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.ed-modal-head .close { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.ed-edges { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.ed-edges .text-input { width: 80px; text-align: center; }
.ed-edges-mid { display: flex; align-items: center; gap: 8px; }
.ed-edges-preview { width: 82px; height: 118px; border: 1px solid #fff; background: var(--line); display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); }

/* ---------- screen width adaptation (added 1.2.20 round) ---------- */
/* Narrow phones (320-360 px): less padding, smaller fixed widths so nothing is pushed off screen. */
@media (max-width: 360px) {
  .topbar { padding-left: 6px; padding-right: 6px; }
  .anlas-balance { padding: 4px 8px; }
  .anlas-buy { padding: 4px 10px; }
  .image-toolbar .tb { padding: 0 8px; }
  .bottombar { gap: 6px; padding-left: 6px; padding-right: 6px; }
  .bottombar .icon-btn { width: 42px; }
  .view-grid { padding: 8px 12px; gap: 12px 10px; }
  .history-grid { gap: 6px; padding: 6px; }
  .panel-body { padding: 12px; }
  .seed-row input { width: 92px; padding: 0 8px; }
  .dropdown { min-width: 96px; }
  .ed-panel-body { width: 170px; }
  .ed-palette { width: min(270px, calc(100vw - 32px)); }
  .ed-modal { width: calc(100% - 24px); }
  .chunk-text { max-width: 180px; }
}
/* Large phones and small tablets: more columns in the history and a wider image grid margin. */
@media (min-width: 600px) {
  .history-grid { grid-template-columns: repeat(4, 1fr); }
  .view-grid { padding: 8px 48px; }
  .modal { max-width: 480px; }
}
@media (min-width: 900px) {
  .history-grid { grid-template-columns: repeat(5, 1fr); }
  .view-grid { padding: 8px 96px; }
}
/* Landscape phones: short screens keep room for the image. */
@media (max-height: 480px) {
  .prompt-field .nai-prompt-field { max-height: 30vh; }
  .character .prompt-field .nai-prompt-field { max-height: 24vh; }
  .drawer[data-state="full"] .prompt-field .nai-prompt-field { max-height: 40vh; }
  .panel-head { height: 44px; padding-top: 8px; padding-bottom: 8px; }
  .sheet { max-height: 70vh; }
  .import-dialog { max-height: calc(100vh - 16px); }
}
