/* ---------------------------------------------------------------- *
 * Inkmagik — theme tokens
 * ---------------------------------------------------------------- */
:root {
  --bg: #0e0f13;
  --bg-elev-1: #15161d;
  --bg-elev-2: #1c1e27;
  --border: #2b2d38;
  --text: #eef0f6;
  --text-dim: #9497a8;
  --text-faint: #6a6d7d;
  --accent: #7c5cff;
  --accent-grad: linear-gradient(135deg, #7c5cff 0%, #34d9c8 100%);
  --danger: #ff5c72;
  /* Status colours (reserved — never used as a data hue). Both checked for
     WCAG AA on the panel surfaces: teal 9.4:1, danger 5.6:1. */
  --good: #34d9c8;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-soft: 0 8px 30px rgba(0, 0, 0, 0.35);
  --panel-w: 272px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h2, h3 { margin: 0; font-weight: 600; letter-spacing: 0.01em; }
h3 { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }
p { margin: 0; }

button { font-family: inherit; }

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.topbar {
  height: 56px;
  min-height: 56px;
  /* Three columns so the centre tool group is centred on the bar itself,
     not just in the space left over by the brand and account pill. */
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: var(--bg-elev-1);
  border-bottom: 1px solid var(--border);
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar-center {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  width: 20px;
  height: 20px;
  border-radius: 7px;
  background: url("../img/branding/inkmagik-logo.png") center / cover no-repeat;
  box-shadow: 0 0 16px rgba(124, 92, 255, 0.55);
}

.brand-name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-self: end;
  gap: 6px;
  min-width: 0;
}

.icon-btn {
  position: relative; /* anchors the "new" dot */
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

/* "Something new here" dot. The button's title/aria-label says so too, so the
   meaning never rests on the colour alone. The ring keeps it legible wherever
   it lands on the icon beneath. */
.icon-btn.has-new::after {
  content: '';
  position: absolute;
  top: 4px;
  right: 4px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 2px var(--bg-elev-2);
  pointer-events: none;
}
.icon-btn:hover { background: #262835; border-color: #383b4a; }
.icon-btn:active { transform: scale(0.94); }
.icon-btn.active {
  background: rgba(124, 92, 255, 0.16);
  border-color: var(--accent);
  color: var(--accent);
}

.only-mobile { display: none; }

.icon-btn[hidden] { display: none; }

/* ---- account pill (Google sign-in) ---- */
.account { position: relative; }
.account-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 12px 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  max-width: 200px;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.account-btn:hover { background: #262835; border-color: #383b4a; }
.account-btn:active { transform: scale(0.96); }
.account-btn svg {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.account-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  z-index: 30;
}
.account-menu[hidden] { display: none; }
.account-email {
  font-size: 12.5px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account-tokens {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
}
.account-tokens-value {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.account-signout {
  height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.account-signout:hover { background: #262835; border-color: #383b4a; }

.account-buy {
  height: 34px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-grad);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s ease, filter 0.15s ease;
}
.account-buy:hover { filter: brightness(1.08); }
.account-buy:active { transform: scale(0.97); }

/* ---------------------------------------------------------------- *
 * Buy tokens
 * ---------------------------------------------------------------- */
.buy-card { width: min(560px, 100%); }

.buy-body {
  padding: 18px 22px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.buy-note {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
}
.buy-note b { color: var(--text); }

.buy-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.buy-pack {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 18px 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.1s ease, background 0.15s ease;
}
.buy-pack:hover { border-color: var(--accent); background: #232532; }
.buy-pack:active { transform: scale(0.98); }
.buy-pack:disabled { opacity: 0.5; cursor: default; }
.buy-pack.best { border-color: var(--accent); }

.buy-pack-tokens {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.buy-pack-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}
.buy-pack-price {
  margin-top: 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
}
.buy-pack-badge {
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent-grad);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}

.buy-msg {
  margin: 0;
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
}
.buy-msg[hidden] { display: none; }

.buy-secure {
  margin: 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-faint);
  text-align: center;
}

/* ---- gift code redemption ---- */
.redeem {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.redeem-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
}
.redeem-row { display: flex; gap: 8px; }
.redeem-input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.redeem-input::placeholder {
  color: var(--text-faint);
  letter-spacing: 0.06em;
  text-transform: none;
}
.redeem-input:focus {
  outline: none;
  border-color: var(--accent);
}
.redeem-btn {
  height: 38px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.redeem-btn:hover { background: #262835; border-color: #383b4a; }
.redeem-btn:disabled { opacity: 0.5; cursor: default; }
.redeem-msg {
  margin: 0;
  font-size: 12.5px;
  color: var(--danger);
}
.redeem-msg.ok { color: var(--accent-2, #34d9c8); }
.redeem-msg[hidden] { display: none; }

/* ---------------------------------------------------------------- *
 * Analytics dashboard (admin)
 *
 * Every chart here is one series measuring magnitude, so they all use the
 * single accent hue — a colour per category would imply an identity that
 * isn't there. Single series also means no legend; the value rides the tip
 * of each mark. Text always wears text tokens, never the data colour.
 * ---------------------------------------------------------------- */
.admin-card { width: min(880px, 100%); }

.admin-body {
  padding: 18px 22px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.admin-msg {
  margin: 0;
  padding: 32px 0;
  text-align: center;
  font-size: 13.5px;
  color: var(--text-faint);
}
.admin-msg[hidden] { display: none; }

.admin-content {
  display: flex;
  flex-direction: column;
  gap: 24px;
}
.admin-content[hidden] { display: none; }

/* ---- KPI tiles ---- */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 10px;
}
.kpi {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
}
.kpi-label {
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kpi-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  /* Proportional figures on purpose: tabular-nums makes a standalone number
     look loose at display sizes. Tabular is for columns that must align. */
}
.kpi-sub {
  font-size: 11px;
  color: var(--text-faint);
}

/* Status colours, reserved for the delta only — never reused as a data hue.
   The arrow (▲/▼) carries the direction too, so meaning never rests on colour
   alone (colourblindness, greyscale printing, forced-colors). */
.kpi-delta {
  margin-top: 3px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.kpi-delta.good { color: var(--good); }
.kpi-delta.bad { color: var(--danger); }
.kpi-delta.neutral { color: var(--text-dim); }
/* The period stays muted: it's a label, not a status. */
.kpi-delta-vs {
  font-weight: 500;
  color: var(--text-faint);
}

/* ---- chart blocks ---- */
.chart-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.chart-empty {
  margin: 0;
  padding: 12px 0;
  font-size: 12.5px;
  color: var(--text-faint);
}

/* ---- horizontal bars ---- */
.bars {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bar-row {
  display: grid;
  grid-template-columns: 104px 1fr 52px;
  align-items: center;
  gap: 10px;
}
.bar-label {
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-track {
  height: 18px; /* under the 24px cap; the slot keeps its air */
  background: var(--bg-elev-2);
  border-radius: 3px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--accent);
  /* Square at the baseline, 4px rounded at the data end. */
  border-radius: 0 4px 4px 0;
  transition: width 0.4s ease;
}
.bar-value {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
  font-variant-numeric: tabular-nums; /* a column of numbers — align them */
}

/* ---- columns (14-day series) ---- */
.cols {
  display: flex;
  align-items: flex-end;
  gap: 2px; /* the 2px surface gap that separates touching marks */
  height: 96px;
  padding-top: 4px;
}
.col {
  flex: 1;
  height: 100%;
  display: flex;
  align-items: flex-end;
}
.col-fill {
  width: 100%;
  background: var(--accent);
  border-radius: 4px 4px 0 0; /* rounded data-end, square at the baseline */
  min-height: 2px;
  transition: height 0.4s ease;
}
.col-fill.empty { background: var(--border); }

.cols-axis {
  display: flex;
  gap: 2px;
  border-top: 1px solid var(--border); /* hairline, solid, recessive */
  padding-top: 6px;
}
.cols-axis .col-tick {
  flex: 1;
  font-size: 10.5px;
  color: var(--text-faint);
  text-align: center;
  white-space: nowrap;
}
.cols-axis .col-tick:first-child { text-align: left; }
.cols-axis .col-tick:last-child { text-align: right; }

/* ---- small tables (lists, not magnitudes) ---- */
.mini-table {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.mini-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
}
.mini-row:last-child { border-bottom: none; }
.mini-cell {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mini-cell.first {
  flex: 0 0 auto;
  color: var(--text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.mini-cell.tag {
  flex: 0 0 auto;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.mini-cell.tag.good {
  background: rgba(52, 217, 200, 0.14);
  color: var(--good);
}
.mini-cell.tag.muted {
  background: var(--bg-elev-2);
  color: var(--text-faint);
}

/* ---- health stats ---- */
.health-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.health {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
}
.health-label { font-size: 11.5px; color: var(--text-faint); }
.health-value { font-size: 17px; font-weight: 700; color: var(--text); }
.health-value.good { color: var(--good); }
.health-value.bad { color: var(--danger); }
.health-value.neutral { color: var(--text); }
.health-sub { font-size: 10.5px; color: var(--text-faint); }

.admin-foot {
  margin: 0;
  font-size: 11px;
  color: var(--text-faint);
  text-align: right;
}

/* ---------------------------------------------------------------- *
 * Toast
 * ---------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  z-index: 1200;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev-1);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
.toast[hidden] { display: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
/* Fullscreen toggle: show the "enter" icon by default, "exit" when active. */
#fullscreenBtn .fs-exit { display: none; }
#fullscreenBtn.is-fullscreen .fs-enter { display: none; }
#fullscreenBtn.is-fullscreen .fs-exit { display: block; }

/* ---------------------------------------------------------------- *
 * Workspace layout
 * ---------------------------------------------------------------- */
.workspace {
  flex: 1;
  position: relative; /* positioning context for the page tabs */
  display: grid;
  grid-template-columns: var(--panel-w) 1fr var(--panel-w);
  min-height: 0;
}

.panel {
  background: var(--bg-elev-1);
  border-right: 1px solid var(--border);
  overflow: hidden;
  min-height: 0;
}
.panel-right {
  border-right: none;
  border-left: 1px solid var(--border);
}

.panel-scroll {
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hint {
  font-size: 12.5px;
  color: var(--text-faint);
  line-height: 1.4;
}

.value-pill {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  padding: 2px 9px;
  border-radius: 999px;
}

/* ---------------------------------------------------------------- *
 * Page tabs — bookmark-style, down the right edge of the canvas
 * ---------------------------------------------------------------- */
.page-tabs {
  position: absolute;
  /* Anchored to the workspace grid at the right panel's left edge, so the
     tabs stay glued to the panel boundary regardless of canvas zoom/scroll. */
  right: var(--panel-w);
  top: 50%;
  display: flex;
  flex-direction: column;
  gap: 7px;
  z-index: 10;
}

.page-tab {
  position: relative;
  overflow: hidden;
  width: 32px;
  height: 44px;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 12px 0 0 12px;
  background: var(--bg-elev-1);
  color: var(--text-dim);
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: -3px 0 10px rgba(0, 0, 0, 0.18);
  transition: width 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.page-tab:hover { width: 38px; color: var(--text); }
.page-tab.active {
  width: 40px;
  background: var(--accent-grad);
  color: #fff;
  border-color: transparent;
}
/* While the page's strokes redraw, keep the tab dark and let the accent
   gradient rise from the bottom (height driven by --load, 0..1) as a real
   progress indicator. Placed after .active so it wins during loading. */
.page-tab.loading {
  background: var(--bg-elev-1);
  color: #fff;
  border-color: transparent;
}
.page-tab.loading::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--load, 0) * 100%);
  background: var(--accent-grad);
  transition: height 0.12s linear;
  pointer-events: none;
}
/* Keep the digit crisp wherever the rising fill sits behind it — the gradient's
   light teal end would otherwise wash out the white number. The digit sits
   above the ::before fill; the dark shadow reads on both the tab and the fill. */
.page-tab.active,
.page-tab.loading { text-shadow: 0 1px 2px rgba(0, 0, 0, 0.6); }

/* ---------------------------------------------------------------- *
 * Brush grid
 * ---------------------------------------------------------------- */
.brush-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.brush-btn {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s ease;
  position: relative;
}
.brush-btn svg {
  width: 27px;
  height: 27px;
  transition: transform 0.15s ease;
}

/* Live stroke preview — the actual brush engine paints this swatch. */
.brush-preview {
  width: 100%;
  height: 46px;
  margin-top: 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  transition: opacity 0.15s ease;
}
.brush-preview.erasing { opacity: 0.3; }
.brush-btn:hover svg { transform: scale(1.12) rotate(-3deg); }
.brush-btn.active svg { transform: scale(1.08); }
.brush-btn:hover { border-color: #3a3d4d; color: var(--text); }
.brush-btn.active {
  background: rgba(124, 92, 255, 0.16);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

/* ---------------------------------------------------------------- *
 * Layers — three stacked sheets, front (top) to back (bottom)
 * ---------------------------------------------------------------- */
.layers-hint { margin: 0 0 8px; }
.layer-list { display: flex; flex-direction: column; gap: 6px; }
.layer-row { display: flex; align-items: stretch; gap: 6px; }
.layer-btn {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text-dim);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}
/* Per-layer clear button (turns red on hover, disabled when the layer is empty). */
.layer-clear {
  flex-shrink: 0;
  width: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}
.layer-clear svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.layer-clear:hover:not(:disabled) {
  border-color: #e5484d;
  color: #e5484d;
  background: rgba(229, 72, 77, 0.12);
}
.layer-clear:disabled { opacity: 0.3; cursor: not-allowed; }
.layer-btn:hover { border-color: #3a3d4d; color: var(--text); }
.layer-btn.active {
  background: rgba(124, 92, 255, 0.16);
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 0 1px var(--accent) inset;
}
/* Live preview of what's on this layer (painted by app.js on white paper). */
.layer-thumb {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  display: block;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
}
.layer-name { flex: 1; font-size: 13.5px; font-weight: 600; }
.layer-empty { font-size: 11px; color: var(--text-dim); font-style: italic; }

/* ---------------------------------------------------------------- *
 * Inline help hint (the "?" next to a title, with a hover/focus tooltip)
 * ---------------------------------------------------------------- */
.title-with-help { display: flex; align-items: center; gap: 6px; }
.title-with-help h3 { margin: 0; }
.help-hint {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 700;
  cursor: help;
  user-select: none;
}
.help-hint:hover,
.help-hint:focus { color: var(--text); border-color: var(--accent); outline: none; }
.help-tip {
  position: fixed; /* escapes the panel's scroll clipping — JS sets top/left */
  z-index: 200;
  width: max-content;
  max-width: 220px;
  background: #191b24;
  color: rgba(255, 255, 255, 0.9);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  letter-spacing: 0;
  text-transform: none;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.5);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-2px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  pointer-events: none;
}
.help-tip b { font-weight: 700; color: #fff; }
.help-hint.help-open .help-tip { opacity: 1; visibility: visible; transform: none; }

/* ---------------------------------------------------------------- *
 * Onboarding tour (one-time coach marks for Layers)
 * ---------------------------------------------------------------- */
#tour { position: fixed; inset: 0; z-index: 99990; }
#tour .tour-block { position: fixed; inset: 0; z-index: 99996; } /* blocks clicks */
.tour-hole {
  position: fixed;
  z-index: 99998;
  border-radius: 12px;
  pointer-events: none;
  box-shadow:
    0 0 0 9999px rgba(8, 9, 13, 0.62),
    0 0 0 2px rgba(124, 92, 255, 0.9),
    0 0 26px 4px rgba(124, 92, 255, 0.45);
  transition: left 0.25s ease, top 0.25s ease, width 0.25s ease, height 0.25s ease;
}
.tour-card {
  position: fixed;
  z-index: 99999;
  width: 280px;
  max-width: calc(100vw - 24px);
  box-sizing: border-box;
  background: #191b24;
  border: 1px solid rgba(124, 92, 255, 0.5);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
  animation: tourIn 0.18s ease;
}
@keyframes tourIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.tour-arrow {
  position: absolute;
  left: -8px;
  width: 14px;
  height: 14px;
  background: #191b24;
  border-left: 1px solid rgba(124, 92, 255, 0.5);
  border-bottom: 1px solid rgba(124, 92, 255, 0.5);
  transform: rotate(45deg);
}
.tour-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #b9a6ff;
  margin-bottom: 8px;
}
.tour-badge svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.tour-card h4 { margin: 0 0 6px; font-size: 16px; font-weight: 700; color: #fff; }
.tour-card p { margin: 0 0 14px; font-size: 13px; line-height: 1.5; color: rgba(255, 255, 255, 0.82); }
.tour-card p b { color: #fff; font-weight: 600; }
.tour-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.tour-dots { display: flex; gap: 6px; }
.tour-dot { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, 0.22); transition: background 0.15s ease; }
.tour-dot.on { background: var(--accent); }
.tour-actions { display: flex; gap: 6px; }
.tour-btn { border: none; border-radius: 999px; cursor: pointer; font-size: 12.5px; font-weight: 700; padding: 7px 14px; transition: filter 0.12s ease, background 0.12s ease; }
.tour-skip { background: transparent; color: rgba(255, 255, 255, 0.5); padding: 7px 8px; }
.tour-skip:hover { color: rgba(255, 255, 255, 0.8); }
.tour-back { background: rgba(255, 255, 255, 0.08); color: #fff; }
.tour-back:hover { background: rgba(255, 255, 255, 0.14); }
.tour-next { background: var(--accent-grad); color: #fff; }
.tour-next:hover { filter: brightness(1.08); }

/* range slider */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: var(--bg-elev-2);
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--accent-grad);
  cursor: pointer;
  border: 2px solid #0e0f13;
  box-shadow: 0 0 0 1px var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--accent-grad);
  cursor: pointer;
  border: 2px solid #0e0f13;
}

/* swatches */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.swatch {
  aspect-ratio: 1;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  transition: transform 0.1s ease, border-color 0.15s ease;
}
.swatch:hover { transform: scale(1.08); }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }

/* custom "My palette" slots */
.custom-palette-header {
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.custom-palette-header { display: flex; }

.save-image-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.save-image-btn svg { width: 17px; height: 17px; }
.save-image-btn:hover { background: #262835; border-color: #3a3d4d; }
.save-image-btn:active { transform: scale(0.98); }
.save-image-btn.saved {
  border-color: var(--accent-2);
  color: var(--accent-2);
}
.save-image-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.save-image-btn:disabled:hover {
  background: var(--bg-elev-2);
  border-color: var(--border);
}

.save-hint {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  color: var(--text-faint);
}
.save-hint[hidden] { display: none; }

.custom-palette { margin-top: 8px; }
.swatch.empty {
  cursor: default;
  background: transparent !important;
  border: 1.5px dashed var(--border);
  box-shadow: none;
  position: relative;
}
.swatch.empty:hover { transform: none; }
.swatch.empty::after {
  content: "+";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 15px;
  line-height: 1;
}

/* The interactive "+" slot that opens the native colour picker. It holds a
   transparent native colour input filling the slot, so a tap lands on the real
   control and the picker anchors here (works on iPad). */
.swatch.empty.add { cursor: pointer; }
.swatch.empty.add:hover {
  transform: scale(1.08);
  border-style: solid;
  border-color: var(--accent);
}
.swatch.empty.add:hover::after { color: var(--text); }
.palette-add-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

.instructions-input {
  width: 100%;
  resize: vertical;
  min-height: 64px;
  max-height: 160px;
  padding: 10px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  line-height: 1.5;
  transition: border-color 0.15s ease;
}
.instructions-input::placeholder { color: var(--text-faint); }
.instructions-input:focus {
  outline: none;
  border-color: var(--accent);
}

.eraser-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  color: var(--text-dim);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 10px 5px 8px;
  cursor: pointer;
}
.eraser-toggle svg { width: 14px; height: 14px; }
.eraser-toggle.active {
  background: rgba(255, 92, 114, 0.15);
  border-color: var(--danger);
  color: var(--text);
}

/* ---------------------------------------------------------------- *
 * Canvas stage
 * ---------------------------------------------------------------- */
.stage {
  position: relative;
  display: flex;
  /* Centering is done with margin:auto on the child (not align/justify
     center) so that when the zoomed canvas overflows, its top-left is still
     reachable by scrolling — flex centering clips that region unreachably. */
  padding: 24px;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  touch-action: none;        /* the stage handles its own touch — no browser scroll/exit gesture */
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 30% 20%, rgba(124, 92, 255, 0.06), transparent 45%),
    radial-gradient(circle at 80% 80%, rgba(52, 217, 200, 0.05), transparent 45%),
    var(--bg);
}

.canvas-wrap {
  position: relative;
  flex-shrink: 0;
  margin: auto;
  /* Actual size is set in px by zoom.js (ZoomController); these are just a
     sane default before JS runs on first paint. */
  width: min(700px, 90vw);
  height: min(700px, 60vh);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-soft), 0 0 0 1px var(--border);
  background: #fff;
  touch-action: none;
}

/* ---------------------------------------------------------------- *
 * Zoom controls
 * ---------------------------------------------------------------- */
.zoom-controls {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elev-1);
  box-shadow: var(--shadow-soft);
  z-index: 10;
}

.zoom-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.zoom-btn:hover:not(:disabled) { background: #2a2c38; }
.zoom-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.zoom-level {
  min-width: 46px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  user-select: none;
}

/* The three drawing layers (back → middle → foreground) stacked; the browser
   composites them for free. The white "paper" is the .canvas-wrap behind them. */
.layer-stack {
  position: absolute;
  inset: 0;
  transition: filter 0.2s ease;
}
.draw-layer {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none; /* input goes to #drawCanvas on top */
}
/* While a page loads (layers replay off-screen), dim the current page so it
   reads as "loading" rather than frozen; it brightens back up the moment the
   finished layers are swapped in. */
.layer-stack.page-loading { filter: brightness(0.5); }

/* Transparent surface on top of the stack that catches all pointer input. */
#drawCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: none; /* replaced by the true-size .brush-cursor ring */
  background: transparent;
}

/* True-size brush cursor: a ring matching the exact brush diameter and
   colour, tracked by app.js. Hidden for touch input. */
.brush-cursor {
  position: absolute;
  border: 1.5px solid #fff;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.28);
  z-index: 5;
}
.brush-cursor.eraser { border-style: dashed; }

/* ---------------------------------------------------------------- *
 * Trace reference image + controls
 * ---------------------------------------------------------------- */
.trace-open-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.trace-open-btn svg { width: 16px; height: 16px; }
.trace-open-btn:hover { background: #262835; border-color: #3a3d4d; }
.trace-open-btn[hidden] { display: none; }

.trace-img {
  position: absolute;
  transform-origin: center;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  z-index: 3;
}
.trace-img[hidden] { display: none; }
.trace-img:not(.locked) {
  outline: 2px dashed var(--accent);
  outline-offset: -1px;
}

.trace-panel {
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin-top: 8px;
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
}
.trace-panel[hidden] { display: none; }
.trace-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}
.trace-remove {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.trace-remove svg { width: 14px; height: 14px; }
.trace-remove:hover { color: var(--danger); border-color: var(--danger); }

.trace-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--text-dim);
}
.trace-row[hidden] { display: none; }
.trace-row > span { width: 42px; flex-shrink: 0; }
.trace-row input[type="range"] { flex: 1; }

.trace-actions {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}
.trace-lock-btn {
  flex: 1;
  padding: 9px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-grad);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.trace-lock-btn:hover { opacity: 0.9; }
.trace-lock-btn.locked {
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
}
/* Shown only while tracing: the clear exit from trace mode. */
.trace-finish-btn {
  flex: 1;
  padding: 9px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent-grad);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.trace-finish-btn:hover { opacity: 0.9; }
/* .trace-finish-btn is a flex item; [hidden] still needs to win over flex. */
.trace-finish-btn[hidden] { display: none; }

/* ---------------------------------------------------------------- *
 * Style picker
 * ---------------------------------------------------------------- */
.style-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.style-card {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-height: 76px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1.5px solid var(--border);
  background-color: var(--bg-elev-2);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
/* Dark gradient over the image so the right-aligned text stays legible. */
.style-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    rgba(10, 11, 15, 0.1) 0%,
    rgba(10, 11, 15, 0.45) 45%,
    rgba(10, 11, 15, 0.82) 100%);
  transition: background 0.15s ease;
}
.style-card:hover { border-color: #3a3d4d; transform: translateY(-1px); }
.style-card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.style-card .style-text {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
  text-align: right;
}
.style-card .style-title {
  font-size: 14.5px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.005em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}
.style-card .style-desc {
  font-size: 11.5px;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.7);
}

.style-card .style-check {
  position: relative;
  z-index: 1;
  width: 20px;
  height: 20px;
  min-width: 20px;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  transition: all 0.15s ease;
}
.style-card .style-check svg { width: 12px; height: 12px; stroke-width: 3; }
.style-card.active .style-check {
  background: var(--accent-grad);
  border-color: transparent;
  color: #fff;
}

.style-item {
  display: flex;
  flex-direction: column;
}

/* Accordion: grid-template-rows animates 0fr -> 1fr so the panel eases open
   to its natural content height (no JS height measuring needed), while the
   overflow-hidden inner clips it during the transition. */
.style-detail-wrap {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.25s ease;
}
.style-detail-wrap.open {
  grid-template-rows: 1fr;
}

.style-detail-inner {
  overflow: hidden;
  min-height: 0;
}

.style-detail-content {
  margin-top: 8px;
  padding: 12px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
}
.style-detail-desc {
  font-size: 12px;
  line-height: 1.55;
  color: var(--text);
  margin: 0 0 10px;
}
.style-detail-list {
  margin: 0 0 10px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.style-detail-list li {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--text-dim);
}
.style-detail-tone {
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text);
  margin: 0;
}
.style-detail-tone strong {
  color: var(--accent);
  font-weight: 700;
}
.style-detail-note {
  margin: 8px 0 0;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  line-height: 1.5;
  color: var(--text-faint);
  font-style: italic;
}

.engine-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.engine-btn {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 10px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--bg-elev-2);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.engine-btn:hover { border-color: #3a3d4d; }
.engine-btn.active {
  border-color: var(--accent);
  background: rgba(124, 92, 255, 0.14);
}
.engine-btn .engine-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
.engine-btn .engine-desc {
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--text-faint);
}

.render-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px;
  border-radius: var(--radius-md);
  border: none;
  background: var(--accent-grad);
  color: #fff;
  font-weight: 700;
  font-size: 14.5px;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(124, 92, 255, 0.35);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.render-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 28px rgba(124, 92, 255, 0.45); }
.render-btn:active { transform: translateY(0); }
.render-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ---------------------------------------------------------------- *
 * Result overlay
 * ---------------------------------------------------------------- */
.result-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 7, 10, 0.72);
  backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.result-overlay.open { display: flex; }

.result-card {
  width: min(1000px, 100%);
  max-height: 92vh;
  background: var(--bg-elev-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.result-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 20px;
  overflow-y: auto;
}

.result-pane {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.pane-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-weight: 600;
}

.result-pane img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border-radius: var(--radius-md);
  background: #0a0b0e;
  border: 1px solid var(--border);
}

.result-render-slot {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  background: #0a0b0e;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.result-render-slot img {
  border: none;
  aspect-ratio: auto;
  height: 100%;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  padding: 0 20px;
}
.loading-state[hidden] { display: none; }
.loading-substext {
  margin-top: -8px;
  font-size: 11.5px;
  color: var(--text-faint);
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-state {
  padding: 20px;
  text-align: center;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.5;
}
/* .btn is display:flex, so it ignores [hidden] without this. */
#errorBuyBtn { margin: 14px auto 0; }
#errorBuyBtn[hidden] { display: none; }

.result-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.btn {
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.15s ease, transform 0.1s ease;
}
.btn:active { transform: scale(0.97); }
.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
}
.btn-ghost:hover { color: var(--text); border-color: #3a3d4d; }
.btn-primary {
  background: var(--accent-grad);
  color: #fff;
}
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------------------------------------------------------------- *
 * About this project
 * ---------------------------------------------------------------- */
.about-card { width: min(560px, 100%); }

/* ---------------------------------------------------------------- *
 * Gallery
 * ---------------------------------------------------------------- */
.gallery-card { width: min(760px, 100%); }

.gallery-body {
  padding: 18px 22px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gallery-note {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--text-faint);
}
.gallery-note svg { width: 16px; height: 16px; flex: none; margin-top: 1px; }
.gallery-note[hidden] { display: none; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.gallery-tile {
  position: relative;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev-2);
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 1 / 1;
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.gallery-tile:hover { border-color: var(--accent); }
.gallery-tile:active { transform: scale(0.98); }
.gallery-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.gallery-tile-date {
  position: absolute;
  left: 6px;
  bottom: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

.gallery-msg {
  margin: 0;
  padding: 28px 0;
  text-align: center;
  font-size: 13.5px;
  color: var(--text-faint);
}
.gallery-msg[hidden] { display: none; }

/* Larger view of one saved render */
.viewer-card { width: min(720px, 100%); }
.viewer-body {
  padding: 18px 22px;
  display: flex;
  justify-content: center;
  overflow-y: auto;
}
.viewer-body img {
  max-width: 100%;
  max-height: 60vh;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.about-body {
  padding: 20px 22px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.about-body p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text-dim);
}

.linkedin-link {
  display: flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  width: fit-content;
  gap: 9px;
  margin-top: 4px;
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  background: #0a66c2;
  color: #fff;
  font-size: 13.5px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: opacity 0.15s ease;
}
.linkedin-link:hover { opacity: 0.88; }
.linkedin-link svg { width: 18px; height: 18px; }

/* ---------------------------------------------------------------- *
 * Welcome splash
 * ---------------------------------------------------------------- */
.splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg);
  opacity: 1;
  transition: opacity 0.5s ease;
}
.splash.hide { opacity: 0; pointer-events: none; }
/* Legibility scrim over the imagery. */
.splash::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background: linear-gradient(180deg,
    rgba(10, 11, 15, 0.35) 0%,
    rgba(10, 11, 15, 0.55) 45%,
    rgba(10, 11, 15, 0.82) 100%);
}

.splash-bg { position: absolute; inset: 0; z-index: 0; }
.splash-fg { position: absolute; inset: 0; z-index: 1; }

/* Blurred, enlarged copy that fills the whole viewport behind the art. */
.splash-layer {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 0;
  transform: scale(1.12); /* overscan so the blurred edge never shows */
  filter: blur(28px) saturate(1.15) brightness(0.85);
  transition: opacity 1.2s ease;
  will-change: opacity;
}
/* Sharp, whole image — always centred, never cropped. */
.splash-fg-layer {
  position: absolute;
  inset: 0;
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  opacity: 0;
  transition: opacity 1.2s ease;
  will-change: opacity;
}
.splash-layer.show,
.splash-fg-layer.show { opacity: 1; }

.splash-content {
  position: relative;
  z-index: 3;
  text-align: center;
  padding: 24px;
  max-width: 560px;
}
.splash-mark {
  display: inline-block;
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: url("../img/branding/inkmagik-logo.png") center / cover no-repeat;
  box-shadow: 0 0 30px rgba(124, 92, 255, 0.6);
  margin-bottom: 22px;
}
.splash-content h1 {
  font-size: 40px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  margin: 0;
  text-shadow: 0 2px 24px rgba(0, 0, 0, 0.55);
}
.splash-tagline {
  margin: 10px 0 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  background: var(--accent-grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.splash-desc {
  margin: 16px auto 0;
  max-width: 420px;
  font-size: 15px;
  line-height: 1.6;
  color: rgba(255, 255, 255, 0.86);
  text-shadow: 0 1px 12px rgba(0, 0, 0, 0.6);
}
.splash-btn {
  margin-top: 28px;
  padding: 13px 34px;
  border: none;
  border-radius: 999px;
  background: var(--accent-grad);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(124, 92, 255, 0.45);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.splash-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 32px rgba(124, 92, 255, 0.55); }
.splash-btn:active { transform: translateY(0); }

@media (prefers-reduced-motion: reduce) {
  .splash-layer,
  .splash-fg-layer { transition: opacity 0.01ms; }
}

/* ---------------------------------------------------------------- *
 * Mobile slide-in panels
 * ---------------------------------------------------------------- */
.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 15;
}
.scrim.open { display: block; }

@media (max-width: 900px) {
  :root { --panel-w: 82vw; }

  .only-mobile { display: flex; }

  .workspace {
    grid-template-columns: 1fr;
    position: relative;
  }

  .panel {
    position: fixed;
    top: 56px;
    bottom: 0;
    width: var(--panel-w);
    max-width: 320px;
    z-index: 16;
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-soft);
  }
  .panel-left { left: 0; transform: translateX(-105%); }
  .panel-left.open { transform: translateX(0); }
  .panel-right { right: 0; border-left: 1px solid var(--border); transform: translateX(105%); }
  .panel-right.open { transform: translateX(0); }

  .stage { padding: 12px; }

  /* Right panel is an off-screen overlay here, so hug the screen edge. */
  .page-tabs { right: 0; }

  .result-body { grid-template-columns: 1fr; }

  .splash-content h1 { font-size: 30px; }
  .splash-desc { font-size: 14px; }
}
