:root {
  --night: #17132f;
  --night-soft: #282046;
  --ink: #28223a;
  --muted: #746d82;
  --cream: #fbf7ef;
  --paper: #fffdf8;
  --gold: #e4a94b;
  --gold-dark: #c98527;
  --violet: #6f5aa8;
  --line: #e8e0d5;
  --shadow: 0 24px 70px rgba(28, 20, 47, 0.14);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--cream);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

.stars {
  position: absolute;
  inset: 0 0 auto;
  height: 470px;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 28%, rgba(255,255,255,.75) 0 1px, transparent 2px),
    radial-gradient(circle at 79% 18%, rgba(255,255,255,.62) 0 1px, transparent 2px),
    radial-gradient(circle at 92% 60%, rgba(255,255,255,.7) 0 1px, transparent 2px),
    radial-gradient(circle at 35% 70%, rgba(255,255,255,.45) 0 1px, transparent 2px),
    linear-gradient(145deg, #18142f 0%, #29204b 55%, #44335e 100%);
  z-index: -1;
}

.topbar {
  max-width: 1180px;
  margin: auto;
  height: 92px;
  padding: 20px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
}

.brand { color: inherit; text-decoration: none; display: flex; gap: 13px; align-items: center; }
.brand-mark { font-size: 36px; color: #f1c167; transform: rotate(-18deg); }
.brand strong { font: 700 20px/1.1 Georgia, serif; display: block; }
.brand small { color: #cfc7dc; display: block; margin-top: 4px; }
.ghost { border: 1px solid rgba(255,255,255,.3); color: white; background: rgba(255,255,255,.06); }
.account-actions { display: flex; gap: 8px; align-items: center; }
.account-actions > span { color: #d8d0e3; font-size: 13px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.ghost.compact { padding-inline: 12px; }

button { font: inherit; cursor: pointer; border-radius: 12px; padding: 12px 17px; border: 0; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 3px solid rgba(228,169,75,.4); outline-offset: 2px; }

.layout { max-width: 1180px; margin: auto; padding: 0 28px 80px; }
.hero { color: white; text-align: center; padding: 50px 12px 78px; }
.eyebrow { margin: 0 0 10px; color: var(--gold); text-transform: uppercase; font-size: 12px; letter-spacing: .18em; font-weight: 800; }
.hero h1 { font: 600 clamp(36px, 5vw, 62px)/1.07 Georgia, serif; margin: 0 auto 20px; letter-spacing: -.02em; }
.hero > p:last-child { max-width: 700px; margin: auto; color: #ddd6e7; line-height: 1.7; font-size: 17px; }

.workspace {
  background: var(--paper);
  box-shadow: var(--shadow);
  border: 1px solid rgba(255,255,255,.7);
  border-radius: 24px;
  min-height: 520px;
  display: grid;
  grid-template-columns: 300px 1fr;
  overflow: hidden;
}
.children-panel { padding: 28px; background: #f5efe7; border-right: 1px solid var(--line); }
.story-form { padding: 28px 34px 34px; }
.section-title { display: flex; align-items: center; justify-content: space-between; font: 700 18px Georgia, serif; margin-bottom: 22px; }
.step { background: #e6dff1; color: var(--violet); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font: 700 13px sans-serif; }
.children-list { display: grid; gap: 10px; }
.child-card { width: 100%; text-align: left; background: transparent; border: 1px solid transparent; padding: 13px; display: flex; gap: 12px; align-items: center; color: var(--ink); }
.child-card.active { background: white; border-color: #ded4c5; box-shadow: 0 7px 20px rgba(58,43,72,.08); }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: #e6dff1; color: var(--violet); display: grid; place-items: center; font: 700 18px Georgia, serif; flex: none; }
.child-card strong, .child-card small { display: block; }
.child-card small { color: var(--muted); margin-top: 3px; }
.add-card { width: 100%; margin-top: 18px; border: 1px dashed #cdbfae; color: var(--muted); background: transparent; }

label { display: grid; gap: 8px; color: #504959; font-size: 14px; font-weight: 650; }
input, textarea, select { width: 100%; border: 1px solid var(--line); background: white; border-radius: 12px; padding: 13px 14px; font: 400 15px/1.45 inherit; color: var(--ink); }
textarea { min-height: 92px; resize: vertical; }
.story-form > label > textarea { min-height: 120px; }
.two-cols, .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 16px; }
.controls { grid-template-columns: 1fr 1fr; padding-top: 4px; }
.primary { background: linear-gradient(135deg, var(--gold), #d7902c); color: #2f210f; font-weight: 800; box-shadow: 0 8px 20px rgba(201,133,39,.25); }
.story-form > .primary { width: 100%; margin-top: 22px; padding: 16px; }
.primary:disabled { opacity: .6; cursor: wait; }
.status { margin: 12px 0 0; min-height: 21px; color: var(--muted); text-align: center; }
.status.error { color: #9e3e3e; }

.library-section { padding: 80px 0 0; }
.library-section h2 { margin: 0; font: 600 34px Georgia, serif; }
.tales-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-top: 28px; }
.tale-card { background: white; border: 1px solid var(--line); border-radius: 18px; padding: 22px; box-shadow: 0 12px 35px rgba(45,34,62,.06); cursor: pointer; transition: transform .2s, box-shadow .2s; }
.tale-card:hover { transform: translateY(-3px); box-shadow: 0 18px 40px rgba(45,34,62,.11); }
.tale-card time { color: var(--gold-dark); font-size: 12px; font-weight: 800; }
.tale-card h3 { font: 600 23px Georgia, serif; margin: 10px 0; }
.tale-card p { color: var(--muted); line-height: 1.55; margin: 0; }
.muted { color: var(--muted); }

dialog { border: 0; padding: 0; border-radius: 22px; box-shadow: var(--shadow); width: min(650px, calc(100% - 32px)); background: var(--paper); }
dialog [hidden] { display: none !important; }
dialog::backdrop { background: rgba(17,13,31,.72); backdrop-filter: blur(4px); }
dialog form { padding: 30px; display: grid; gap: 16px; }
.dialog-head { display: flex; justify-content: space-between; align-items: start; }
.dialog-head h2 { margin: 0; font: 600 30px Georgia, serif; }
.close { background: #eee8df; width: 38px; height: 38px; padding: 0; font-size: 24px; }
.reader-dialog { max-width: 760px; padding: 42px; max-height: 88vh; }
.reader-dialog article { font: 18px/1.8 Georgia, serif; white-space: pre-wrap; }
.reader-dialog article h1 { font-size: 38px; line-height: 1.15; }
.close-reader { display: block; margin: 26px auto 0; background: var(--night-soft); color: white; }
.auth-dialog { width: min(820px, calc(100% - 32px)); }
.auth-shell { display: grid; grid-template-columns: .85fr 1.15fr; min-height: 500px; }
.auth-copy { padding: 44px 38px; color: white; background: linear-gradient(145deg, var(--night), #44335e); }
.auth-copy .brand-mark { display: block; margin-bottom: 50px; }
.auth-copy h2 { font: 600 38px/1.1 Georgia, serif; margin: 0 0 18px; }
.auth-copy > p:last-child { color: #d9d1e3; line-height: 1.7; }
.auth-forms { padding: 42px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; padding: 4px; background: #f0ebe4; border-radius: 13px; margin-bottom: 28px; }
.auth-tab { background: transparent; color: var(--muted); }
.auth-tab.active { background: white; color: var(--ink); box-shadow: 0 3px 12px rgba(40,34,58,.08); }
.auth-form { display: grid; gap: 17px; }
.auth-form .primary { margin-top: 5px; padding: 14px; }
.auth-form small { color: var(--muted); font-weight: 400; }
.first-user-note { background: #f4efe0; color: #6d582c; border-radius: 12px; padding: 12px; margin: 0; font-size: 13px; line-height: 1.5; }
.invite-content { position: relative; text-align: center; padding: 38px; }
.invite-content .close { position: absolute; right: 18px; top: 18px; }
.invite-content h2 { font: 600 30px Georgia, serif; margin: 0; }
.invite-code { display: block; padding: 18px; margin: 24px 0; background: #f2ede5; border: 1px dashed #c9bba7; border-radius: 12px; font: 800 22px ui-monospace, monospace; letter-spacing: .08em; }

@media (max-width: 780px) {
  .topbar { height: 78px; padding: 15px 18px; }
  .brand small, .account-actions > span, #new-child-button { display: none; }
  .topbar .ghost.compact { display: inline-block; }
  .layout { padding: 0 14px 50px; }
  .hero { padding: 36px 0 55px; }
  .hero h1 br { display: none; }
  .workspace { grid-template-columns: 1fr; }
  .children-panel { border-right: 0; border-bottom: 1px solid var(--line); padding: 22px; }
  .story-form { padding: 24px 20px; }
  .two-cols, .controls { grid-template-columns: 1fr; }
  .tales-list { grid-template-columns: 1fr; }
  .library-section { padding-top: 55px; }
  .reader-dialog { padding: 25px; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-copy { padding: 28px; min-height: 190px; }
  .auth-copy .brand-mark { display: none; }
  .auth-copy h2 { font-size: 30px; }
  .auth-forms { padding: 28px 22px; }
}

.feedback-form { border-top: 1px solid var(--line); margin-top: 28px; }
.feedback-form h2, .feedback-form p { margin: 0; }
.feedback-form fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 18px; min-width: 0; }
.feedback-tags { display: flex; flex-wrap: wrap; gap: 10px; }
.feedback-tags label { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; cursor: pointer; }
.feedback-tags input { width: auto; margin: 0; accent-color: var(--night); }
.feedback-tags span { margin: 0; }
.feedback-card { padding: 20px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.feedback-card h3 { margin: 0; }
.feedback-comment { white-space: pre-wrap; }
.feedback-pagination { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }

.generation-section { margin-top: 40px; }
.generation-section h2 { margin: 0; font: 600 28px Georgia, serif; }
.generation-list { display: grid; gap: 12px; }
.generation-card { display: grid; gap: 12px; background: white; border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.generation-card small { color: var(--muted); }
.generation-card p { margin: 0; }
.generation-card button { justify-self: start; }

.account-dialog-head { padding: 28px 30px 0; }
.account-dialog-status { padding: 0 30px 28px; }
.account-confirm { display: flex; align-items: flex-start; gap: 10px; }
.account-confirm input { width: auto; margin-top: 4px; }
.danger { background: #8e2939; color: white; }
#delete-account-form { border-top: 1px solid var(--line); }
