@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;1,300;1,400;1,600&family=DM+Mono:wght@300;400&family=Marcellus&family=IM+Fell+English:ital@0;1&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* ── Characterium palette — cream pages, dark ink ── */
  --page:        #f5f0e8;      /* aged cream */
  --page-warm:   #ede6d6;      /* slightly darker cream for cards */
  --page-deep:   #e4dbc8;      /* folded page shadow */
  --ink:         #2a2118;      /* dark brown-black ink */
  --ink-mid:     #5c4a38;      /* secondary ink */
  --ink-faint:   #9a8878;      /* faint annotations */
  --gold:        #8b6914;      /* aged gold ink */
  --gold-light:  #c4962a;      /* brighter gold accent */
  --rose:        #8b3a52;      /* wax seal burgundy-rose */
  --teal:        #2a6b6b;      /* botanical teal */
  --lavender:    #6b5a8b;      /* soft arcane purple */
  --border:      #c8b99a;      /* parchment border */
  --border-dark: #a89070;      /* stronger border */
  --success:     #2a6b3a;      /* forest green */
  --danger:      #8b2a2a;      /* deep red */

  /* ── Washes — watercolor tints ── */
  --wash-gold:   rgba(196,150,42,0.08);
  --wash-rose:   rgba(139,58,82,0.07);
  --wash-teal:   rgba(42,107,107,0.06);
  --wash-lav:    rgba(107,90,139,0.07);

  --tab-h: 64px;
  --top-h: 52px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* ── Notebook texture SVG ── */
  --noise: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
}

html, body {
  height: 100%; overflow: hidden;
  background: var(--page); color: var(--ink);
  font-family: 'DM Mono', monospace;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-image:
    var(--noise),
    radial-gradient(ellipse 70% 50% at 20% 0%, rgba(196,150,42,0.06) 0%, transparent 60%),
    radial-gradient(ellipse 50% 60% at 90% 100%, rgba(139,58,82,0.05) 0%, transparent 60%);
}

/* ════════════════════════════════════════════════════════
   APP SHELL
════════════════════════════════════════════════════════ */
.app-shell {
  display: flex; flex-direction: column;
  height: 100%; height: 100dvh; overflow: hidden;
}

/* ════════════════════════════════════════════════════════
   TOP BAR
════════════════════════════════════════════════════════ */
.top-bar {
  height: var(--top-h); flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.1rem;
  background: rgba(245,240,232,0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: relative;
}
/* Bottom flourish line on top bar */
.top-bar::after {
  content: '';
  position: absolute; bottom: -3px; left: 1rem; right: 1rem; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-light), var(--gold), var(--gold-light), transparent);
  opacity: 0.4;
}

.top-logo {
  font-family: 'IM Fell English', serif;
  font-size: 1.15rem;
  color: var(--ink);
  letter-spacing: 0.01em;
  display: flex; align-items: center; gap: 0.4rem;
}
.top-logo .logo-ornament {
  color: var(--gold);
  font-size: 0.9em;
  opacity: 0.8;
}

.install-btn {
  display: none;
  font-family: 'DM Mono', monospace; font-size: 0.55rem; letter-spacing: 0.1em;
  text-transform: uppercase; padding: 0.28rem 0.6rem; border-radius: 3px;
  border: 1px solid var(--border-dark); background: transparent; color: var(--ink-mid);
  cursor: pointer; transition: all 0.2s;
}
.install-btn.visible { display: block; }
.install-btn:active { background: var(--ink); color: var(--page); }

/* ════════════════════════════════════════════════════════
   PAGES
════════════════════════════════════════════════════════ */
.pages { flex: 1; overflow: hidden; position: relative; }
.page {
  display: none; position: absolute; inset: 0;
  overflow-y: auto; overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.page.active { display: block; }
.page-inner {
  max-width: 780px; margin: 0 auto;
  padding: 1.5rem 1.1rem calc(1.5rem + var(--tab-h) + var(--safe-bottom));
}

/* ════════════════════════════════════════════════════════
   BOTTOM TAB BAR
════════════════════════════════════════════════════════ */
.tab-bar {
  flex-shrink: 0; display: flex;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(245,240,232,0.97);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  position: relative;
}
.tab-bar::before {
  content: '';
  position: absolute; top: -3px; left: 1rem; right: 1rem; height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-light), var(--gold), var(--gold-light), transparent);
  opacity: 0.35;
}
.tab-btn {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 0.18rem;
  background: none; border: none; cursor: pointer;
  color: var(--ink-faint); transition: color 0.15s;
  padding: 0; position: relative;
  -webkit-tap-highlight-color: transparent;
}
.tab-btn.active { color: var(--gold); }
.tab-btn:active { opacity: 0.6; }
.tab-icon { width: 21px; height: 21px; flex-shrink: 0; }
.tab-label {
  font-family: 'DM Mono', monospace; font-size: 0.52rem;
  letter-spacing: 0.1em; text-transform: uppercase;
}
.tab-badge {
  position: absolute; top: 7px; right: calc(50% - 15px);
  background: var(--rose); color: var(--page);
  font-size: 0.42rem; font-family: 'DM Mono', monospace;
  min-width: 14px; height: 14px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center; padding: 0 3px;
}

/* ════════════════════════════════════════════════════════
   GENERATE PAGE — HEADER
════════════════════════════════════════════════════════ */
.gen-header { text-align: center; margin-bottom: 1.6rem; padding-top: 0.5rem; }

/* Decorative top flourish above title */
.gen-header::before {
  content: '✦ ── ✦ ── ✦';
  display: block;
  font-size: 0.55rem; letter-spacing: 0.3em;
  color: var(--gold); opacity: 0.6;
  margin-bottom: 0.8rem;
}

.eyebrow {
  font-family: 'DM Mono', monospace;
  font-size: 0.55rem; letter-spacing: 0.3em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 0.5rem;
}
h1 {
  font-family: 'IM Fell English', serif;
  font-size: clamp(1.9rem, 7vw, 2.9rem);
  font-weight: 400; line-height: 1.1;
  color: var(--ink);
}
h1 em {
  font-style: italic; color: var(--gold);
}
.subtitle {
  margin-top: 0.45rem;
  font-family: 'Cormorant Garamond', serif;
  font-style: italic;
  font-size: 0.9rem; color: var(--ink-mid); letter-spacing: 0.04em;
}

/* Decorative divider below subtitle */
.gen-header::after {
  content: '';
  display: block; width: 60%; max-width: 220px;
  height: 1px; margin: 0.9rem auto 0;
  background: linear-gradient(90deg, transparent, var(--border-dark), transparent);
}

