/* Layout and components. Colours, fonts and sizes come from theme.css. */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
p { margin: 0; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: var(--space-4); top: -48px; z-index: var(--z-modal);
  background: var(--primary); color: var(--on-primary);
  padding: var(--space-2) var(--space-4); border-radius: var(--radius-sm); text-decoration: none;
}
.skip-link:focus { top: var(--space-4); }

.icon { width: 20px; height: 20px; flex: none; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 28px; height: 28px; }

.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  width: var(--sidebar-w); flex: none;
  display: flex; flex-direction: column;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  z-index: var(--z-sidebar);
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-5) var(--space-5) var(--space-4);
}
.brand {
  display: flex; align-items: center; gap: var(--space-3);
  color: var(--text); text-decoration: none;
  font-family: var(--font-display); font-size: 1.25rem; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap;
}
.brand-mark {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  background: var(--primary); color: var(--on-primary);
  display: grid; place-items: center;
}
.brand-mark .icon { width: 18px; height: 18px; }

.nav { flex: 1; overflow-y: auto; padding: var(--space-2) var(--space-3); }
.nav ul { list-style: none; margin: 0; padding: 0; }
.nav > ul > li + li { margin-top: var(--space-1); }
.nav-label {
  padding: var(--space-4) var(--space-3) var(--space-2);
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-subtle);
}
.nav-link {
  width: 100%; min-height: 44px;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 0; border-radius: var(--radius-sm); background: transparent;
  color: var(--text); text-decoration: none; text-align: left;
  font-size: var(--text-sm); font-weight: 500;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-link:hover { background: var(--sidebar-hover); }
.nav-link .icon { color: var(--text-muted); }
.nav-link.is-active { background: var(--surface); box-shadow: var(--shadow-sm); }
.nav-link.is-active .icon { color: var(--accent); }
.nav-link .chevron { margin-left: auto; transition: transform var(--dur) var(--ease); }
.nav-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.nav-sub { margin: var(--space-1) 0 0 22px !important; padding-left: var(--space-3) !important; border-left: 1px solid var(--border-strong); }
.nav-sublink {
  display: flex; align-items: center; gap: var(--space-3);
  min-height: 40px; padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  color: var(--text-muted); text-decoration: none; font-size: var(--text-sm);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-sublink:hover { background: var(--sidebar-hover); color: var(--text); }
.nav-sublink.is-active { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: var(--shadow-sm); }
.nav-sublink.is-active .icon { color: var(--accent); }

.sidebar-foot { padding: var(--space-3); border-top: 1px solid var(--border); }
.sidebar-note { padding: var(--space-2) var(--space-3); font-size: var(--text-xs); color: var(--text-subtle); }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.main { flex: 1; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--space-7) var(--space-6) var(--space-8); }
.main:focus { outline: none; }

.site-footer {
  width: 100%; max-width: var(--content-max); margin: 0 auto;
  padding: var(--space-4) var(--space-6) var(--space-5);
  border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-1) var(--space-5);
  font-size: var(--text-sm); color: var(--text-muted);
}
.site-footer ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0 var(--space-5); }
.site-footer a { display: inline-flex; align-items: center; min-height: 44px; color: var(--text-muted); }
.site-footer a:hover { color: var(--text); }
.site-footer p { min-width: 0; overflow-wrap: anywhere; }

.sidebar-scrim { position: fixed; inset: 0; background: rgba(31, 27, 22, 0.45); z-index: var(--z-scrim); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 44px; padding: 0 var(--space-5);
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: var(--text-sm); font-weight: 600; text-decoration: none; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-subtle); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft); color: var(--text); }
.btn-danger-solid { background: var(--danger); color: var(--on-primary); }
.btn-danger-solid:hover:not(:disabled) { filter: brightness(0.9); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 0 var(--space-3); font-size: var(--text-xs); }

.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: grid; place-items: center;
  border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text);
  transition: background var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--sidebar-hover); }
