:root {
  --bg: #171717;
  --panel: #1f1f1f;
  --ink: #f1f1ec;
  --muted: #bebeb8;
  --line: #343434;
  --accent: #2f2f2f;
  --accent-strong: #3b3b3b;
  --danger: #c98d8d;
  --success: #9bc9b3;
  --galaxy: #2a2038;
  --galaxy-soft: #3a2e4a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Cormorant Garamond", "Iowan Old Style", "Baskerville", "Palatino Linotype", Georgia, serif;
  color: var(--ink);
  background: radial-gradient(circle at 15% 0%, #241d2f 0%, #1b1a22 28%, var(--bg) 62%);
  min-height: 100vh;
  line-height: 1.5;
}

button,
input,
textarea,
select,
a {
  font-family: inherit;
}

body.chat-page {
  overflow: hidden;
}

.bg-pattern {
  position: fixed;
  inset: 0;
  background-image: linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
  opacity: 0.35;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, rgba(26, 24, 31, 0.96), rgba(20, 20, 20, 0.96));
  backdrop-filter: blur(6px);
  min-height: 68px;
}

.brand {
  text-decoration: none;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 1.56rem;
  font-weight: 200;
  color: #f3f3ef;
  letter-spacing: 0.6px;
  line-height: 1.1;
}

.user-email {
  color: var(--muted);
  font-size: 0.9rem;
}

.menu-wrap {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
}

.menu-wrap[open] .menu-trigger {
  border-color: #8b7ba6;
}

.menu-trigger {
  list-style: none;
  width: 42px;
  height: 42px;
  border: 1px solid #5b5366;
  border-radius: 10px;
  background: #2f2f2f;
  display: inline-flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  cursor: pointer;
}

.menu-trigger::-webkit-details-marker {
  display: none;
}

.menu-trigger span {
  width: 16px;
  height: 1.6px;
  border-radius: 999px;
  background: #ece7f5;
}

.menu-dropdown {
  position: absolute;
  right: 0;
  margin-top: 8px;
  min-width: 170px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #25232a;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.4);
  padding: 6px;
  display: grid;
  gap: 4px;
}

.menu-dropdown a,
.menu-dropdown button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  text-decoration: none;
  text-align: left;
  width: 100%;
  padding: 9px 10px;
  font: inherit;
  cursor: pointer;
}

.menu-dropdown a:hover,
.menu-dropdown button:hover {
  background: #32303a;
}

.page {
  width: min(860px, calc(100vw - 32px));
  margin: 28px auto 56px;
}

body.chat-page .page {
  width: min(980px, calc(100vw - 28px));
  margin: 14px auto 18px;
  height: calc(100vh - 82px);
}

body.landing-page .page {
  width: 100vw;
  margin: 0;
  height: 100vh;
}

body.landing-page .topbar {
  display: none;
}

.landing-shell {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.landing-shell picture {
  display: block;
  width: 100%;
  height: 100%;
}

.landing-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.landing-enter {
  position: absolute;
  right: 28px;
  bottom: 28px;
  min-width: 260px;
  height: 62px;
  font-size: 1.55rem !important;
  padding: 12px 20px;
  line-height: 1;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.35), 0 0 0 1px rgba(60, 48, 78, 0.25) inset;
  padding: 24px;
}

.about-panel {
  max-width: 760px;
  margin: 0 auto;
}

.about-panel .hero-brand {
  margin-bottom: 14px;
}

.billing-page {
  display: grid;
  gap: 14px;
}

.billing-title {
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-weight: 300;
  letter-spacing: 0.5px;
  margin: 0;
}

.billing-status {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #242329;
  padding: 12px 14px;
}

.billing-status p {
  margin: 0 0 4px;
}

.billing-status p:last-child {
  margin-bottom: 0;
}

.billing-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.billing-card {
  border: 1px solid #4c4658;
  border-radius: 12px;
  background: #27242f;
  padding: 14px;
  display: grid;
  gap: 8px;
}

.billing-card h3 {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-weight: 300;
  letter-spacing: 0.4px;
  font-size: 1.18rem;
}

.billing-card .btn {
  width: 100%;
}

.quota-trial {
  margin-top: -2px;
  margin-bottom: 2px;
}

.poetic-copy {
  font-family: "Cormorant Garamond", "Iowan Old Style", "Baskerville", "Palatino Linotype", Georgia, serif;
  font-size: 1.06rem;
  line-height: 1.62;
  letter-spacing: 0.006em;
  font-weight: 300;
  color: #e4deef;
  margin: 0 0 10px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
  font-feature-settings: "liga" 1, "kern" 1;
}

