:root {
  --bg: #07101c;
  --bg-deep: #050b13;
  --surface: #0d1928;
  --surface-2: #122238;
  --surface-3: #172a43;
  --text: #f7f4ed;
  --muted: #aeb8c5;
  --muted-strong: #d1d7df;
  --line: rgba(255, 255, 255, .11);
  --line-strong: rgba(255, 255, 255, .2);
  --accent: #e2524a;
  --accent-dark: #bf3d37;
  --accent-soft: rgba(226, 82, 74, .14);
  --gold: #d7bd86;
  --green: #79c99e;
  --danger: #ff8b85;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 24px 70px rgba(0, 0, 0, .4);
}

*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 9% 4%, rgba(226, 82, 74, .12), transparent 31rem),
    radial-gradient(circle at 94% 100%, rgba(215, 189, 134, .06), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body.app-page { background: var(--bg-deep); }
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { line-height: 1.08; text-wrap: balance; }

:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
  border-radius: 8px;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-weight: 850;
  transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 1.22rem;
  font-weight: 900;
  letter-spacing: -.03em;
}
.brand::after {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 18px rgba(226, 82, 74, .65);
  content: "";
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 14px;
  color: var(--gold);
  font-size: .74rem;
  font-weight: 850;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.eyebrow::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
}

.muted { color: var(--muted); }
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.button {
  min-height: 50px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 12px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: rgba(255, 255, 255, .045);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  line-height: 1.2;
  transition: transform .2s ease, background .2s ease, border-color .2s ease;
}
.button:hover { transform: translateY(-1px); background: rgba(255, 255, 255, .08); }
.button:disabled { cursor: wait; opacity: .58; transform: none; }
.button--primary {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: 0 12px 32px rgba(226, 82, 74, .22);
}
.button--primary:hover { border-color: var(--accent-dark); background: var(--accent-dark); }
.button--full { width: 100%; }
.button--danger { border-color: rgba(255, 139, 133, .35); color: var(--danger); }
.button--small { min-height: 42px; padding: 9px 14px; font-size: .9rem; }

.field { display: grid; gap: 8px; }
.field label { color: var(--muted-strong); font-size: .9rem; font-weight: 750; }
.field input,
.field textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 13px;
  background: rgba(255, 255, 255, .035);
  color: var(--text);
  transition: border-color .2s ease, background .2s ease, box-shadow .2s ease;
}
.field input { min-height: 54px; padding: 0 15px; }
.field textarea { min-height: 170px; padding: 15px; resize: vertical; line-height: 1.55; }
.field input::placeholder,
.field textarea::placeholder { color: #778393; }
.field input:focus,
.field textarea:focus {
  border-color: var(--gold);
  background: rgba(255, 255, 255, .055);
  box-shadow: 0 0 0 4px rgba(215, 189, 134, .09);
  outline: 0;
}
.field-help { margin: 0; color: var(--muted); font-size: .8rem; }

.notice {
  display: none;
  padding: 12px 14px;
  border: 1px solid rgba(255, 139, 133, .3);
  border-radius: 12px;
  background: rgba(255, 139, 133, .09);
  color: #ffd2cf;
  font-size: .9rem;
}
.notice.is-visible { display: block; }
.notice--success {
  border-color: rgba(121, 201, 158, .3);
  background: rgba(121, 201, 158, .09);
  color: #c8f3db;
}
.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid rgba(215, 189, 134, .24);
  border-radius: 99px;
  background: rgba(215, 189, 134, .08);
  color: var(--gold);
  font-size: .72rem;
  font-weight: 850;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.mode-pill::before {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  content: "";
}

/* Authentication */
.auth-layout {
  width: min(calc(100% - 36px), 1120px);
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, .9fr) minmax(390px, .65fr);
  align-items: center;
  gap: clamp(38px, 7vw, 90px);
  margin: 0 auto;
  padding: 38px 0;
}
.auth-story { max-width: 590px; padding: 30px 0; }
.auth-story h1 {
  max-width: 600px;
  margin: 54px 0 20px;
  font-size: clamp(2.8rem, 6vw, 5rem);
  letter-spacing: -.055em;
}
.auth-story > p {
  max-width: 560px;
  color: var(--muted-strong);
  font-size: 1.08rem;
}
.auth-points {
  display: grid;
  gap: 14px;
  margin-top: 40px;
}
.auth-point {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 14px;
  align-items: start;
}
.auth-point span {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--accent);
  font-size: .77rem;
  font-weight: 900;
}
.auth-point strong { display: block; margin: 2px 0 3px; }
.auth-point p { margin: 0; color: var(--muted); font-size: .9rem; }
.auth-card {
  position: relative;
  padding: clamp(26px, 5vw, 44px);
  border: 1px solid var(--line);
  border-radius: 28px;
  background:
    radial-gradient(circle at 90% 0, rgba(226, 82, 74, .12), transparent 22rem),
    linear-gradient(145deg, var(--surface-2), #0a1421);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.auth-card h2 {
  margin-bottom: 8px;
  font-size: clamp(2rem, 4vw, 3rem);
  letter-spacing: -.045em;
}
.auth-card > p { color: var(--muted); }
.auth-form { display: grid; gap: 17px; margin-top: 28px; }
.auth-legal { margin: 0; color: var(--muted); font-size: .76rem; text-align: center; }
.auth-switch { margin: 24px 0 0; color: var(--muted); text-align: center; }
.auth-switch a { color: #ff8e87; font-weight: 800; }
.auth-back {
  display: inline-flex;
  margin-top: 26px;
  color: var(--muted);
  font-size: .88rem;
  font-weight: 750;
}

/* App shell */
.app-shell {
  width: min(100%, 1500px);
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  margin: 0 auto;
}
.app-sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 28px 20px 22px;
  border-right: 1px solid var(--line);
  background: #07101c;
}
.app-nav { display: grid; gap: 7px; margin-top: 48px; }
.app-nav a {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--muted);
  font-weight: 750;
}
.app-nav a::before {
  width: 8px;
  height: 8px;
  border: 1px solid currentColor;
  border-radius: 50%;
  content: "";
}
.app-nav a:hover { color: var(--text); background: rgba(255, 255, 255, .035); }
.app-nav a.is-active {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}
.app-nav a.is-active::before { border-color: var(--accent); background: var(--accent); }
.sidebar-user {
  margin-top: auto;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .025);
}
.sidebar-user strong,
.sidebar-user span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user span { margin-top: 3px; color: var(--muted); font-size: .78rem; }