.sidebar .sidebar-close { display: none; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Page header ---------- */
.eyebrow { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.page-head { margin-bottom: var(--space-6); max-width: 720px; }
.page-head h1 { margin-top: var(--space-2); font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 600; letter-spacing: -0.015em; }
.page-head p { margin-top: var(--space-3); color: var(--text-muted); }

/* ---------- Home ---------- */
.hero { padding: var(--space-6) 0 var(--space-7); max-width: 760px; }
.hero h1 { margin-top: var(--space-3); font-family: var(--font-display); font-size: var(--text-3xl); font-weight: 600; letter-spacing: -0.02em; line-height: 1.08; }
.hero p { margin-top: var(--space-4); font-size: var(--text-lg); color: var(--text-muted); max-width: 60ch; }
.hero-actions { margin-top: var(--space-6); display: flex; flex-wrap: wrap; gap: var(--space-3); }

.section-title { font-size: var(--text-lg); font-weight: 600; margin-bottom: var(--space-4); }
.section + .section { margin-top: var(--space-7); }

.tool-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: var(--space-4); }
.tool-card {
  display: flex; flex-direction: column; gap: var(--space-3);
  padding: var(--space-5);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.tool-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-2px); }
.tool-card-icon { width: 44px; height: 44px; border-radius: var(--radius-sm); background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.tool-card h3 { font-size: var(--text-base); font-weight: 600; }
.tool-card p { font-size: var(--text-sm); color: var(--text-muted); flex: 1; }
.tool-card-cta { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--text-sm); font-weight: 600; color: var(--accent); }

.steps { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--space-4); counter-reset: step; }
.steps li { counter-increment: step; padding: var(--space-4) var(--space-5); border-left: 2px solid var(--border-strong); }
.steps li::before { content: "0" counter(step); display: block; font-family: var(--font-display); font-size: var(--text-xl); color: var(--accent); margin-bottom: var(--space-2); }
.steps strong { display: block; font-size: var(--text-sm); }
.steps span { font-size: var(--text-sm); color: var(--text-muted); }

.note {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-4); border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: var(--text-sm); color: var(--text-muted);
}
.note .icon { color: var(--accent); margin-top: 1px; }
.note + .note { margin-top: var(--space-3); }
noscript .note { margin-bottom: var(--space-5); }

.info-card h3 { font-size: var(--text-base); font-weight: 600; margin-bottom: var(--space-2); }
.info-card p { font-size: var(--text-sm); color: var(--text-muted); }
.info-card p + p { margin-top: var(--space-2); }

/* ---------- Text pages (terms, privacy, contact) ---------- */
.prose { max-width: 72ch; overflow-wrap: break-word; }
.prose h1 { margin-top: var(--space-2); font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 600; letter-spacing: -0.015em; }
.prose h2 { margin-top: var(--space-6); font-size: var(--text-lg); font-weight: 600; }
.prose h3 { margin-top: var(--space-5); font-size: var(--text-base); font-weight: 600; }
.prose p, .prose ul, .prose ol, .prose address, .prose .note { margin-top: var(--space-3); }
.prose ul, .prose ol { padding-left: var(--space-5); margin-bottom: 0; }
.prose li + li { margin-top: var(--space-2); }
.prose address { font-style: normal; }
.prose .lead { font-size: var(--text-lg); color: var(--text-muted); }
.prose .prose-meta { font-size: var(--text-sm); color: var(--text-muted); }
.prose .note p { margin-top: 0; }
.prose code { font-size: 0.9em; }

