:root {
  color-scheme: light;
  --pink-950: #5a2036;
  --pink-850: #733149;
  --pink-700: #b84e73;
  --pink-600: #d65f87;
  --pink-500: #ef7da1;
  --pink-300: #f7b6ca;
  --pink-200: #fbd0dc;
  --pink-100: #ffe5ed;
  --pink-50: #fff5f8;
  --cream: #fffaf7;
  --paper: #ffffff;
  --ink: #3c2530;
  --muted: #7d6570;
  --line: rgba(159, 75, 108, 0.18);
  --shadow: 0 14px 34px rgba(91, 45, 63, 0.12);
  --shadow-small: 0 8px 20px rgba(91, 45, 63, 0.09);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; background: #f8eaf0; }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(255,255,255,.95), transparent 31rem),
    linear-gradient(180deg, #fff7fa 0%, #f8e8ef 100%);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
img { max-width: 100%; display: block; }
textarea { resize: vertical; }

.app-shell { min-height: 100vh; padding-bottom: calc(92px + var(--safe-bottom)); }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px clamp(16px, 4vw, 36px);
  border-bottom: 1px solid rgba(155, 74, 105, .12);
  background: rgba(255, 249, 251, .94);
  box-shadow: 0 8px 22px rgba(91, 45, 63, .06);
}
.brand-group { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-icon { width: 42px; height: 42px; border-radius: 14px; object-fit: cover; box-shadow: var(--shadow-small); }
.brand-group h1 { margin: 1px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1rem, 2.8vw, 1.35rem); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.eyebrow { margin: 0 0 5px; font-weight: 800; letter-spacing: .12em; font-size: .67rem; color: var(--pink-700); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.save-state { font-size: .76rem; color: var(--muted); white-space: nowrap; }

main { width: min(1220px, 100%); margin: 0 auto; padding: clamp(18px, 4vw, 34px); }
.view { display: none; animation: fadeIn .26s ease; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.artwork-layer { position: relative; overflow: hidden; border-radius: var(--radius-xl); box-shadow: var(--shadow); isolation: isolate; }
.hero-stage { min-height: min(680px, 74vh); display: grid; align-items: end; background: var(--pink-100); }
.hero-art {
  position: absolute;
  inset: 0;
  z-index: -2;
  background-image:
    linear-gradient(180deg, rgba(255, 242, 247, .05), rgba(103, 35, 60, .27)),
    url("assets/app-cover.jpg");
  background-size: cover;
  background-position: 50% 26%;
  transform: scale(1.015);
}
.hero-stage::after, .cafe-stage::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: linear-gradient(180deg, transparent 42%, rgba(71, 24, 42, .16));
}
.scene-reading-layer {
  background: linear-gradient(180deg, rgba(255, 232, 240, .73), rgba(255, 247, 250, .9));
  border: 1px solid rgba(255, 245, 248, .9);
  box-shadow: 0 12px 32px rgba(92, 42, 64, .14);
}
.hero-content { margin: clamp(14px, 3vw, 30px); padding: clamp(22px, 4vw, 42px); border-radius: 26px; max-width: 720px; }
.hero-content h2, .section-heading h2, .scene-header h2 { font-family: Georgia, "Times New Roman", serif; }
.hero-content h2 { margin: 0 0 14px; font-size: clamp(2rem, 7vw, 4.5rem); line-height: .98; color: var(--pink-950); }
.hero-content p:not(.eyebrow) { max-width: 62ch; line-height: 1.72; margin: 0; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 24px; }

.primary-button, .secondary-button, .danger-button, .text-button, .copy-button, .file-button {
  border-radius: 14px;
  border: 0;
  min-height: 44px;
  padding: 11px 16px;
  font-weight: 800;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}
.primary-button { color: #fff; background: linear-gradient(135deg, var(--pink-600), #ea8cac); box-shadow: 0 9px 20px rgba(202, 77, 119, .25); }
.secondary-button { color: var(--pink-850); background: #fff; border: 1px solid rgba(171, 78, 112, .22); box-shadow: var(--shadow-small); }
.danger-button { color: #fff; background: #9d3e56; }
.text-button { min-height: 36px; color: var(--pink-700); background: transparent; padding: 8px 4px; }
.copy-button { min-height: 36px; padding: 7px 11px; color: var(--pink-850); background: var(--pink-50); border: 1px solid var(--line); font-size: .78rem; }
.primary-button:hover, .secondary-button:hover, .danger-button:hover, .copy-button:hover { transform: translateY(-1px); }
.primary-button.small, .secondary-button.small { min-height: 38px; padding: 8px 12px; font-size: .8rem; }
.full { width: 100%; }

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--pink-850);
  background: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-small);
}
.icon-button svg, .bottom-nav svg, .action-dock svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.section-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin: 42px 0 18px; }
.section-heading.compact { margin-top: 34px; }
.section-heading h2 { margin: 0; font-size: clamp(1.55rem, 4vw, 2.6rem); line-height: 1.08; }
.section-heading p:not(.eyebrow) { margin: 10px 0 0; color: var(--muted); line-height: 1.6; max-width: 72ch; }

.card-grid { display: grid; gap: 16px; }
.card-grid.two-column { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card-grid.three-column { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.white-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-small);
}
.feature-card { padding: 22px; min-height: 182px; }
.feature-card h3 { margin: 18px 0 8px; }
.feature-card p { margin: 0; color: var(--muted); line-height: 1.6; }
.card-number { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 14px; color: var(--pink-850); background: var(--pink-100); font-weight: 900; }
.home-source-card { padding: 18px; display: flex; gap: 14px; align-items: flex-start; }
.home-source-card img { width: 72px; height: 90px; border-radius: 14px; object-fit: cover; }
.home-source-card h3 { margin: 0 0 6px; font-size: 1rem; }
.home-source-card p { margin: 0; color: var(--muted); font-size: .86rem; line-height: 1.5; }

/* Cafe */
.cafe-stage {
  min-height: calc(100vh - 215px);
  display: flex;
  align-items: stretch;
  background-color: #f3dce5;
  background-image:
    linear-gradient(180deg, rgba(255, 237, 244, .12), rgba(71, 24, 42, .27)),
    var(--cafe-image, url("assets/cafe-character.jpg"));
  background-size: cover;
  background-position: center;
}
.cafe-veil { width: min(840px, calc(100% - 28px)); margin: 14px; padding: clamp(16px, 3vw, 28px); border-radius: 26px; display: flex; flex-direction: column; }
.status-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.status-strip span, .composer-meta span, .status-badge { padding: 7px 10px; border-radius: 999px; background: rgba(255,255,255,.88); border: 1px solid rgba(171,78,112,.18); font-size: .74rem; font-weight: 800; }
.scene-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.scene-header h2 { margin: 0 0 6px; font-size: clamp(1.6rem, 5vw, 2.7rem); }
.scene-header p:not(.eyebrow) { margin: 0; color: var(--muted); }
.conversation-feed { flex: 1; min-height: 290px; max-height: 52vh; overflow-y: auto; padding: 22px 4px; display: flex; flex-direction: column; gap: 12px; scrollbar-width: thin; }
.message { max-width: min(86%, 610px); padding: 13px 15px; border-radius: 18px; box-shadow: 0 6px 16px rgba(92,42,64,.08); line-height: 1.58; white-space: pre-wrap; }
.message.character { align-self: flex-start; background: rgba(255,255,255,.95); border-bottom-left-radius: 6px; }
.message.user { align-self: flex-end; color: #fff; background: linear-gradient(135deg, #d66086, #ec8fac); border-bottom-right-radius: 6px; }
.message.system { align-self: center; max-width: 96%; font-size: .82rem; color: var(--pink-850); background: rgba(255,244,248,.92); border: 1px dashed rgba(171,78,112,.28); text-align: center; }
.message-meta { display: block; font-size: .67rem; opacity: .7; margin-bottom: 4px; font-weight: 900; letter-spacing: .04em; }
.composer-panel { padding: 14px; border-radius: 20px; background: rgba(255,255,255,.86); border: 1px solid rgba(171,78,112,.16); }
.composer-panel > label { display: block; margin-bottom: 8px; font-size: .78rem; font-weight: 800; }
.composer-row { display: flex; gap: 10px; align-items: stretch; }
.composer-row textarea { flex: 1; min-height: 62px; }
.send-button { width: 82px; }
.composer-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 9px; }
.action-dock { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-top: 12px; }
.action-dock button { min-height: 70px; border: 1px solid var(--line); border-radius: 18px; color: var(--pink-850); background: #fff; box-shadow: var(--shadow-small); display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px; font-weight: 800; font-size: .75rem; }

/* Forms */
input, textarea, select {
  width: 100%;
  color: var(--ink);
  background: #fff;
  border: 1px solid rgba(150, 80, 105, .23);
  border-radius: 13px;
  padding: 12px 13px;
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease;
}
input:focus, textarea:focus, select:focus { border-color: var(--pink-500); box-shadow: 0 0 0 4px rgba(239,125,161,.12); }
label { display: grid; gap: 7px; font-size: .8rem; font-weight: 800; color: var(--pink-850); }
.helper-text { color: var(--muted); font-size: .78rem; line-height: 1.55; }

/* Work cards */
.work-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.work-card { overflow: hidden; }
.work-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 18px 12px; }
.work-card-header h3 { margin: 0; font-size: 1rem; }
.work-card-actions { display: flex; gap: 7px; }
.work-card-body { padding: 0 18px 18px; }
.work-card-guide { margin: 0 0 12px; padding: 12px 14px; border-radius: 14px; color: var(--muted); background: var(--pink-50); line-height: 1.55; font-size: .84rem; }
.work-card textarea { min-height: 210px; }
.work-card.collapsed .work-card-body { display: none; }
.source-heading { margin-top: 52px; }
.source-browser { overflow: hidden; }
.source-toolbar { display: grid; grid-template-columns: 1fr minmax(220px, 2fr) auto; gap: 12px; align-items: end; padding: 18px; border-bottom: 1px solid var(--line); }
.source-layout { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(290px, .55fr); min-height: 620px; }
.source-reader { padding: 20px; max-height: 72vh; overflow-y: auto; border-right: 1px solid var(--line); }
.source-reader h2 { margin-top: 0; font-family: Georgia, "Times New Roman", serif; }
.source-reader p { line-height: 1.65; margin: 0 0 10px; }
.source-reader .source-block { padding: 13px 15px; margin-bottom: 10px; background: #fff; border: 1px solid var(--line); border-radius: 14px; }
.source-reader .source-block.heading-like { color: var(--pink-850); font-weight: 900; background: #fff8fa; }
.source-note-panel { padding: 18px; background: #fff8fa; }
.sticky-note-card { position: sticky; top: 90px; }
.card-title-row { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
.card-title-row h3 { margin: 0; }
.source-note-panel textarea { min-height: 430px; }

/* Context */
.context-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(290px, .5fr); gap: 16px; align-items: start; }
.context-controls, .token-meter-card, .api-card, .compiled-card { padding: 18px; }
.context-sidebar { display: grid; gap: 16px; position: sticky; top: 84px; }
.field-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.preset-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.preset-row button { border: 1px solid var(--line); color: var(--pink-850); background: var(--pink-50); border-radius: 999px; padding: 8px 11px; font-weight: 800; font-size: .76rem; }
.context-domain-fields { display: grid; gap: 12px; }
.context-field { padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: #fff; }
.context-field-header { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.context-field-title { font-weight: 900; color: var(--pink-850); }
.context-field-token { font-size: .72rem; color: var(--muted); }
.context-field textarea { min-height: 94px; }
.meter { height: 12px; border-radius: 999px; overflow: hidden; background: #f2dbe3; margin: 14px 0 10px; }
.meter span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, #6ca87f, #e7a443, #bf4f68); transition: width .2s ease; }
.status-badge { color: #27643b; background: #ecf8ef; border-color: #cce7d3; }
.status-badge.warning { color: #805015; background: #fff6df; border-color: #eddba8; }
.status-badge.danger { color: #853148; background: #fff0f3; border-color: #efcad5; }
.api-card label { margin-top: 12px; }
.compiled-card { margin-top: 16px; }
.compiled-card textarea { min-height: 320px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; }

/* Social */
.npc-card { overflow: hidden; }
.npc-cover { height: 140px; background-size: cover; background-position: center; }
.npc-card-body { padding: 18px; }
.npc-avatar-row { display: flex; gap: 12px; align-items: center; margin-top: -46px; }
.npc-avatar { width: 76px; height: 76px; border-radius: 24px; object-fit: cover; border: 4px solid #fff; box-shadow: var(--shadow-small); }
.npc-card h3 { margin: 12px 0 4px; }
.npc-card p { color: var(--muted); line-height: 1.55; }
.npc-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.npc-tags span { padding: 6px 8px; border-radius: 999px; background: var(--pink-50); border: 1px solid var(--line); font-size: .7rem; font-weight: 800; }
.social-workspace { margin-top: 18px; padding: 18px; }

/* Settings */
.settings-card { padding: 22px; }
.settings-card h3 { margin-top: 0; }
.settings-card p, .settings-card li { color: var(--muted); line-height: 1.6; }
.button-stack { display: grid; gap: 9px; }
.file-button { display: flex; align-items: center; justify-content: center; text-align: center; color: var(--pink-850); background: #fff; border: 1px solid var(--line); }
.file-button input { display: none; }
.danger-card { border-color: rgba(157,62,86,.24); }

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: max(10px, var(--safe-bottom));
  z-index: 40;
  width: min(760px, calc(100% - 22px));
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
  padding: 8px;
  border: 1px solid rgba(165, 77, 109, .18);
  border-radius: 24px;
  background: rgba(255,255,255,.97);
  box-shadow: 0 18px 42px rgba(87,38,57,.22);
}
.bottom-nav button { min-width: 0; min-height: 58px; border: 0; border-radius: 16px; color: var(--muted); background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: .68rem; font-weight: 800; }
.bottom-nav button.active { color: var(--pink-850); background: var(--pink-100); }
.bottom-nav svg { width: 20px; height: 20px; }

/* Bottom sheet */
.sheet-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(52, 23, 35, .38); }
.bottom-sheet { position: fixed; left: 50%; bottom: 0; z-index: 80; width: min(760px, 100%); max-height: 88vh; overflow-y: auto; transform: translateX(-50%); background: var(--cream); border: 1px solid rgba(165,77,109,.18); border-radius: 28px 28px 0 0; box-shadow: 0 -18px 50px rgba(87,38,57,.25); padding: 10px 18px calc(24px + var(--safe-bottom)); }
.sheet-handle { width: 48px; height: 5px; border-radius: 99px; background: #d9bac5; margin: 0 auto 12px; }
.sheet-header { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.sheet-header h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; }
.sheet-content { padding-top: 16px; }
.sheet-options { display: grid; gap: 10px; }
.sheet-option { display: flex; justify-content: space-between; gap: 14px; align-items: center; width: 100%; text-align: left; padding: 14px; border: 1px solid var(--line); border-radius: 17px; background: #fff; color: var(--ink); }
.sheet-option strong { display: block; color: var(--pink-850); margin-bottom: 4px; }
.sheet-option small { color: var(--muted); line-height: 1.4; }
.sheet-option.selected { border-color: var(--pink-500); background: var(--pink-50); box-shadow: 0 0 0 3px rgba(239,125,161,.11); }
.sheet-option-price { font-weight: 900; white-space: nowrap; }
.order-summary { margin-top: 14px; padding: 14px; border-radius: 16px; background: #fff; border: 1px solid var(--line); }

.toast { position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); z-index: 100; transform: translate(-50%, 18px); opacity: 0; pointer-events: none; color: #fff; background: var(--pink-950); border-radius: 999px; padding: 10px 16px; font-size: .78rem; font-weight: 800; box-shadow: var(--shadow); transition: opacity .2s ease, transform .2s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 900px) {
  .card-grid.three-column { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .work-card-grid { grid-template-columns: 1fr; }
  .source-layout, .context-layout { grid-template-columns: 1fr; }
  .source-reader { border-right: 0; border-bottom: 1px solid var(--line); max-height: 58vh; }
  .source-note-panel { padding-top: 14px; }
  .sticky-note-card, .context-sidebar { position: static; }
  .action-dock { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .save-state { display: none; }
  main { padding: 14px; }
  .hero-stage { min-height: 70vh; }
  .hero-content { margin: 10px; padding: 20px; }
  .hero-content h2 { font-size: clamp(2.1rem, 12vw, 3.4rem); }
  .card-grid.two-column, .card-grid.three-column, .settings-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; flex-direction: column; margin-top: 34px; }
  .source-toolbar { grid-template-columns: 1fr; }
  .cafe-stage { min-height: calc(100vh - 202px); }
  .cafe-veil { width: calc(100% - 16px); margin: 8px; padding: 13px; }
  .scene-header { flex-direction: column; }
  .conversation-feed { min-height: 260px; max-height: 46vh; }
  .composer-row { flex-direction: column; }
  .send-button { width: 100%; }
  .action-dock button { min-height: 62px; }
  .field-row.two { grid-template-columns: 1fr; }
  .bottom-nav { width: calc(100% - 12px); bottom: max(6px, var(--safe-bottom)); border-radius: 20px; padding: 5px; }
  .bottom-nav button { min-height: 54px; font-size: .61rem; }
  .bottom-nav svg { width: 18px; height: 18px; }
  .brand-group h1 { max-width: 180px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