/* ════════════════════════════════════════════════════════
   CONTROLS
════════════════════════════════════════════════════════ */
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 0.7rem; margin-bottom: 1.2rem; }
.ctrl-group { display: flex; flex-direction: column; gap: 0.3rem; }
.ctrl-group label {
  font-family: 'DM Mono', monospace;
  font-size: 0.52rem; letter-spacing: 0.2em; text-transform: uppercase;
  color: var(--ink-faint);
}
select {
  background: var(--page-warm); border: 1px solid var(--border); color: var(--ink);
  font-family: 'Cormorant Garamond', serif; font-size: 0.95rem;
  padding: 0.5rem 2rem 0.5rem 0.65rem;
  border-radius: 4px; cursor: pointer; appearance: none; width: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%239a8878' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 0.65rem center;
  transition: border-color 0.2s;
}
select:focus { outline: none; border-color: var(--gold); }
optgroup { color: var(--ink-mid); font-family: 'DM Mono', monospace; font-size: 0.75rem; }
option { color: var(--ink); background: var(--page-warm); }

.btn-generate {
  grid-column: 1 / -1;
  background: var(--ink);
  border: none; color: var(--page); font-family: 'DM Mono', monospace;
  font-size: 0.65rem; letter-spacing: 0.2em; text-transform: uppercase;
  padding: 0.85rem 1.2rem; border-radius: 4px; cursor: pointer;
  transition: opacity 0.2s, transform 0.12s; width: 100%;
  position: relative; overflow: hidden;
}
.btn-generate::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, transparent 40%, rgba(196,150,42,0.15) 100%);
  pointer-events: none;
}
.btn-generate:hover { opacity: 0.88; }
.btn-generate:active { transform: scale(0.99); opacity: 0.85; }
.btn-generate:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ════════════════════════════════════════════════════════
   PROMPT CARD — the notebook entry
════════════════════════════════════════════════════════ */
.prompt-card {
  background: var(--page-warm);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1.4rem 1.4rem 1.6rem;
  position: relative; overflow: hidden;
  display: none; animation: fadeUp 0.4s ease both;
  /* Subtle inner shadow for paper depth */
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.6),
    0 2px 12px rgba(42,33,24,0.08),
    0 0 0 1px rgba(168,144,112,0.2);
}
.prompt-card.visible { display: block; }

/* Left margin rule — like a notebook */
.prompt-card::before {
  content: '';
  position: absolute; top: 0; left: 2.4rem; bottom: 0; width: 1px;
  background: linear-gradient(to bottom, transparent 0%, rgba(196,150,42,0.25) 5%, rgba(196,150,42,0.25) 95%, transparent 100%);
}
/* Top tape / wax seal decoration */
.prompt-card::after {
  content: '❧';
  position: absolute; top: 0.9rem; right: 1rem;
  font-size: 1rem; color: var(--rose); opacity: 0.35;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.char-name {
  font-family: 'IM Fell English', serif;
  font-size: 1.5rem; font-weight: 400;
  color: var(--ink); margin-bottom: 0.1rem;
  padding-left: 0.2rem;
}
.char-archetype {
  font-family: 'DM Mono', monospace;
  font-size: 0.54rem; letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-faint); margin-bottom: 1.3rem; padding-left: 0.2rem;
}

/* ── Section dividers — ink ruled lines ── */
.section { margin-bottom: 1.15rem; }
.section-title {
  font-family: 'DM Mono', monospace;
  font-size: 0.5rem; letter-spacing: 0.25em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 0.45rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.section-title::before {
  content: '§';
  font-size: 0.65rem; opacity: 0.5;
}
.section-title::after {
  content: ''; flex: 1; height: 1px;
  background: linear-gradient(90deg, var(--border), transparent);
}
.section p {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.05rem; line-height: 1.7;
  color: var(--ink-mid);
}

/* ════════════════════════════════════════════════════════
   PALETTE STRIP
════════════════════════════════════════════════════════ */
.palette-strip {
  display: flex; border-radius: 3px; overflow: hidden; height: 48px;
  margin-bottom: 0.6rem;
  border: 1px solid var(--border-dark);
  box-shadow: inset 0 1px 3px rgba(42,33,24,0.12);
}
.swatch { flex: 1; position: relative; cursor: pointer; transition: flex 0.25s ease; }
.swatch:active { flex: 1.6; }
.swatch-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(42,33,24,0.7); color: var(--page);
  font-size: 0.46rem; text-align: center; padding: 2px 1px;
  opacity: 0; transition: opacity 0.15s; font-family: 'DM Mono', monospace;
}
.swatch:active .swatch-label { opacity: 1; }

.palette-names { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.palette-name-chip {
  display: flex; align-items: center; gap: 0.28rem;
  font-family: 'Cormorant Garamond', serif; font-size: 0.82rem; color: var(--ink-mid);
}
.chip-dot {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
  border: 1px solid rgba(42,33,24,0.2);
}

/* ════════════════════════════════════════════════════════
   REFERENCE BOARD
════════════════════════════════════════════════════════ */
.ref-board {
  margin-top: 1.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--page-deep);
  overflow: hidden;
}
.ref-board-header {
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
  background: var(--page-warm);
  display: flex; align-items: center; justify-content: space-between;
}
.ref-board-title {
  font-family: 'DM Mono', monospace;
  font-size: 0.5rem; letter-spacing: 0.25em; text-transform: uppercase;
  color: var(--gold); display: flex; align-items: center; gap: 0.4rem;
}
.ref-board-title::before { content: '⊕'; font-size: 0.7rem; opacity: 0.6; }

.ref-tabs {
  display: flex; background: var(--page-warm);
  border-bottom: 1px solid var(--border);
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch; scrollbar-width: none;
}
.ref-tabs::-webkit-scrollbar { display: none; }
.ref-tab {
  font-family: 'DM Mono', monospace;
  font-size: 0.5rem; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 0.5rem 0.8rem; cursor: pointer; color: var(--ink-faint); white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  background: none; border-top: none; border-left: none; border-right: none;
  transition: color 0.15s; -webkit-tap-highlight-color: transparent;
}
.ref-tab.active { color: var(--gold); border-bottom-color: var(--gold); }
.ref-tab:active { opacity: 0.7; }

.ref-panel { display: none; padding: 0.7rem; }
.ref-panel.active { display: block; }
.ref-panel-header { display: flex; justify-content: flex-end; margin-bottom: 0.45rem; }

/* Image grid */
.img-grid { columns: 3; column-gap: 5px; }
.img-cell {
  break-inside: avoid; margin-bottom: 5px; border-radius: 3px;
  overflow: hidden; background: var(--border); cursor: zoom-in; position: relative;
}
.img-cell img { width: 100%; display: block; }
.img-cell-cap {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(42,33,24,0.75));
  color: rgba(245,240,232,0.9); font-size: 0.44rem; padding: 0.35rem 0.3rem 0.22rem;
  font-family: 'DM Mono', monospace; opacity: 0; transition: opacity 0.18s;
}
.img-cell:active .img-cell-cap { opacity: 1; }

/* SVG grid — kept for lightbox zoom wrapper */
.svg-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 5px; }
.svg-cell { border-radius: 3px; overflow: hidden; cursor: zoom-in; position: relative; }
.svg-cell svg { width: 100%; display: block; }