/* Page not found (404.html has no sidebar and no script) */
.error-page { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.error-page main { flex: 1; display: grid; justify-items: center; align-content: center; gap: var(--space-4); padding: var(--space-7) var(--space-4); text-align: center; }
.error-page h1 { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 600; }
.error-page p { color: var(--text-muted); max-width: 44ch; }

/* ---------- Tool workspace ---------- */
.workspace { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); gap: var(--space-5); align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.form-panel { position: sticky; top: var(--space-5); max-height: calc(100vh - 2 * var(--space-5)); overflow-y: auto; }
.form-section { padding: var(--space-5); }
.form-section + .form-section { border-top: 1px solid var(--border); }
.section-label { font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-subtle); margin-bottom: var(--space-4); }
.form-actions { position: sticky; bottom: 0; padding: var(--space-4) var(--space-5) var(--space-5); background: var(--surface); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.form-actions .hint { margin-top: var(--space-2); text-align: center; font-size: var(--text-xs); color: var(--text-subtle); }
.hint a, .variant.is-error a { color: inherit; font-weight: 600; }
.form-actions .btn + .btn { margin-top: var(--space-2); }

.field + .field { margin-top: var(--space-4); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.field-row .field + .field { margin-top: 0; }
.field-row + .field { margin-top: var(--space-4); }
.field-label { display: block; margin-bottom: var(--space-2); font-size: var(--text-sm); font-weight: 500; }
.field-label .req { color: var(--danger); margin-left: 2px; }
.field-help { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); }
.field-error { margin-top: var(--space-2); font-size: var(--text-xs); color: var(--danger); display: flex; gap: var(--space-1); align-items: center; }
.field.has-error .input, .field.has-error .dropzone { border-color: var(--danger); }
.counter { float: right; font-size: var(--text-xs); color: var(--text-subtle); font-weight: 400; }

.input {
  width: 100%; min-height: 44px; padding: var(--space-2) var(--space-3);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: var(--text-base);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.input:hover { border-color: var(--border-strong); }
.input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { min-height: 88px; resize: vertical; line-height: 1.5; }
select.input {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236B6255' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}

/* Toggle switch */
.toggle { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-height: 44px; cursor: pointer; }
.toggle-text { font-size: var(--text-sm); font-weight: 500; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track { position: relative; width: 40px; height: 24px; flex: none; border-radius: 999px; background: var(--border-strong); transition: background var(--dur) var(--ease); }
.toggle-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-sm); transition: transform var(--dur) var(--ease); }
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle input:checked + .toggle-track::after { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-group .field + .field { margin-top: 0; }

/* Dropzone */
.dropzone {
  position: relative; display: grid; place-items: center; text-align: center;
  min-height: 150px; padding: var(--space-5);
  background: var(--surface-2); border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  color: var(--text-muted); cursor: pointer;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.dropzone:hover, .dropzone.is-dragover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .icon { margin: 0 auto var(--space-2); color: var(--accent); }
.dropzone strong { display: block; color: var(--text); font-size: var(--text-sm); }
.dropzone small { font-size: var(--text-xs); }
.dropzone.has-image { padding: 0; min-height: 0; border-style: solid; overflow: hidden; background: var(--surface-2); }
.dropzone.has-image img { width: 100%; max-height: 260px; object-fit: contain; }
.thumb-remove {
  position: absolute; top: var(--space-2); right: var(--space-2);
  width: 32px; height: 32px; border-radius: 50%; border: 0;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, 0.92); color: var(--text); box-shadow: var(--shadow-sm);
}
.thumb-remove:hover { background: var(--surface); color: var(--danger); }
.thumb-remove::before { content: ""; position: absolute; inset: -6px; } /* larger hit area */

.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); }
.thumb { position: relative; aspect-ratio: 1; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .thumb-remove { top: 4px; right: 4px; width: 28px; height: 28px; }
.thumb-add {
  aspect-ratio: 1; display: grid; place-items: center; align-content: center; gap: var(--space-1);
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2);
  color: var(--text-muted); font-size: var(--text-xs);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.thumb-add:hover { border-color: var(--accent); background: var(--accent-soft); }

/* Compact file row (used when a mask editor shows the image large) */
.file-chip { position: relative; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2); padding-right: 48px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-size: var(--text-sm); }
.file-chip img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }
.file-chip span { flex: 1; color: var(--text-muted); }
.file-chip .thumb-remove { top: 50%; transform: translateY(-50%); }

