:root {
  color-scheme: light;
  --paper: #f8f4ec;
  --white: #fffefa;
  --ink: #292b37;
  --muted: #8b8992;
  --purple: #6352a4;
  --purple-dark: #4f418d;
  --lavender: #f0edfa;
  --line: #eee9df;
  --peach: #f5dfcc;
  --serif: "Palatino Linotype", "Book Antiqua", Georgia, serif;
  --sans: "Avenir Next", Avenir, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 15px; }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); font-weight: 700; font-size: 14px; letter-spacing: -.035em; text-decoration: none; }
.brand-mark { display: grid; width: 28px; height: 28px; place-items: center; border-radius: 9px; color: #fff; background: var(--purple); font-size: 15px; }
.eyebrow { color: #a29bab; font-size: 9px; font-weight: 700; letter-spacing: .16em; }
.muted { color: var(--muted); line-height: 1.6; }
.topbar { height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 max(calc((100vw - 1180px)/2), 5vw); background: rgba(255,254,250,.8); border-bottom: 1px solid rgba(54,48,70,.06); }
.top-actions { display: flex; align-items: center; gap: 23px; }
.user-greeting { display: flex; align-items: center; gap: 9px; color: #686674; font-size: 12px; }
.avatar { width: 30px; height: 30px; display: grid; place-items: center; background: #e9e3f7; border-radius: 50%; color: var(--purple); font-weight: 700; }
.text-button { padding: 6px 0; border: 0; background: transparent; color: #777582; font-size: 12px; }
.text-button:hover, .auth-switch a:hover { color: var(--purple); }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 11px; border: 0; border-radius: 12px; font-weight: 600; transition: transform .18s ease, background .18s ease, box-shadow .18s ease; }
.button:active { transform: translateY(1px); }
.button-primary { min-height: 50px; padding: 0 18px; color: white; background: var(--purple); box-shadow: 0 8px 18px rgba(99,82,164,.18); }
.button-primary:hover { background: var(--purple-dark); box-shadow: 0 10px 24px rgba(99,82,164,.25); }
.button-wide { width: 100%; }
.button-install { min-height: 34px; padding: 0 12px; background: var(--lavender); color: var(--purple); font-size: 11px; }
.app-shell { width: min(1120px, calc(100% - 48px)); margin: 0 auto; }
.welcome-row { display: flex; align-items: center; justify-content: space-between; min-height: 157px; position: relative; }
.welcome-row h1 { margin: 8px 0 3px; font: 600 32px/1.2 var(--serif); letter-spacing: -.045em; }
.welcome-row p { margin: 7px 0 0; color: #8b8992; font-size: 13px; }
.wave { color: #dda56e; font: 22px var(--sans); vertical-align: 4px; }
.welcome-doodle { position: absolute; right: 7%; top: 31px; width: 100px; height: 100px; border: 1px solid #e8dfd3; border-radius: 50%; display: grid; place-items: center; color: #d7ad7f; font-size: 42px; transform: rotate(-20deg); }
.welcome-doodle i { position: absolute; right: 8px; top: 7px; color: #a897d1; font-style: normal; font-size: 19px; }
.workspace { display: grid; grid-template-columns: minmax(390px, .92fr) minmax(410px, 1.08fr); gap: 22px; align-items: start; }
.panel { background: var(--white); border: 1px solid rgba(60,50,80,.055); border-radius: 18px; box-shadow: 0 9px 30px rgba(43,37,62,.045); }
.composer { padding: 25px 27px 19px; }
.panel-heading { display: flex; align-items: center; gap: 12px; margin: 0 0 23px; }
.step-badge { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 11px; background: #f0edfa; color: var(--purple); font-size: 10px; font-weight: 700; }
.panel-heading h2, .library-heading h2 { margin: 0; font: 600 20px/1.3 var(--serif); letter-spacing: -.03em; }
.panel-heading p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.composer label { display: block; margin: 16px 0 9px; color: #54525e; font-size: 11px; font-weight: 600; }
.suggestion-label { display: block; margin: 12px 0 7px; color: #a5a1aa; font-size: 9px; }
.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.theme-chip { min-height: 37px; display: flex; align-items: center; gap: 7px; padding: 0 9px; border: 1px solid #eeebf1; border-radius: 9px; background: #fff; color: #696774; text-align: left; font-size: 10px; transition: .15s ease; }
.theme-chip span { font-size: 14px; }
.theme-chip:hover { border-color: #c9c0e8; }
.theme-chip.selected { border-color: #a99bd4; background: #f5f2fc; color: #574995; box-shadow: inset 0 0 0 1px rgba(99,82,164,.08); }
.optional { margin-left: 4px; color: #aaa7b0; font-weight: 400; }
.composer input[type="text"], .composer select { width: 100%; height: 42px; padding: 0 12px; border: 1px solid #eeeaf0; border-radius: 9px; outline: none; background: #fff; color: #62606c; font-size: 11px; }
.composer input::placeholder { color: #b6b3bd; }
.composer input:focus, .composer select:focus { border-color: #a99bd4; box-shadow: 0 0 0 3px rgba(99,82,164,.08); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-row label { margin-top: 15px; }
.generate-button { margin-top: 20px; font-size: 12px; }
.button-spark { font-size: 15px; }
.button-arrow { margin-left: auto; font-size: 16px; }
.form-note { margin: 11px 0 0; color: #a5a1aa; text-align: center; font-size: 9px; }
.story-column { display: grid; gap: 16px; }
.story-card { min-height: 337px; padding: 26px 30px; position: relative; overflow: hidden; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.empty-art { position: relative; width: 114px; height: 90px; display: grid; place-items: center; margin: 1px 0 14px; }
.book { display: grid; width: 67px; height: 70px; place-items: center; border-radius: 7px 14px 14px 7px; background: #eeeaf8; color: #8c7cbd; font: 40px var(--serif); transform: rotate(-5deg); box-shadow: 6px 4px 0 #e3def0; }
.empty-star { position: absolute; color: #d6ae7d; }
.star-a { right: 1px; top: 9px; font-size: 20px; }
.star-b { left: 3px; bottom: 10px; color: #a79acb; font-size: 16px; }
.empty-state h2 { margin: 8px 0; font: 600 25px var(--serif); letter-spacing: -.04em; }
.empty-state p { margin: 0; color: #9b98a1; font-size: 11px; line-height: 1.7; }
.story-card.has-story { min-height: 337px; display: block; padding: 25px 29px 21px; }
.story-meta { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.story-tag { padding: 6px 9px; border-radius: 30px; background: #f2effa; color: var(--purple); font-size: 9px; }
.story-date { color: #aaa7b0; font-size: 9px; }
.story-title { margin: 16px 0 12px; font: 600 25px/1.15 var(--serif); letter-spacing: -.035em; }
.story-text { max-height: 184px; overflow: auto; color: #696774; font: 12px/1.75 var(--serif); white-space: pre-wrap; scrollbar-color: #d8d1e8 transparent; }
.story-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; border-top: 1px solid #f0edf0; margin-top: 16px; padding-top: 12px; }
.rating-control { display: flex; align-items: center; gap: 3px; }
.rating-control span { margin-right: 5px; color: #a29eaa; font-size: 9px; }
.rating-star { padding: 1px; border: 0; background: transparent; color: #d7d2dc; font-size: 16px; }
.rating-star.active { color: #dda85f; }
.rating-star:hover { color: #e4ac55; transform: scale(1.12); }
.save-button { padding: 8px 11px; border: 1px solid #e7e1ef; border-radius: 8px; background: #fff; color: var(--purple); font-size: 10px; font-weight: 600; }
.save-button.saved { border-color: #e7e1ef; background: #f2effa; }
.delete-button { padding: 8px 9px; border: 1px solid #f0d8d2; border-radius: 8px; background: #fff; color: #a75a4a; font-size: 10px; }
.delete-button:hover { background: #fff3f0; }
.library { padding: 21px 23px; }
.library-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
.library-heading h2 { margin-top: 5px; font-size: 19px; }
.count-pill { min-width: 24px; height: 24px; display: grid; place-items: center; border-radius: 20px; background: #f1eef9; color: var(--purple); font-size: 10px; font-weight: 700; }
.saved-list { display: grid; gap: 5px; }
.saved-item { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 9px; border: 0; border-radius: 10px; background: #fbf9fd; text-align: left; }
.saved-item:hover, .recent-item:hover { background: #f4f1f9; }
.saved-icon { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 9px; background: #f0edfa; color: #8979b8; }
.saved-copy { display: grid; flex: 1; min-width: 0; gap: 3px; }
.saved-copy strong { overflow: hidden; color: #55535f; font-size: 10px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.saved-copy small { color: #a39faa; font-size: 9px; }
.saved-arrow { color: #aaa5b7; font-size: 13px; }
.library-empty { margin: 6px 0 12px; color: #aaa7b0; font-size: 10px; line-height: 1.6; }
.recent-block { margin-top: 17px; padding-top: 15px; border-top: 1px solid #f1edf0; }
.recent-block > .eyebrow { display: block; margin-bottom: 8px; }
.recent-block #recent-list { max-height: 225px; overflow-y: auto; }
.recent-item { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 7px 6px; border: 0; border-radius: 6px; background: transparent; color: #777480; text-align: left; font-size: 10px; }
.recent-item span:last-child { color: #aaa5b7; }
.app-footer { padding: 24px 0 20px; color: #aaa5ac; text-align: center; font-size: 8px; letter-spacing: .15em; }
.app-footer span { margin: 0 6px; color: #baa9d7; }
.error-banner { padding: 12px 14px; border: 1px solid #f0c9bd; border-radius: 10px; background: #fff4f0; color: #9a4936; font-size: 11px; }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 20; padding: 10px 16px; border-radius: 10px; background: #302d3b; color: #fff; font-size: 11px; opacity: 0; pointer-events: none; transform: translate(-50%, 8px); transition: .2s ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.loading { opacity: .7; pointer-events: none; }
.loading .button-spark { animation: sparkle .7s ease-in-out infinite alternate; }
@keyframes sparkle { to { transform: rotate(45deg) scale(1.25); } }

/* Authentication */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: #f4f0e9; }
.auth-layout { width: min(1000px, 100%); min-height: min(650px, calc(100vh - 56px)); display: grid; grid-template-columns: .95fr 1.05fr; overflow: hidden; border-radius: 23px; background: var(--white); box-shadow: 0 22px 65px rgba(47,39,68,.11); }
.auth-art { position: relative; min-height: 600px; overflow: hidden; padding: 36px 39px; color: #fff; background: #594c84; }
.brand-light { color: #fff; }
.brand-light .brand-mark { background: rgba(255,255,255,.17); }
.art-copy { position: absolute; z-index: 2; top: 27%; left: 12%; }
.art-copy .eyebrow { color: #c7bddb; }
.art-copy h1 { margin: 17px 0 12px; font: 500 50px/1.08 var(--serif); letter-spacing: -.045em; }
.art-copy h1 em { color: #e9c79e; font-weight: 500; }
.art-copy p { color: #d4ccdf; font-size: 12px; }
.moon-scene { position: absolute; right: -15px; bottom: 48px; width: 310px; height: 210px; border-radius: 50% 50% 0 0; background: rgba(42,38,72,.25); }
.moon { position: absolute; right: 83px; top: -31px; color: #ebcf9f; font-size: 65px; transform: rotate(-20deg); }
.spark { position: absolute; color: #e6d2b0; }
.spark-one { top: 24px; left: 43px; font-size: 23px; }
.spark-two { top: -15px; right: 23px; color: #c2b4dc; font-size: 20px; }
.hill { position: absolute; left: -60px; right: -30px; bottom: -74px; height: 160px; border-radius: 50%; background: #76699b; transform: rotate(-7deg); }
.art-foot { position: absolute; bottom: 26px; left: 39px; color: #c4bbd7; font-size: 8px; letter-spacing: .16em; }
.auth-panel { position: relative; display: grid; place-items: center; padding: 50px 52px 65px; }
.auth-card { width: min(100%, 340px); }
.auth-card > .eyebrow { display: block; margin-bottom: 11px; }
.auth-card h2 { margin: 0; font: 600 29px/1.2 var(--serif); letter-spacing: -.04em; }
.auth-card > .muted { margin: 9px 0 25px; font-size: 12px; }
.auth-form { display: grid; }
.auth-form label { margin: 13px 0 7px; color: #595763; font-size: 11px; font-weight: 600; }
.auth-form input, .auth-form select { width: 100%; height: 44px; padding: 0 12px; border: 1px solid #eae6ed; border-radius: 9px; outline: none; background: #fff; color: var(--ink); font-size: 12px; }
.auth-form input:focus, .auth-form select:focus { border-color: #a99bd4; box-shadow: 0 0 0 3px rgba(99,82,164,.08); }
.auth-form input::placeholder { color: #b3b0bb; }
.auth-form .button { margin-top: 23px; }
.auth-form .button span { margin-left: auto; }
.auth-switch { margin: 18px 0 0; color: #8c8993; text-align: center; font-size: 10px; }
.auth-switch a { margin-left: 3px; color: var(--purple); font-weight: 600; text-decoration: none; }
.privacy-note { margin-top: 22px; color: #aaa7b0; text-align: center; font-size: 9px; }
.panel-footer { position: absolute; bottom: 24px; color: #aaa5ac; font-size: 8px; letter-spacing: .15em; }
.panel-footer span { margin-left: 4px; color: #b6a8d1; }
.flash { margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; font-size: 10px; }
.flash-error { background: #fff0ec; color: #a34935; }
.flash-info { background: #f2effa; color: #594c84; }
.field-error { margin-top: 5px; color: #a34935; font-size: 10px; }
.brand-mobile { display: none; }

@media (max-width: 860px) {
  .topbar { padding: 0 24px; }
  .app-shell { width: min(690px, calc(100% - 36px)); }
  .workspace { grid-template-columns: 1fr; }
  .welcome-row { min-height: 135px; }
  .welcome-doodle { right: 5%; }
  .story-column { grid-row: 1; }
  .story-card { min-height: 310px; }
}
@media (max-width: 540px) {
  .topbar { height: 62px; padding: 0 15px; }
  .top-actions { gap: 10px; }
  .user-greeting { font-size: 0; }
  .avatar { font-size: 12px; }
  .text-button { font-size: 10px; }
  .app-shell { width: calc(100% - 28px); }
  .welcome-row { min-height: 116px; }
  .welcome-row h1 { font-size: 26px; }
  .welcome-doodle { right: 2%; width: 68px; height: 68px; font-size: 33px; }
  .composer { padding: 20px 16px 17px; }
  .panel-heading h2 { font-size: 18px; }
  .theme-chip { font-size: 9px; padding: 0 7px; }
  .story-card { padding: 22px 19px; }
  .story-card.has-story { padding: 21px 18px 18px; }
  .story-title { font-size: 23px; }
  .library { padding: 19px 16px; }
  .auth-page { padding: 0; background: var(--white); }
  .auth-layout { min-height: 100vh; display: block; border-radius: 0; box-shadow: none; }
  .auth-art { display: none; }
  .auth-panel { min-height: 100vh; padding: 25px 27px 65px; }
  .brand-mobile { display: inline-flex; margin-bottom: 54px; }
  .auth-card h2 { font-size: 27px; }
}

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