/* Composition grid */
.comp-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.comp-card {
  background: var(--page-warm);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  cursor: zoom-in;
  transition: border-color 0.2s;
}
.comp-card:active { border-color: var(--gold); }
.comp-card svg { width: 100%; display: block; }
.comp-label {
  padding: 0.3rem 0.35rem 0.35rem;
  border-top: 1px solid var(--border);
  background: var(--page);
}
.comp-name {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: 0.48rem; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 0.12rem;
}
.comp-desc {
  font-family: 'Cormorant Garamond', serif;
  font-style: italic; font-size: 0.75rem;
  color: var(--ink-mid); line-height: 1.35;
}

/* Skeleton */
.img-skeleton { columns: 3; column-gap: 5px; }
.skel-block {
  break-inside: avoid; margin-bottom: 5px; border-radius: 3px;
  background: var(--border); animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:.35} 50%{opacity:.7} }

.ref-status {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: 0.88rem; color: var(--ink-faint); text-align: center;
  padding: 1.5rem 0.5rem; line-height: 1.6;
}
.pexels-credit {
  font-size: 0.48rem; color: var(--ink-faint); text-align: right;
  margin-top: 0.3rem; opacity: 0.55; font-family: 'DM Mono', monospace;
}
.pexels-credit a { color: var(--gold); text-decoration: none; }

/* Regen button */
.btn-regen {
  font-family: 'DM Mono', monospace; font-size: 0.5rem; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 0.25rem 0.55rem; border-radius: 3px; cursor: pointer;
  border: 1px solid var(--border-dark); background: transparent; color: var(--ink-faint);
  display: flex; align-items: center; gap: 0.3rem; transition: all 0.2s;
}
.btn-regen:active { border-color: var(--gold); color: var(--gold); }
.btn-regen .spin { display: inline-block; }
.btn-regen.spinning .spin { animation: rot 0.5s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
.btn-regen:disabled { opacity: 0.35; }

/* ════════════════════════════════════════════════════════
   STUDY TIP BOX — annotated note
════════════════════════════════════════════════════════ */
.tip-box {
  background: rgba(139,105,20,0.06);
  border: 1px solid rgba(139,105,20,0.25);
  border-left: 3px solid var(--gold);
  border-radius: 0 4px 4px 0;
  padding: 0.85rem 1rem 0.85rem 0.9rem;
  margin-top: 1.1rem;
  position: relative;
}
.tip-box::before {
  content: '✎';
  position: absolute; top: 0.65rem; right: 0.8rem;
  font-size: 0.8rem; color: var(--gold); opacity: 0.4;
}
.tip-box p {
  font-family: 'Cormorant Garamond', serif !important;
  font-size: 0.95rem !important; line-height: 1.7 !important;
  color: var(--ink-mid) !important;
}

/* ════════════════════════════════════════════════════════
   BUTTONS
════════════════════════════════════════════════════════ */
.card-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1.2rem; }
.btn-sm {
  font-family: 'DM Mono', monospace; font-size: 0.55rem; letter-spacing: 0.12em; text-transform: uppercase;
  padding: 0.4rem 0.8rem; border-radius: 3px; cursor: pointer;
  border: 1px solid var(--border-dark); background: transparent; color: var(--ink-mid);
  transition: all 0.2s; -webkit-tap-highlight-color: transparent;
}
.btn-sm:active { background: var(--ink); color: var(--page); border-color: var(--ink); }
.btn-sm.accent { border-color: var(--gold); color: var(--gold); }
.btn-sm.saved  { border-color: var(--success); color: var(--success); }

.btn-primary {
  background: var(--ink); border: none; color: var(--page);
  font-family: 'DM Mono', monospace; font-size: 0.65rem; letter-spacing: 0.18em; text-transform: uppercase;
  padding: 0.7rem 1.2rem; border-radius: 4px; cursor: pointer;
  transition: opacity 0.2s; width: 100%;
}
.btn-primary:active { opacity: 0.75; }

/* ════════════════════════════════════════════════════════
   EMPTY STATE
════════════════════════════════════════════════════════ */
.empty-state { text-align: center; padding: 3rem 1.5rem; }
.empty-icon {
  font-size: 1.8rem; margin-bottom: 0.6rem;
  color: var(--gold); opacity: 0.35;
}
.empty-state p {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: 1.05rem; color: var(--ink-faint);
  line-height: 1.6;
}

/* ════════════════════════════════════════════════════════
   HISTORY PAGE
════════════════════════════════════════════════════════ */
.page-title-row {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 1.2rem; padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.page-title-row::after {
  content: '';
  position: absolute; bottom: -3px; left: 0; right: 0; height: 1px;
  background: linear-gradient(90deg, var(--gold-light), transparent);
  opacity: 0.3;
}
.page-title-row h2 {
  font-family: 'IM Fell English', serif;
  font-size: 1.5rem; font-weight: 400; color: var(--ink);
}

.streak-card {
  display: flex; align-items: center; gap: 1rem;
  background: var(--page-warm);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: 0 4px 4px 0;
  padding: 0.85rem 1.1rem; margin-bottom: 1.2rem;
}
.streak-num {
  font-family: 'IM Fell English', serif;
  font-size: 2.6rem; color: var(--gold); line-height: 1;
}
.streak-label {
  font-family: 'DM Mono', monospace;
  font-size: 0.56rem; text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--ink-faint); margin-bottom: 0.2rem;
}
.streak-hint {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: 0.88rem; color: var(--ink-faint); line-height: 1.4;
}

.hist-list { display: flex; flex-direction: column; gap: 0.55rem; }
.hist-item {
  background: var(--page-warm); border: 1px solid var(--border); border-radius: 4px;
  padding: 0.8rem 0.95rem; cursor: pointer; display: flex;
  align-items: flex-start; justify-content: space-between; gap: 0.8rem;
  transition: border-color 0.2s; -webkit-tap-highlight-color: transparent;
  box-shadow: 0 1px 3px rgba(42,33,24,0.05);
}
.hist-item:active { border-color: var(--gold); }
.hist-item.completed { border-left: 3px solid var(--success); }
.hist-item-left { flex: 1; min-width: 0; }
.hist-item-name {
  font-family: 'IM Fell English', serif; font-size: 1rem;
  color: var(--ink); margin-bottom: 0.1rem;
}
.hist-item-meta {
  font-family: 'DM Mono', monospace;
  font-size: 0.5rem; color: var(--ink-faint); letter-spacing: 0.06em; text-transform: uppercase;
}
.hist-item-diff {
  font-family: 'DM Mono', monospace;
  font-size: 0.5rem; color: var(--gold); letter-spacing: 0.05em; margin-top: 0.18rem;
}
.hist-item-actions { display: flex; gap: 0.35rem; flex-shrink: 0; padding-top: 0.1rem; }
.btn-icon {
  background: none; border: 1px solid var(--border); color: var(--ink-faint);
  width: 28px; height: 28px; border-radius: 3px; cursor: pointer; font-size: 0.75rem;
  display: flex; align-items: center; justify-content: center; transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon.done { border-color: var(--success); color: var(--success); }
.btn-icon:active { opacity: 0.6; }

.hist-empty { text-align: center; padding: 3rem 1rem; }
.hist-empty p {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  color: var(--ink-faint); line-height: 1.8; font-size: 1rem;
}

/* ════════════════════════════════════════════════════════
   SETTINGS PAGE
════════════════════════════════════════════════════════ */
.settings-section { margin-bottom: 2rem; }
.settings-section-title {
  font-family: 'DM Mono', monospace;
  font-size: 0.54rem; letter-spacing: 0.22em; text-transform: uppercase;
  color: var(--gold); padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border); margin-bottom: 1rem;
  display: flex; align-items: center; gap: 0.4rem;
}
.settings-section-title::before { content: '§'; font-size: 0.7rem; opacity: 0.6; }