/* Mask editor */
.mask-editor { display: flex; flex-direction: column; gap: var(--space-2); }
.mask-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }
.mask-toolbar .spacer { flex: 1; }
.mask-modes { display: flex; gap: var(--space-1); }
.mask-modes .btn[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.mask-size-label { display: flex; align-items: center; gap: var(--space-2); margin-left: auto; font-size: var(--text-xs); color: var(--text-muted); }
.mask-size { width: 110px; accent-color: var(--accent); }
.mask-stage { display: grid; place-items: center; min-height: 140px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.mask-canvas { display: block; cursor: none; touch-action: none; }
.mask-empty { display: grid; justify-items: center; gap: var(--space-2); padding: var(--space-5); text-align: center; font-size: var(--text-sm); color: var(--text-muted); }
.mask-empty .icon { color: var(--border-strong); }
.mask-editor.is-disabled .mask-toolbar { opacity: 0.5; pointer-events: none; }
.modal.mask-modal { width: min(1100px, 100%); max-width: none; padding: var(--space-5); }
.mask-modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.mask-modal-head h2 { font-size: var(--text-lg); }
.mask-modal .btn { margin-top: 0; }

/* ---------- Output ---------- */
.output-panel { padding: var(--space-5); min-width: 0; }
.stage { min-height: 420px; display: flex; flex-direction: column; }
.empty-state { flex: 1; display: grid; place-items: center; text-align: center; padding: var(--space-7) var(--space-5); border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--border); color: var(--text-muted); }
.empty-state .icon-lg { margin: 0 auto var(--space-3); color: var(--border-strong); width: 40px; height: 40px; }
.empty-state strong { display: block; color: var(--text); margin-bottom: var(--space-1); }
.empty-state p { font-size: var(--text-sm); max-width: 38ch; }

.viewer { position: relative; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.viewer > img { width: 100%; max-height: 72vh; object-fit: contain; }

.compare { position: relative; width: 100%; max-height: 72vh; margin: 0 auto; user-select: none; }
.compare img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.compare .compare-before { position: absolute; inset: 0; }
.compare-line { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--surface); box-shadow: 0 0 0 1px rgba(31, 27, 22, 0.25); pointer-events: none; }
.compare-range { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: ew-resize; }
.compare-tag { position: absolute; top: var(--space-3); padding: 2px var(--space-2); border-radius: 999px; background: rgba(255, 255, 255, 0.9); font-size: var(--text-xs); font-weight: 600; pointer-events: none; }
.compare-tag.before { left: var(--space-3); }
.compare-tag.after { right: var(--space-3); }

.viewer-bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-top: var(--space-3); }
.viewer-bar .spacer { flex: 1; }
.viewer-note { margin-top: var(--space-3); align-items: center; }
.send-to { position: relative; }
.menu {
  position: absolute; right: 0; bottom: calc(100% + 6px); min-width: 220px; z-index: 10;
  padding: var(--space-1); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: var(--shadow-lg);
}
.menu button { width: 100%; min-height: 40px; display: flex; align-items: center; gap: var(--space-2); padding: 0 var(--space-3); border: 0; border-radius: 6px; background: transparent; text-align: left; font-size: var(--text-sm); }
.menu button:hover { background: var(--surface-2); }

.model-note { margin-top: var(--space-3); font-size: var(--text-sm); color: var(--text-muted); }
details.prompt-used { margin-top: var(--space-3); font-size: var(--text-sm); }
details.prompt-used summary { cursor: pointer; color: var(--text-muted); min-height: 32px; display: flex; align-items: center; }
details.prompt-used pre { margin: var(--space-2) 0 0; padding: var(--space-3); white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: var(--text-xs); color: var(--text-muted); }