.auth-grid {
  display: grid;
  gap: 22px;
}

.hero-brand-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 8px 0 2px;
}

.hero-brand {
  margin: 0;
  text-align: center;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: clamp(2.5rem, 6vw, 4rem);
  font-weight: 200;
  letter-spacing: 1px;
  color: #f3f3ef;
}

.brand-heading {
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-weight: 200;
  letter-spacing: 0.6px;
}

.auth-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  background: #242424;
}

h1, h2 {
  margin: 0 0 10px;
  letter-spacing: 0.2px;
}

h1 {
  font-size: clamp(1.8rem, 2.7vw, 2.35rem);
  font-weight: 600;
}

h2 {
  font-size: clamp(1.2rem, 2vw, 1.45rem);
  font-weight: 600;
}

.muted {
  color: var(--muted);
  font-weight: 300;
  letter-spacing: 0.006em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.stack {
  display: grid;
  gap: 10px;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.95rem;
  color: var(--muted);
}

input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  font: inherit;
  color: var(--ink);
  background: #2a2a2a;
  transition: border-color 120ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

input:focus, textarea:focus {
  outline: none;
  border-color: #5a5a5a;
  box-shadow: 0 0 0 3px rgba(90, 90, 90, 0.25);
  background: #2f2f2f;
}

textarea {
  resize: vertical;
}

.btn {
  appearance: none;
  border: 1px solid #5b5366;
  border-radius: 10px;
  padding: 9px 14px;
  background: #2f2f2f;
  color: #f1f1ec;
  text-decoration: none;
  font: inherit;
  font-weight: 400;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 110ms ease, box-shadow 140ms ease, border-color 140ms ease, background-color 140ms ease;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.btn.primary {
  border-color: #6f6283;
  background: linear-gradient(180deg, #3a3344, #312b3a);
  color: #f1f1ec;
}

.btn.ghost {
  border-color: #574d66;
  background: #2d2b31;
}

.btn:hover {
  border-color: #7d6d97;
  box-shadow: 0 0 0 1px rgba(114, 91, 145, 0.35) inset, 0 0 14px rgba(56, 39, 84, 0.35);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

a {
  color: #cfc7dc;
  text-decoration-color: rgba(207, 199, 220, 0.45);
  text-underline-offset: 2px;
}

a:hover {
  color: #e4dff0;
  text-decoration-color: rgba(228, 223, 240, 0.75);
}

.btn.danger {
  border-color: var(--danger);
  color: var(--danger);
}

.alert {
  border-left: 4px solid var(--accent-strong);
  background: #272727;
  padding: 10px 12px;
  border-radius: 8px;
}

.chat-header {
  margin-bottom: 12px;
}

.quota {
  display: inline;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 0.88rem;
  color: var(--muted);
}

.chat-log {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 10px;
  margin: 16px 0;
}

.chat-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 10px;
  padding: 16px;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.chat-toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
}

.chat-toolbar h1 {
  font-size: 1.2rem;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.scroll-region {
  margin: 0;
  overflow-y: auto;
  padding: 8px 2px 12px;
  background: transparent;
  border: 0;
  border-radius: 0;
}

.bubble {
  border-radius: 10px;
  padding: 12px;
  border: 1px solid #3a3a3a;
  max-width: min(72ch, 82%);
  width: fit-content;
  align-self: flex-start;
}

.bubble p {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "Cormorant Garamond", "Iowan Old Style", "Baskerville", "Palatino Linotype", Georgia, serif;
  font-size: 1.06rem;
  line-height: 1.62;
  letter-spacing: 0.006em;
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-kerning: normal;
  font-feature-settings: "liga" 1, "kern" 1;
}

.bubble.user {
  background: #2f2b36;
  align-self: flex-end;
  color: #eeeaf6;
  max-width: min(62ch, 78%);
}

.bubble.assistant {
  background: transparent;
  border: 0;
  border-left: 2px solid rgba(200, 190, 220, 0.35);
  border-radius: 0;
  padding: 8px 0 30px 14px;
  max-width: min(68ch, 84%);
  color: #ddd8e7;
  align-self: flex-start;
  position: relative;
}

.typing-bubble {
  min-width: 64px;
  border: 0;
  border-left: 2px solid rgba(200, 190, 220, 0.35);
  border-radius: 0;
  background: transparent;
  padding: 6px 0 6px 12px;
}

.copy-bubble-btn {
  position: absolute;
  bottom: 2px;
  right: 2px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #4f495c;
  background: #2a2732;
  color: #d9d2e6;
  border-radius: 8px;
  width: 30px;
  height: 28px;
  padding: 0;
  cursor: pointer;
}

.copy-bubble-btn:hover {
  border-color: #7d6d97;
}

.copy-bubble-btn svg {
  width: 14px;
  height: 14px;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 1px;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #c7c2d3;
  opacity: 0.35;
  animation: typingPulse 1s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes typingPulse {
  0%,
  80%,
  100% {
    opacity: 0.3;
    transform: translateY(0);
  }
  40% {
    opacity: 0.95;
    transform: translateY(-2px);
  }
}

.draft-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.58);
  display: grid;
  place-items: center;
  z-index: 50;
}

.draft-modal-backdrop[hidden] {
  display: none !important;
}

.draft-modal {
  width: min(430px, calc(100vw - 24px));
  border: 1px solid #4a4357;
  border-radius: 14px;
  background: #232029;
  box-shadow: 0 20px 46px rgba(0, 0, 0, 0.45);
  padding: 16px;
}

.draft-modal h3 {
  margin: 0 0 6px;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-weight: 300;
  font-size: 1.18rem;
}

.draft-modal p {
  margin: 0 0 12px;
  color: var(--muted);
}

.draft-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: nowrap;
  align-items: center;
}

.draft-modal-actions .btn {
  min-width: 94px;
}

.actions {
  margin: 0;
  align-items: center;
}

.actions form {
  display: inline-flex;
  align-items: center;
}

.tag {
  display: inline-block;
  background: #1d2a24;
  color: #a7e6c8;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
}

.search-row label {
  min-width: 220px;
  flex: 1;
}

.search-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 16px;
}

.search-inline input {
  flex: 1;
  height: 42px;
}

.rename-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
}