.settings-row { display: flex; flex-direction: column; gap: 0.42rem; margin-bottom: 1rem; }
.settings-label {
  font-family: 'Cormorant Garamond', serif; font-size: 1rem; color: var(--ink);
}
.settings-hint {
  font-family: 'Cormorant Garamond', serif; font-style: italic;
  font-size: 0.9rem; color: var(--ink-faint); line-height: 1.6;
}
.settings-input {
  background: var(--page-warm); border: 1px solid var(--border); color: var(--ink);
  font-family: 'DM Mono', monospace; font-size: 0.7rem;
  padding: 0.6rem 0.8rem; border-radius: 4px; width: 100%;
  transition: border-color 0.2s; -webkit-appearance: none;
}
.settings-input:focus { outline: none; border-color: var(--gold); }
.settings-input.valid { border-color: var(--success); }
.settings-input.invalid { border-color: var(--danger); }
.settings-input::placeholder { color: var(--ink-faint); }

.key-status {
  font-family: 'DM Mono', monospace; font-size: 0.55rem; min-height: 1em;
}
.key-status.ok  { color: var(--success); }
.key-status.err { color: var(--danger); }
.key-status.dim { color: var(--ink-faint); }

/* ════════════════════════════════════════════════════════
   LIGHTBOX
════════════════════════════════════════════════════════ */
.lightbox {
  display: none; position: fixed; inset: 0; z-index: 1000;
  background: rgba(30,24,16,0.92); align-items: center; justify-content: center; padding: 1rem;
}
.lightbox.open { display: flex; }
.lightbox img, .lightbox svg {
  max-width: 92vw; max-height: 85vh; border-radius: 4px; object-fit: contain;
}
.lightbox-close {
  position: fixed; top: 1rem; right: 1rem;
  background: rgba(245,240,232,0.12); border: 1px solid rgba(245,240,232,0.2);
  color: var(--page); width: 2.2rem; height: 2.2rem; border-radius: 50%;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 1rem; z-index: 1001;
}

/* ════════════════════════════════════════════════════════
   TOAST
════════════════════════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 0.75rem);
  left: 50%; transform: translateX(-50%) translateY(4rem);
  background: var(--ink); color: var(--page);
  font-family: 'DM Mono', monospace; font-size: 0.6rem; letter-spacing: 0.08em;
  padding: 0.5rem 1rem; border-radius: 3px; z-index: 500;
  transition: transform 0.28s ease, opacity 0.28s ease;
  opacity: 0; pointer-events: none; white-space: nowrap;
  box-shadow: 0 4px 16px rgba(42,33,24,0.25);
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ════════════════════════════════════════════════════════
   SVG CELL LABELS
════════════════════════════════════════════════════════ */
.svg-cell { position: relative; }
.svg-cap {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(30,24,16,0.7));
  color: rgba(245,240,232,0.85); font-size: 0.46rem;
  padding: 0.4rem 0.3rem 0.25rem; font-family: 'DM Mono', monospace;
  letter-spacing: 0.06em; opacity: 0; transition: opacity 0.18s; pointer-events: none;
}
.svg-cell:hover .svg-cap, .svg-cell:active .svg-cap { opacity: 1; }

/* ════════════════════════════════════════════════════════
   RESPONSIVE
════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .controls { grid-template-columns: 1fr; }
  .btn-generate { grid-column: 1; }
  .img-grid, .img-skeleton { columns: 2; }
  .comp-grid { grid-template-columns: repeat(2,1fr); }
}

@media (min-width: 768px) {
  .tab-bar { display: none; }
  .page-inner { padding-bottom: 3rem; }
  .toast { bottom: 1.5rem; }
}


/* =========================================
   CHARACTERIUM — THEME COMPATIBILITY BRIDGE
   Makes the existing HTML shell use the pastel navy system
   ========================================= */

.top-bar {
  background: rgba(249, 244, 235, 0.82);
  border-bottom: 1px solid var(--char-line);
  box-shadow: 0 1px 0 rgba(255,255,255,0.7);
}

.top-logo {
  color: var(--char-ink);
  text-shadow: 0 1px 0 rgba(255,255,255,0.45);
}
.top-logo .logo-ornament { color: var(--char-gold); }

.install-btn {
  border-radius: 16px;
  border-color: rgba(183,140,58,0.30);
  color: var(--char-ink);
  background:
    linear-gradient(180deg, rgba(252,248,240,0.92), rgba(238,229,214,0.94)),
    linear-gradient(90deg, rgba(111,130,163,0.16), rgba(183,140,58,0.10));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.72), 0 8px 18px rgba(52,40,31,0.07);
}

.gen-header,
.hero-shell {
  position: relative;
  padding: 1.8rem 1.15rem 1.35rem;
  border-radius: var(--char-radius-xl);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.48), rgba(255,255,255,0.18)),
    radial-gradient(circle at 50% 18%, rgba(111,130,163,0.09), transparent 42%);
  border: 1px solid rgba(183,140,58,0.14);
  box-shadow: var(--char-shadow-soft);
  overflow: hidden;
  margin-bottom: 1rem;
}
.gen-header::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.42;
  background:
    radial-gradient(circle at 50% 30%, rgba(183,140,58,0.10), transparent 22%),
    radial-gradient(circle at 20% 40%, rgba(111,130,163,0.08), transparent 20%),
    radial-gradient(circle at 78% 42%, rgba(111,130,163,0.06), transparent 18%);
}
.gen-header > * { position: relative; z-index: 1; }
.eyebrow {
  color: var(--char-ink-faint);
  letter-spacing: 0.28em;
  font-size: 0.76rem;
}
h1 { color: var(--char-ink); }
h1 em { color: var(--char-gold); }
.subtitle {
  color: var(--char-ink-soft);
  line-height: 1.5;
}
.gen-header::after {
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(183, 140, 58, 0.08) 10%,
    rgba(183, 140, 58, 0.32) 50%,
    rgba(183, 140, 58, 0.08) 90%,
    transparent 100%
  );
  width: 100%;
  max-width: 260px;
  margin: 1rem auto 0;
}