.variants { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.variant { position: relative; aspect-ratio: 4 / 3; border-radius: var(--radius-sm); overflow: hidden; border: 2px solid transparent; background: var(--surface-2); padding: 0; }
.variant img { width: 100%; height: 100%; object-fit: cover; }
.variant.is-selected { border-color: var(--accent); }
.variant.is-loading { display: grid; place-items: center; align-content: center; gap: var(--space-2); color: var(--text-muted); font-size: var(--text-xs); cursor: default; border: 1px solid var(--border); background: linear-gradient(100deg, var(--surface-2) 30%, var(--accent-soft) 50%, var(--surface-2) 70%); background-size: 300% 100%; animation: shimmer 1.6s ease-in-out infinite; }
.variant.is-error { display: grid; place-items: center; align-content: center; gap: var(--space-1); padding: var(--space-3); text-align: center; background: var(--danger-soft); color: var(--danger); font-size: var(--text-xs); cursor: default; border: 1px solid transparent; }
.variant.is-error .btn { margin-top: var(--space-1); }
/* An error can be several sentences (what happened, what became of the credits, what to do):
   the box grows with the text instead of cutting it off. */
.variant.is-error { aspect-ratio: auto; min-height: 105px; overflow: visible; overflow-wrap: anywhere; }
.variant-lg.is-error { min-height: 180px; padding: var(--space-5); }
.variant-lg { width: 100%; aspect-ratio: 16 / 10; font-size: var(--text-sm); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
.elapsed { font-variant-numeric: tabular-nums; }

.history { margin-top: var(--space-6); padding-top: var(--space-5); border-top: 1px solid var(--border); }
.history-strip { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: var(--space-2); }
.history-strip button { flex: none; width: 88px; height: 66px; padding: 0; border-radius: 6px; overflow: hidden; border: 2px solid transparent; background: var(--surface-2); }
.history-strip button.is-selected { border-color: var(--accent); }
.history-strip img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Feedback ---------- */
.alert { display: flex; gap: var(--space-3); padding: var(--space-4); border-radius: var(--radius); background: var(--danger-soft); color: var(--danger); font-size: var(--text-sm); }
.toasts { position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--space-2); max-width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; gap: var(--space-2); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-lg); font-size: var(--text-sm); animation: toast-in 220ms var(--ease); }
.toast.is-error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Sign-in modal ---------- */
/* A dialog never grows taller than the screen (phone in landscape, on-screen keyboard):
   it scrolls inside instead, so its buttons can always be reached. */
.modal-backdrop { position: fixed; inset: 0; z-index: var(--z-modal); display: grid; place-items: center; padding: var(--space-4); overflow-y: auto; background: rgba(247, 243, 236, 0.86); backdrop-filter: blur(6px); }
.modal {
  width: 100%; max-width: 380px; padding: var(--space-6);
  max-height: calc(100vh - 2 * var(--space-4)); max-height: calc(100dvh - 2 * var(--space-4)); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: toast-in 240ms var(--ease);
}
.modal:focus { outline: none; }
.modal-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-5); }
.modal .modal-actions .btn { margin-top: 0; }
.modal.modal-wide { max-width: 460px; }
.modal ul { margin: 0 0 var(--space-4); padding-left: var(--space-5); font-size: var(--text-sm); color: var(--text-muted); }
.check { display: flex; align-items: flex-start; gap: var(--space-2); margin-top: var(--space-3); font-size: var(--text-sm); color: var(--text-muted); cursor: pointer; }
.check input { flex: none; width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--primary); }
.modal .brand-mark { margin-bottom: var(--space-4); }
.modal h2 { font-family: var(--font-display); font-size: var(--text-xl); font-weight: 600; }
.modal p { margin: var(--space-2) 0 var(--space-5); color: var(--text-muted); font-size: var(--text-sm); }
.modal .btn { margin-top: var(--space-4); }
.password-wrap { position: relative; }
.password-wrap .input { padding-right: 48px; }
.password-wrap .icon-btn { position: absolute; right: 0; top: 0; color: var(--text-muted); }
.password-wrap .icon-btn:hover { background: transparent; color: var(--text); }