.rename-inline[hidden] {
  display: none;
}

.rename-inline input {
  flex: 1;
  height: 40px;
}

.vault-list {
  margin-top: 16px;
  display: grid;
  gap: 12px;
}

.item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.item-head h2 {
  font-family: "Cormorant Garamond", "Iowan Old Style", "Baskerville", "Palatino Linotype", Georgia, serif;
  font-weight: 500;
  letter-spacing: 0.01em;
  font-size: 1.34rem;
}

.item-title-wrap {
  display: grid;
  gap: 1px;
}

.icon-edit {
  appearance: none;
  border: 1px solid #5b5366;
  background: #2d2b31;
  color: #ece7f5;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-edit svg {
  width: 15px;
  height: 15px;
}

.icon-edit svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-edit:hover {
  border-color: #7d6d97;
  box-shadow: 0 0 0 1px rgba(114, 91, 145, 0.35) inset;
}

.vault-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
}

.usage-pill {
  font-size: 0.92rem;
}

.chat-composer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #262626;
}

.chat-composer textarea {
  min-height: 88px;
  max-height: 220px;
  overflow-y: auto;
  resize: none;
  border: 0;
  border-radius: 10px;
  background: #262626;
  box-shadow: none;
  padding-top: 8px;
  padding-bottom: 8px;
  padding-left: 8px;
  padding-right: 8px;
  flex: 1;
}

.chat-composer textarea:focus {
  border: 0;
  box-shadow: none;
  background: #262626;
}

.send-btn {
  border-color: #d8d8d2;
  box-shadow: 0 0 0 1px rgba(235, 235, 230, 0.2) inset;
  min-width: 96px;
  height: 92px;
}

.mic-btn {
  min-width: 44px;
  width: 44px;
  height: 92px;
}

.mic-btn.listening {
  border-color: #c98d8d;
  box-shadow: 0 0 0 1px rgba(201, 141, 141, 0.28) inset;
}

.mic-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.composer-actions {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  gap: 6px;
  min-width: 104px;
}

.composer-actions .btn {
  width: 100%;
  height: 42px;
}

.icon-btn {
  padding: 0;
}

.icon-btn svg {
  width: 18px;
  height: 18px;
  display: block;
}

.icon-btn svg path {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 720px) {
  .auth-cards {
    grid-template-columns: 1fr;
  }

  .topbar {
    justify-content: center;
    align-items: center;
    min-height: 64px;
    padding: 10px 14px;
  }

  body.landing-page .page {
    height: 100vh;
  }

  body.chat-page .page {
    width: calc(100vw - 12px);
    margin: 10px auto;
    height: calc(100vh - 112px);
  }

  .chat-toolbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .chat-composer {
    width: 100%;
  }

  .composer-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .send-btn {
    min-width: 88px;
  }

  .billing-grid {
    grid-template-columns: 1fr;
  }

  .landing-enter {
    right: 16px;
    bottom: 16px;
    min-width: 220px;
    height: 56px;
    font-size: 1.3rem !important;
  }
}