.controls {
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.ctrl-group {
  position: relative;
}
.ctrl-group label {
  color: var(--char-ink-faint);
  letter-spacing: 0.22em;
  font-size: 0.74rem;
}
.ctrl-group::before {
  content: "✦";
  position: absolute;
  left: 1rem;
  top: 2.56rem;
  transform: translateY(-50%);
  color: var(--char-gold);
  font-size: 0.95rem;
  pointer-events: none;
  z-index: 2;
}
.ctrl-group select {
  padding-left: 2.7rem;
}

select,
.settings-input {
  border-radius: 16px;
  border: 1px solid rgba(183, 140, 58, 0.30);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.72), rgba(247,241,231,0.96)),
    linear-gradient(90deg, rgba(111, 130, 163, 0.08), transparent 28%);
  color: var(--char-ink);
  min-height: 58px;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.65),
    0 2px 8px rgba(52, 40, 31, 0.04);
}
select:hover,
.settings-input:hover {
  border-color: rgba(183, 140, 58, 0.44);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.72),
    0 6px 18px rgba(52, 40, 31, 0.06);
}
select:focus,
.settings-input:focus,
.settings-input:focus-visible {
  border-color: rgba(183, 140, 58, 0.62);
  box-shadow:
    0 0 0 3px rgba(183, 140, 58, 0.12),
    0 0 0 7px rgba(111, 130, 163, 0.10),
    0 8px 24px rgba(52, 40, 31, 0.08);
}

.btn-generate,
.btn-primary,
.btn-sm,
.btn-icon,
.btn-regen {
  border-radius: 18px;
}
.btn-generate,
.btn-primary {
  border: 1px solid rgba(183, 140, 58, 0.34);
  color: var(--char-ink);
  background:
    linear-gradient(180deg, rgba(252,248,240,0.92), rgba(238,229,214,0.94)),
    linear-gradient(90deg, rgba(111,130,163,0.16), rgba(183,140,58,0.10) 60%, rgba(255,255,255,0.25));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.72),
    0 8px 18px rgba(52, 40, 31, 0.07);
}
.btn-generate::before,
.btn-primary::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.42;
  pointer-events: none;
  background:
    linear-gradient(120deg, transparent 0%, rgba(255,255,255,0.30) 45%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 500ms ease;
}
.btn-generate:hover::before,
.btn-primary:hover::before {
  transform: translateX(100%);
}
.btn-generate:hover,
.btn-primary:hover,
.btn-sm:hover,
.btn-regen:hover {
  transform: translateY(-1px);
  border-color: rgba(183, 140, 58, 0.48);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.82),
    0 10px 22px rgba(52, 40, 31, 0.10),
    0 0 22px rgba(183, 140, 58, 0.08);
}
.btn-generate {
  position: relative;
  overflow: hidden;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.prompt-card,
.streak-card,
.hist-item,
.settings-section,
.ref-board {
  border-radius: 24px;
  border: 1px solid rgba(183, 140, 58, 0.22);
  background:
    linear-gradient(180deg, rgba(252,248,240,0.95), rgba(246,239,228,0.98));
  box-shadow:
    0 12px 26px rgba(52, 40, 31, 0.08),
    inset 0 1px 0 rgba(255,255,255,0.72);
}
.prompt-card::before {
  left: 2rem;
}
.page-title-row h2,
.char-name {
  color: var(--char-ink);
}
.char-archetype,
.hist-item-meta,
.streak-label,
.key-status.dim,
.settings-hint {
  color: var(--char-ink-faint);
}
.section-title,
.settings-section-title,
.ref-board-title,
.comp-kicker,
.comp-plate-label,
.comp-guides span,
.comp-note span {
  color: var(--char-gold);
}
.section p,
.comp-copy,
.comp-plate-effect,
.comp-guides p,
.comp-note p,
.hist-empty p,
.empty-state p {
  color: var(--char-ink-soft);
}
.ref-board {
  background:
    linear-gradient(180deg, rgba(252,248,240,0.96), rgba(243,236,224,0.98)),
    radial-gradient(circle at top right, rgba(111,130,163,0.08), transparent 22%);
}
.ref-tabs {
  gap: 0.3rem;
  padding: 0.45rem 0.45rem 0.2rem;
  border-bottom: none;
}
.ref-tab {
  border-radius: 999px;
  border: 1px solid rgba(183,140,58,0.2);
  background: rgba(255,255,255,0.3);
  margin-bottom: 0;
}
.ref-tab.active {
  background: linear-gradient(180deg, rgba(250,245,236,0.98), rgba(234,226,212,0.98));
  color: var(--char-gold);
  border-color: rgba(183,140,58,0.36);
}

.tab-bar {
  background: rgba(246, 241, 232, 0.88);
  border-top: 1px solid var(--char-line);
  box-shadow: 0 -4px 20px rgba(52, 40, 31, 0.04);
}
.tab-btn {
  color: var(--char-ink-faint);
}
.tab-btn.active { color: var(--char-gold); }
.tab-btn.active svg {
  filter: drop-shadow(0 0 8px rgba(183, 140, 58, 0.18));
}

.empty-state {
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(252,248,240,0.70), rgba(244,236,223,0.78));
  border: 1px solid rgba(183, 140, 58, 0.16);
  box-shadow: var(--char-shadow-soft);
}

@media (max-width: 640px) {
  .gen-header {
    padding: 1.5rem 1rem 1.25rem;
    border-radius: 22px;
  }
  .prompt-card,
  .streak-card,
  .hist-item,
  .settings-section,
  .ref-board,
  .empty-state {
    border-radius: 20px;
  }
  .ctrl-group::before {
    top: 2.45rem;
  }
}


/* Directed reference build */
.direction-studio {
  margin-top: 1rem;
  padding: 1rem;
  background: rgba(255,248,239,0.78);
  border: 1px solid rgba(168,144,112,0.5);
  backdrop-filter: blur(6px);
}
.direction-header {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  align-items: flex-start;
  margin-bottom: 0.9rem;
}
.direction-kicker,
.direction-title {
  font-family: 'DM Mono', monospace;
  font-size: 0.56rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}