/* ---------- Accounts ---------- */
.credit-pill {
  display: flex; align-items: center; gap: var(--space-2); margin: 0 0 var(--space-2); padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm); background: var(--surface); box-shadow: var(--shadow-sm);
  color: var(--text); text-decoration: none; font-size: var(--text-sm);
}
.credit-pill .icon { color: var(--accent); }
.credit-pill strong { font-variant-numeric: tabular-nums; }
.credit-pill:hover { box-shadow: var(--shadow); }
.sidebar-user { padding: 0 var(--space-3) var(--space-1); font-size: var(--text-xs); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .btn-block + .nav-link { margin-top: var(--space-1); }

.verify-banner {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  margin-bottom: var(--space-5); padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--accent-soft);
  font-size: var(--text-sm);
}
.verify-banner > .icon { color: var(--accent); }
.verify-banner p { flex: 1; min-width: 220px; }
.verify-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.modal { position: relative; }
.modal-close { position: absolute; top: var(--space-3); right: var(--space-3); display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-sm); color: var(--text-muted); }
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.auth-modal .input { margin-bottom: var(--space-3); }
.auth-modal .password-wrap .input { margin-bottom: 0; }
.auth-modal .password-wrap { margin-bottom: var(--space-2); }
.auth-row { display: flex; justify-content: space-between; align-items: baseline; }
.auth-link { font-size: var(--text-xs); }
.auth-switch { margin: var(--space-4) 0 0 !important; text-align: center; }
.hint.is-warning { color: var(--danger); }

.muted { color: var(--text-muted); font-size: var(--text-sm); }
.badge { display: inline-block; margin-left: var(--space-1); padding: 1px var(--space-2); border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: var(--text-xs); color: var(--text-muted); }
.badge-ok { background: var(--success-soft); border-color: transparent; color: var(--success); }
.badge-warn { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.badge-bad { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-danger { color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }

/* History */
.page-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); flex-wrap: wrap; margin-bottom: var(--space-4); }
.page-toolbar .input { width: auto; min-width: 220px; }
.page-toolbar .section-label { margin: 0; }
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-4); }
.history-card {
  display: flex; flex-direction: column; padding: 0; overflow: hidden; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  transition: box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.history-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.history-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--surface-2); }
.history-card .thumb-missing { display: grid; place-items: center; width: 100%; aspect-ratio: 4 / 3; background: var(--surface-2); color: var(--border-strong); }
.history-card.is-loading { aspect-ratio: 4 / 3.8; background: linear-gradient(100deg, var(--surface-2) 30%, var(--accent-soft) 50%, var(--surface-2) 70%); background-size: 300% 100%; animation: shimmer 1.6s ease-in-out infinite; }
.history-meta { display: flex; flex-direction: column; padding: var(--space-3); font-size: var(--text-sm); }
.history-meta span { color: var(--text-muted); font-size: var(--text-xs); }
.history-empty { grid-column: 1 / -1; }
.load-more { display: flex; justify-content: center; margin-top: var(--space-5); }