.app-main { min-width: 0; padding: 32px clamp(24px, 5vw, 68px) 110px; }
.app-topbar {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 40px;
}
.app-topbar .mode-pill { flex-shrink: 0; }
.app-heading { max-width: 780px; margin-bottom: 30px; }
.app-heading h1 {
  margin-bottom: 12px;
  font-size: clamp(2.35rem, 5vw, 4.2rem);
  letter-spacing: -.055em;
}
.app-heading p { max-width: 680px; color: var(--muted); font-size: 1.02rem; }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 20px;
  align-items: start;
}
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .18);
}
.composer { padding: clamp(20px, 4vw, 34px); }
.composer-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}
.composer h2 { margin-bottom: 7px; font-size: clamp(1.6rem, 3vw, 2.2rem); letter-spacing: -.035em; }
.composer-head p { margin: 0; color: var(--muted); font-size: .9rem; }
.quick-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.quick-chip {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: rgba(255, 255, 255, .025);
  color: var(--muted-strong);
  cursor: pointer;
  font-size: .82rem;
  font-weight: 750;
}
.quick-chip:hover,
.quick-chip.is-selected { border-color: rgba(226, 82, 74, .5); background: var(--accent-soft); color: #ffaaa5; }
.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 16px;
}
.composer-actions p { max-width: 420px; margin: 0; color: var(--muted); font-size: .78rem; }
.side-stack { display: grid; gap: 18px; }
.side-card { padding: 22px; }
.side-card h3 { margin-bottom: 9px; font-size: 1.08rem; }
.side-card p { margin-bottom: 16px; color: var(--muted); font-size: .88rem; }
.usage-number { display: flex; align-items: end; justify-content: space-between; gap: 14px; }
.usage-number strong { font-size: 2rem; letter-spacing: -.04em; }
.usage-bar { height: 7px; margin-top: 13px; border-radius: 99px; background: rgba(255, 255, 255, .07); overflow: hidden; }
.usage-bar span { display: block; width: 30%; height: 100%; border-radius: inherit; background: var(--accent); }
.principle-card { border-color: rgba(215, 189, 134, .18); background: linear-gradient(145deg, #18243a, #0d1827); }
.principle-card small { color: var(--gold); font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }
.principle-card blockquote { margin: 14px 0 0; font-size: 1.08rem; font-weight: 750; line-height: 1.45; }

.analysis-result { display: none; margin-top: 20px; padding: clamp(22px, 4vw, 34px); }
.analysis-result.is-visible { display: block; }
.analysis-result h2 { max-width: 780px; margin: 14px 0 22px; font-size: clamp(1.7rem, 4vw, 2.65rem); letter-spacing: -.04em; }
.analysis-meta { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.analysis-meta span { color: var(--gold); font-size: .72rem; font-weight: 850; letter-spacing: .11em; text-transform: uppercase; }
.saved-status { color: var(--green) !important; letter-spacing: 0 !important; text-transform: none !important; }
.analysis-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border-top: 1px solid var(--line); }
.analysis-item { padding: 21px 20px 21px 0; border-bottom: 1px solid var(--line); }
.analysis-item:nth-child(even) { padding-left: 20px; border-left: 1px solid var(--line); }
.analysis-item--wide { grid-column: 1 / -1; padding-left: 0 !important; border-left: 0 !important; }
.analysis-item small,
.message-box small {
  display: block;
  margin-bottom: 8px;
  color: var(--accent);
  font-weight: 850;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.analysis-item p { margin: 0; color: var(--muted-strong); }
.message-box {
  margin-top: 20px;
  padding: 22px;
  border-left: 3px solid var(--accent);
  background: rgba(255, 255, 255, .035);
}
.message-box p { margin: 0 0 15px; font-size: 1.08rem; font-weight: 700; }
.result-footer { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 14px; }
.result-note { padding: 16px; border: 1px solid var(--line); border-radius: 13px; }
.result-note span { display: block; margin-bottom: 5px; color: var(--gold); font-size: .72rem; font-weight: 850; text-transform: uppercase; }
.result-note strong { font-size: .92rem; }

/* History */
.history-tools { display: flex; gap: 10px; margin-bottom: 18px; }
.history-tools input {
  width: min(100%, 420px);
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}
.history-list { display: grid; gap: 12px; }
.history-card { padding: 20px; }
.history-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 18px;
}
.history-card h2 { margin-bottom: 7px; font-size: 1.18rem; }
.history-card time { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.history-card > p { margin: 0; color: var(--muted); }
.history-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 15px; }
.history-details { display: none; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.history-details.is-visible { display: grid; gap: 14px; }
.history-detail strong { display: block; margin-bottom: 3px; color: var(--gold); font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; }
.history-detail p { margin: 0; color: var(--muted-strong); }
.empty-state { padding: 46px 24px; text-align: center; }
.empty-state h2 { margin-bottom: 9px; }
.empty-state p { max-width: 500px; margin: 0 auto 20px; color: var(--muted); }

/* Profile */
.profile-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, .55fr); gap: 18px; }
.profile-card { padding: clamp(22px, 4vw, 32px); }
.profile-card h2 { margin-bottom: 8px; font-size: 1.35rem; }
.profile-card > p { color: var(--muted); }
.profile-form { display: grid; gap: 16px; margin-top: 24px; }
.profile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
}
.profile-row:last-child { border-bottom: 0; }
.profile-row span { color: var(--muted); font-size: .87rem; }
.profile-row strong { text-align: right; }
.privacy-box {
  margin-top: 20px;
  padding: 17px;
  border: 1px solid rgba(121, 201, 158, .22);
  border-radius: 14px;
  background: rgba(121, 201, 158, .06);
}
.privacy-box strong { display: block; margin-bottom: 5px; color: #b9edcf; }
.privacy-box p { margin: 0; color: var(--muted); font-size: .84rem; }

.mobile-tabbar {
  position: fixed;
  z-index: 80;
  left: 12px;
  right: 12px;
  bottom: 12px;
  display: none;
  grid-template-columns: repeat(4, 1fr);
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(9, 18, 30, .94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.mobile-tabbar a {
  min-height: 48px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--muted);
  font-size: .73rem;
  font-weight: 800;
}
.mobile-tabbar a.is-active { background: var(--surface-3); color: var(--text); }

@media (max-width: 980px) {
  .auth-layout { grid-template-columns: 1fr; width: min(calc(100% - 32px), 650px); }
  .auth-story { display: none; }
  .app-shell { display: block; }
  .app-sidebar { display: none; }
  .app-main { padding: 24px 20px 110px; }
  .mobile-tabbar { display: grid; }
  .dashboard-grid,
  .profile-grid { grid-template-columns: 1fr; }
  .side-stack { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 650px) {
  .auth-layout { width: 100%; padding: 0; }
  .auth-card { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; border: 0; border-radius: 0; box-shadow: none; }
  .app-main { padding-inline: 15px; }
  .app-topbar { margin-bottom: 26px; }
  .app-topbar .brand { font-size: 1.05rem; }
  .app-topbar .mode-pill { padding: 6px 8px; font-size: .62rem; }
  .side-stack,
  .analysis-grid,
  .result-footer { grid-template-columns: 1fr; }
  .analysis-item:nth-child(even) { padding-left: 0; border-left: 0; }
  .composer-actions { align-items: stretch; flex-direction: column; }
  .composer-actions .button { width: 100%; }
  .history-card-head { flex-direction: column; gap: 7px; }
}

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