.direction-copy {
  margin-top: 0.35rem;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.95rem;
  color: var(--ink-mid);
  line-height: 1.5;
}
.direction-block + .direction-block { margin-top: 1rem; }
.palette-choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 0.7rem;
  margin-top: 0.6rem;
}
.palette-choice-card {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.42);
  border-radius: 10px;
  padding: 0.7rem;
  text-align: left;
  cursor: pointer;
}
.palette-choice-card.selected,
.img-cell.selected,
.comp-card.selected,
.comp-hero.selected {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px rgba(196,150,42,0.22), 0 8px 18px rgba(42,33,24,0.08);
}
.palette-choice-header {
  display: flex;
  justify-content: space-between;
  gap: 0.6rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.52rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink);
}
.choice-check { color: var(--gold); }
.palette-choice-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin: 0.6rem 0 0.5rem;
}
.mini-swatch {
  height: 22px;
  border-radius: 999px;
  border: 1px solid rgba(42,33,24,0.08);
}
.palette-choice-desc {
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.9rem;
  color: var(--ink-mid);
  line-height: 1.45;
}
.direction-summary { margin-top: 0.65rem; }
.direction-pill-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0,1fr));
  gap: 0.6rem;
}
.direction-pill-grid-secondary { margin-top: 0.6rem; }
.direction-pill {
  border: 1px dashed rgba(168,144,112,0.55);
  border-radius: 10px;
  padding: 0.65rem 0.7rem;
  background: rgba(255,255,255,0.28);
}
.direction-pill.filled {
  background: rgba(255,252,247,0.62);
  border-style: solid;
}
.pill-label {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: 0.48rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.18rem;
}
.pill-value {
  display: block;
  font-family: 'Cormorant Garamond', serif;
  color: var(--ink-mid);
  line-height: 1.35;
  font-size: 0.92rem;
}
.direction-ready {
  margin-top: 0.7rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.5rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.direction-actions { margin-top: 0.8rem; }

.img-cell { position: relative; }
.img-tap { cursor: zoom-in; }
.img-pick-btn,
.comp-zoom-btn {
  position: absolute;
  z-index: 2;
  top: 7px;
  right: 7px;
  border: 1px solid rgba(245,240,232,0.8);
  background: rgba(42,33,24,0.78);
  color: var(--page);
  border-radius: 999px;
  padding: 0.22rem 0.5rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.42rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.comp-zoom-btn { right: 10px; }
.img-cell.selected .img-pick-btn {
  background: rgba(139,105,20,0.95);
}
.comp-card,
.comp-hero {
  position: relative;
}

@media (max-width: 640px) {
  .palette-choice-grid,
  .direction-pill-grid {
    grid-template-columns: 1fr;
  }
  .direction-header {
    flex-direction: column;
  }
}


/* ── Image generation studio ─────────────────────────────────────────────── */
.style-preset-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
  margin: 0.8rem 0 0.9rem;
}
.style-preset {
  background: rgba(255,255,255,0.42);
  border: 1px solid rgba(168,144,112,0.5);
  border-radius: 14px;
  padding: 0.75rem 0.7rem;
  text-align: left;
  cursor: pointer;
  color: var(--ink);
}
.style-preset.selected {
  border-color: rgba(139,105,20,0.85);
  box-shadow: 0 0 0 1px rgba(196,150,42,0.25), 0 10px 18px rgba(42,33,24,0.08);
  background: linear-gradient(180deg, rgba(252,249,243,0.95), rgba(243,236,224,0.95));
}
.style-preset-name {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: 0.64rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.style-preset-desc {
  display: block;
  margin-top: 0.28rem;
  font-family: 'Cormorant Garamond', serif;
  font-size: 0.95rem;
  line-height: 1.15;
  color: var(--ink-mid);
}
.generate-actions { margin-top: 0.35rem; }
.generated-ref-card {
  margin-top: 0.95rem;
  border: 1px solid rgba(168,144,112,0.45);
  border-radius: 22px;
  background: rgba(255,251,245,0.8);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.4);
  padding: 1rem;
}
.generated-ref-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}
.generated-ref-kicker {
  font-family: 'DM Mono', monospace;
  font-size: 0.7rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}
.generated-ref-meta {
  margin-top: 0.18rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.generated-ref-body {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.generated-ref-empty, .generated-ref-status {
  text-align: center;
  color: var(--ink-faint);
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.05rem;
}
.generated-ref-error {
  width: 100%;
  background: rgba(173, 84, 72, 0.09);
  border-radius: 18px;
  padding: 1rem;
  color: #9b4b49;
  font-family: 'Cormorant Garamond', serif;
  font-size: 1rem;
  line-height: 1.35;
}
.generated-ref-image-wrap { width: 100%; }
.generated-ref-image {
  width: 100%;
  display: block;
  border-radius: 16px;
  border: 1px solid rgba(168,144,112,0.35);
}
@media (max-width: 640px) {
  .style-preset-row { grid-template-columns: 1fr; }
  .generated-ref-head { flex-direction: column; }
}


/* ═════════════════ DESIGN LOCK — STORYBOOK REINFORCEMENT ═════════════════ */
:root {
  --story-bg: url('assets/field-guide-bg.jpg');
  --story-paper: rgba(251, 246, 238, 0.82);
  --story-paper-strong: rgba(250, 245, 236, 0.92);
  --story-blue: #8a97b7;
  --story-blue-deep: #7082a4;
  --story-gold: #b38c3a;
  --story-gold-deep: #8f6b22;
  --story-line: rgba(166, 138, 93, 0.42);
  --story-ink: #3c2c21;
  --story-shadow: 0 14px 36px rgba(65, 48, 32, 0.09), inset 0 1px 0 rgba(255,255,255,0.68);
}
html, body {
  background: #f4ede3;
  color: var(--story-ink);
}
body {
  position: relative;
  background-image:
    radial-gradient(circle at 50% 18%, rgba(255,255,255,0.56), transparent 24%),
    linear-gradient(180deg, rgba(248,242,232,0.68), rgba(248,242,232,0.76)),
    var(--story-bg);
  background-size: auto, auto, cover;
  background-position: center top, center, center top;
  background-attachment: fixed, fixed, fixed;
}
body::before,
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
body::before {
  background:
    radial-gradient(circle at 50% 18%, rgba(255,255,255,0.52), transparent 22%),
    radial-gradient(circle at 14% 16%, rgba(124,140,180,0.12), transparent 20%),
    radial-gradient(circle at 88% 74%, rgba(124,140,180,0.14), transparent 24%),
    radial-gradient(circle at 50% 50%, rgba(255,255,255,0.08), transparent 48%);
}
body::after {
  background:
    linear-gradient(90deg, rgba(119,134,168,0.16), transparent 12%, transparent 88%, rgba(119,134,168,0.16)),
    linear-gradient(180deg, rgba(255,255,255,0.18), transparent 20%, transparent 80%, rgba(119,134,168,0.08));
  mix-blend-mode: multiply;
}
.app-shell, .lightbox, .toast { position: relative; z-index: 1; }
.pages { background: transparent; }
.page-inner {
  max-width: 860px;
  position: relative;
}
.page[data-page="generate"] .page-inner::before,
.page[data-page="generate"] .page-inner::after {
  content: '';
  position: absolute;
  top: 0.4rem;
  bottom: calc(1.5rem + var(--tab-h) + var(--safe-bottom));
  width: 2px;
  background: linear-gradient(180deg, rgba(179,140,58,0), rgba(179,140,58,0.68) 10%, rgba(112,130,164,0.32) 65%, rgba(179,140,58,0));
  opacity: 0.45;
}
.page[data-page="generate"] .page-inner::before { left: 0.2rem; }
.page[data-page="generate"] .page-inner::after { right: 0.2rem; }

.top-bar {
  min-height: 80px;
  padding: calc(env(safe-area-inset-top, 0px) + 0.85rem) 1.1rem 0.9rem;
  height: auto;
  background: linear-gradient(180deg, rgba(247,241,232,0.88), rgba(243,236,226,0.72));
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(154,122,72,0.34);
  box-shadow: 0 1px 0 rgba(255,255,255,0.75);
}
.top-bar::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(111,130,163,0.12), transparent 25%, transparent 75%, rgba(111,130,163,0.12));
  opacity: 0.65;
  pointer-events: none;
}
.top-bar::after {
  left: 1.2rem;
  right: 1.2rem;
  bottom: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(179,140,58,0.2) 12%, rgba(179,140,58,0.75) 50%, rgba(179,140,58,0.2) 88%, transparent);
  opacity: 1;
}
.top-logo {
  gap: 0.85rem;
  font-family: 'IM Fell English', serif;
  font-size: clamp(1.7rem, 4.9vw, 2.2rem);
  letter-spacing: 0.01em;
  align-items: center;
}
.top-logo-wordmark {
  display: inline-block;
  line-height: 1;
  padding-bottom: 0.04em;
  text-shadow: 0 1px 0 rgba(255,255,255,0.55);
}
.top-logo-badge {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  position: relative;
  flex: 0 0 52px;
  border: 1px solid rgba(143,107,34,0.5);
  background:
    radial-gradient(circle at 50% 48%, rgba(113,177,211,0.95) 0 16%, rgba(61,78,118,0.9) 17% 22%, transparent 23%),
    radial-gradient(circle at 52% 45%, rgba(241,194,114,0.95), rgba(176,120,55,0.7) 35%, transparent 36%),
    linear-gradient(135deg, rgba(255,251,244,0.95), rgba(233,220,197,0.9));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.78),
    0 6px 18px rgba(61,45,31,0.12);
}
.top-logo-badge::before,
.top-logo-badge::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 11px;
  pointer-events: none;
}
.top-logo-badge::before {
  border: 1px solid rgba(143,107,34,0.24);
  background:
    conic-gradient(from 0deg, transparent 0 15%, rgba(143,107,34,0.8) 18% 24%, transparent 27% 47%, rgba(143,107,34,0.8) 50% 58%, transparent 61% 84%, rgba(143,107,34,0.8) 87% 94%, transparent 96% 100%);
  opacity: 0.9;
}
.top-logo-badge::after {
  border: 1px solid rgba(255,255,255,0.4);
  box-shadow: inset 0 0 18px rgba(143,107,34,0.12);
}
.logo-ornament { display:none; }
.install-btn {
  padding: 0.55rem 0.85rem;
  min-height: 42px;
  border-radius: 999px;
}