.modal.lightbox-panel { width: min(1200px, 100%); max-width: none; max-height: calc(100dvh - 32px); overflow: auto; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr) 320px; }
.lightbox-image { display: grid; place-items: center; background: var(--surface-2); min-height: 300px; }
.lightbox-image img { max-height: calc(100dvh - 40px); width: 100%; object-fit: contain; }
.lightbox-info { padding: var(--space-6) var(--space-5) var(--space-5); display: flex; flex-direction: column; gap: var(--space-2); }
.lightbox-info h2 { font-size: var(--text-xl); }
.lightbox-info .section-label { margin: var(--space-3) 0 0; }
.lightbox-actions, .lightbox-send { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.lightbox-panel .btn { margin-top: 0; }

/* Account & admin */
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--space-4); align-items: start; }
.card { padding: var(--space-5); }
.card-wide { grid-column: 1 / -1; }
.card-actions { margin-top: var(--space-4); }
.balance { font-size: var(--text-lg); margin-bottom: var(--space-2); }
.balance strong { font-family: var(--font-display); font-size: 2.5rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.card .muted + .btn { margin-top: var(--space-4); }
.card .muted + .muted { margin-top: var(--space-2); }
.link-btn { padding: 0; border: 0; background: none; color: var(--accent); text-decoration: underline; font-size: inherit; }

/* Delete account */
.panel.danger-zone { border-color: var(--danger); }
.danger-zone .section-label { color: var(--danger); }
.danger-zone h3 { font-size: var(--text-sm); font-weight: 600; margin-top: var(--space-4); }
.danger-zone ul { margin: var(--space-2) 0 0; padding-left: var(--space-5); font-size: var(--text-sm); color: var(--text-muted); }
.danger-zone li + li { margin-top: var(--space-1); }
.danger-zone .btn { margin-top: var(--space-5); border-color: var(--danger); }

/* Admin system check */
.check-summary { margin-bottom: var(--space-4); }
.check-list { list-style: none; margin: 0; padding: 0; }
.check-list li { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-2) 0; font-size: var(--text-sm); overflow-wrap: anywhere; }
.check-list li + li { border-top: 1px solid var(--border); }
.check-list .badge { flex: none; min-width: 44px; margin: 1px 0 0; text-align: center; }
.check-details { margin-top: var(--space-4); font-size: var(--text-sm); }
.check-details summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; color: var(--text-muted); }
.check-details h3 { font-size: var(--text-sm); font-weight: 600; margin: var(--space-4) 0 var(--space-2); }
.details { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); margin: 0; font-size: var(--text-sm); }
.details dt { color: var(--text-muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th { text-align: left; font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-subtle); padding: var(--space-2) var(--space-3); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: var(--space-3); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .pos { color: var(--success); }
.table .neg { color: var(--text-muted); }
.cell-email { overflow-wrap: anywhere; }
.row-actions { display: flex; gap: var(--space-1); justify-content: flex-end; flex-wrap: wrap; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.stat { padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-1); }
.stat span { font-size: var(--text-xs); color: var(--text-muted); }
.stat strong { font-family: var(--font-display); font-size: var(--text-2xl); font-weight: 600; font-variant-numeric: tabular-nums; }
.pager { display: flex; gap: var(--space-2); justify-content: flex-end; margin-top: var(--space-3); }
.pager:empty { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .form-panel { position: static; max-height: none; overflow: visible; }
}

@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform 240ms var(--ease); box-shadow: var(--shadow-lg); }
  .sidebar.is-open { transform: none; }
  .sidebar .sidebar-close { display: grid; }
  .topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: rgba(247, 243, 236, 0.94); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
  }
  .topbar-title { font-family: var(--font-display); font-weight: 600; }
  .main { padding: var(--space-5) var(--space-4) var(--space-7); }
  .site-footer { padding: var(--space-3) var(--space-4) var(--space-4); }
  .hero { padding-top: var(--space-2); }
  .field-row { grid-template-columns: 1fr; }
  .field-row .field + .field { margin-top: var(--space-4); }
  .output-panel { padding: var(--space-4); }
  .stage { min-height: 280px; }
  .toasts { left: var(--space-4); right: var(--space-4); bottom: var(--space-4); max-width: none; }
  .modal.lightbox-panel { grid-template-columns: 1fr; }
  .lightbox-image img { max-height: 60dvh; }
  .page-toolbar .input { width: 100%; }
  .check-details .details { grid-template-columns: 1fr; gap: 0; }
  .check-details .details dd { margin-bottom: var(--space-2); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