.gen-header,
.hero-shell {
  margin-top: 0.85rem;
  padding: 2.3rem 1.4rem 1.8rem;
  border-radius: 28px;
  border: 1px solid rgba(167,134,84,0.26);
  background:
    linear-gradient(180deg, rgba(255,248,239,0.68), rgba(251,246,239,0.58)),
    radial-gradient(circle at 50% 22%, rgba(255,255,255,0.72), transparent 35%),
    var(--story-bg);
  background-size: auto, auto, cover;
  background-position: center, center, center top;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.36),
    0 18px 40px rgba(67,48,31,0.08);
}
.gen-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 33%, rgba(173,144,84,0.14), transparent 17%),
    radial-gradient(circle at 50% 33%, rgba(111,130,163,0.13), transparent 35%),
    linear-gradient(90deg, rgba(111,130,163,0.08), transparent 18%, transparent 82%, rgba(111,130,163,0.08));
  opacity: 0.92;
}
.gen-header::after {
  width: 170px;
  max-width: 170px;
  margin-top: 1.15rem;
  height: 16px;
  background: none;
  border-top: 1px solid rgba(171,136,82,0.45);
  position: relative;
}
.hero-shell::after {
  content: '✧';
  display: block;
  color: rgba(171,136,82,0.7);
  font-size: 0.95rem;
  letter-spacing: 0.4em;
  margin: 0.1rem auto 0;
  text-indent: 0.45em;
}
.eyebrow {
  color: rgba(95,77,53,0.82);
  font-size: 0.78rem;
  letter-spacing: 0.34em;
  margin-bottom: 0.9rem;
}
.gen-header > * { position: relative; z-index: 1; }
h1 {
  font-size: clamp(2.7rem, 8vw, 4rem);
  line-height: 0.95;
  color: #422e22;
  text-shadow: 0 1px 0 rgba(255,255,255,0.62);
}
h1 em {
  color: var(--story-gold-deep);
  font-style: italic;
}
.subtitle {
  margin-top: 1rem;
  font-family: 'Cormorant Garamond', serif;
  font-size: clamp(1.35rem, 4.4vw, 1.95rem);
  line-height: 1.12;
  color: #523a2d;
}

.controls.study-controls {
  position: relative;
  gap: 0.9rem 1rem;
  margin-top: 1.05rem;
}
.ctrl-group {
  background: transparent;
}
.ctrl-group::before {
  left: 0.85rem;
  top: 2.75rem;
  font-size: 1rem;
  color: rgba(143,107,34,0.9);
}
.ctrl-group label {
  padding-left: 0.2rem;
  color: #755a35;
  font-size: 0.72rem;
  letter-spacing: 0.22em;
}
.field-select,
.select-wrap {
  position: relative;
}
.field-select::before,
.field-select::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 18px;
  height: 42px;
  transform: translateY(-50%);
  border: 1px solid rgba(160,124,74,0.42);
  background: linear-gradient(180deg, rgba(247,234,202,0.95), rgba(222,201,159,0.92));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.55);
  z-index: 1;
  pointer-events: none;
}
.field-select::before {
  left: 0;
  border-radius: 12px 0 0 12px;
  border-right: none;
}
.field-select::after {
  right: 0;
  border-radius: 0 12px 12px 0;
  border-left: none;
}
select,
.settings-input {
  min-height: 60px;
  padding-left: 2.8rem;
  padding-right: 2.6rem;
  border-radius: 18px;
  border: 1px solid rgba(160,124,74,0.42);
  background:
    linear-gradient(180deg, rgba(255,250,244,0.96), rgba(245,238,225,0.98));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.82), 0 8px 20px rgba(72,54,35,0.06);
}
.btn-generate,
.btn-primary {
  min-height: 58px;
  border-radius: 18px;
  border: 1px solid rgba(127,138,169,0.56);
  color: #f9f6f0;
  background:
    linear-gradient(180deg, rgba(161,180,212,0.92), rgba(118,138,177,0.96)),
    linear-gradient(90deg, rgba(255,255,255,0.18), rgba(231,201,138,0.18));
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.42),
    inset 0 -1px 0 rgba(92,106,140,0.4),
    0 12px 24px rgba(67,55,42,0.12);
  font-family: 'IM Fell English', serif;
  letter-spacing: 0.06em;
  font-size: 1.05rem;
  text-transform: none;
}
.btn-generate::after,
.btn-primary::after {
  opacity: 0.18;
  background: linear-gradient(135deg, transparent 20%, rgba(255,255,255,0.26) 50%, transparent 75%);
}
.btn-generate:hover,
.btn-primary:hover {
  color: #fffdf9;
}
.btn-sm,
.btn-regen,
.btn-icon {
  border-radius: 999px;
  border: 1px solid rgba(160,124,74,0.52);
  background: linear-gradient(180deg, rgba(255,251,245,0.96), rgba(243,234,220,0.98));
  color: #6b5334;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.82);
}
.btn-sm.accent {
  border-color: rgba(127,138,169,0.56);
  background: linear-gradient(180deg, rgba(161,180,212,0.92), rgba(118,138,177,0.96));
  color: #fbf8f2;
}

.prompt-card,
.direction-studio,
.generated-ref-card,
.settings-section,
.hist-item,
.streak-card,
.ref-board,
.empty-state {
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255,250,244,0.92), rgba(246,239,227,0.96));
  border: 1px solid rgba(163,131,86,0.26);
  box-shadow: var(--story-shadow);
  position: relative;
  overflow: hidden;
}
.prompt-card::before,
.direction-studio::before,
.generated-ref-card::before,
.settings-section::before,
.hist-item::before,
.streak-card::before,
.ref-board::before,
.empty-state::before {
  content: '';
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(163,131,86,0.16);
  border-radius: 22px;
  pointer-events: none;
}
.prompt-card::after,
.direction-studio::after,
.generated-ref-card::after,
.settings-section::after,
.hist-item::after,
.streak-card::after,
.ref-board::after,
.empty-state::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 14% 10%, rgba(255,255,255,0.42), transparent 14%),
    radial-gradient(circle at 86% 86%, rgba(111,130,163,0.06), transparent 16%);
  pointer-events: none;
}
.char-name,
.page-title-row h2 {
  font-family: 'IM Fell English', serif;
  font-size: clamp(2.1rem, 7vw, 3rem);
  letter-spacing: -0.01em;
  color: #3c2c21;
}
.char-archetype {
  font-family: 'DM Mono', monospace;
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: #8d6f43;
}
.section-title,
.settings-section-title,
.ref-board-title,
.direction-title,
.direction-kicker,
.generated-ref-kicker,
.comp-kicker {
  color: #9e7730;
  letter-spacing: 0.22em;
  font-size: 0.72rem;
}
.section p,
.direction-copy,
.palette-choice-desc,
.pill-value,
.generated-ref-empty,
.generated-ref-status,
.generated-ref-error,
.settings-hint,
.empty-state p,
.hist-empty p {
  font-family: 'Cormorant Garamond', serif;
  font-size: 1.05rem;
  line-height: 1.45;
  color: #5f4d39;
}
.tip-box {
  background: linear-gradient(180deg, rgba(247,239,228,0.92), rgba(241,233,219,0.95));
  border: 1px solid rgba(163,131,86,0.2);
  border-radius: 20px;
}
.palette-card {
  background: rgba(255,255,255,0.36);
  border-radius: 18px;
  border: 1px solid rgba(163,131,86,0.16);
}
.ref-board {
  background:
    linear-gradient(180deg, rgba(254,250,244,0.94), rgba(243,236,223,0.98)),
    linear-gradient(90deg, rgba(111,130,163,0.06), transparent 20%, transparent 80%, rgba(111,130,163,0.06));
}
.ref-tab {
  border-radius: 999px;
  padding: 0.7rem 1rem;
}
.ref-grid {
  gap: 0.75rem;
}
.img-cell {
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid rgba(163,131,86,0.18);
  box-shadow: 0 8px 18px rgba(67,55,42,0.06);
}
.direction-studio {
  margin-top: 1.1rem;
  padding: 1.15rem;
  background:
    linear-gradient(180deg, rgba(255,250,244,0.9), rgba(247,239,228,0.96)),
    linear-gradient(90deg, rgba(111,130,163,0.06), transparent 22%, transparent 78%, rgba(111,130,163,0.06));
}
.style-preset {
  border-radius: 18px;
  background: rgba(255,255,255,0.5);
}
.style-preset.selected,
.palette-choice-card.selected,
.comp-card.selected,
.comp-hero.selected,
.img-cell.selected {
  border-color: rgba(158,119,48,0.72);
  box-shadow: 0 0 0 1px rgba(179,140,58,0.22), 0 12px 24px rgba(67,55,42,0.08);
  background: linear-gradient(180deg, rgba(255,253,249,0.98), rgba(246,239,227,0.98));
}
.generated-ref-card {
  margin-top: 1.1rem;
  padding: 1.15rem;
}
.generated-ref-meta,
.direction-ready,
.pill-label,
.palette-choice-header,
.style-preset-name,
.tab-label,
.ctrl-group label {
  font-family: 'DM Mono', monospace;
  text-transform: uppercase;
}
.generated-ref-error {
  background: rgba(173,84,72,0.08);
  border: 1px solid rgba(173,84,72,0.12);
}
.tab-bar {
  background: linear-gradient(180deg, rgba(248,242,233,0.84), rgba(243,236,225,0.88));
  border-top: 1px solid rgba(154,122,72,0.3);
  box-shadow: 0 -8px 24px rgba(67,55,42,0.06);
}
.tab-btn.active {
  color: #9e7730;
}
.tab-btn.active svg {
  filter: drop-shadow(0 0 6px rgba(179,140,58,0.22));
}

@media (max-width: 640px) {
  .top-bar {
    min-height: 72px;
    padding: calc(env(safe-area-inset-top, 0px) + 0.65rem) 0.95rem 0.8rem;
  }
  .top-logo { font-size: 1.35rem; gap: 0.65rem; }
  .top-logo-badge { width: 40px; height: 40px; flex-basis: 40px; border-radius: 12px; }
  .page-inner { padding-left: 1rem; padding-right: 1rem; }
  .page[data-page="generate"] .page-inner::before,
  .page[data-page="generate"] .page-inner::after { opacity: 0.24; }
  .gen-header,
  .hero-shell { padding: 1.85rem 1rem 1.45rem; border-radius: 24px; }
  h1 { font-size: clamp(2.2rem, 11vw, 3.1rem); }
  .subtitle { font-size: clamp(1.15rem, 6vw, 1.55rem); }
  .controls { grid-template-columns: 1fr; }
  .prompt-card,
  .direction-studio,
  .generated-ref-card,
  .settings-section,
  .hist-item,
  .streak-card,
  .ref-board,
  .empty-state { border-radius: 24px; }
  .prompt-card::before,
  .direction-studio::before,
  .generated-ref-card::before,
  .settings-section::before,
  .hist-item::before,
  .streak-card::before,
  .ref-board::before,
  .empty-state::before { inset: 10px; border-radius: 18px; }
}
