:root,
body.theme-dark {
  --bg: #0a0f1a;
  --bg-2: #0f1728;
  --bg-3: #0e1524;
  --panel: rgba(14, 21, 36, 0.88);
  --panel-strong: #111b2e;
  --panel-soft: rgba(255, 255, 255, 0.04);
  --line: rgba(148, 163, 184, 0.16);
  --text: #f4f7fb;
  --muted: #92a0b7;
  --blue: #4ea1ff;
  --blue-strong: #2f7fe0;
  --green: #2fd28b;
  --shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
  --sidebar-bg-top: rgba(10, 15, 26, 0.92);
  --sidebar-bg-bottom: rgba(13, 20, 34, 0.96);
  --radial-top: rgba(78, 161, 255, 0.16);
  --radial-bottom: rgba(47, 210, 139, 0.12);
  --tabs-bg: rgba(13, 20, 34, 0.75);
}

body.theme-light {
  --bg: #edf3fb;
  --bg-2: #f7faff;
  --bg-3: #eef4fc;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: #ffffff;
  --panel-soft: rgba(32, 70, 122, 0.06);
  --line: rgba(34, 62, 105, 0.12);
  --text: #12233b;
  --muted: #5e7493;
  --blue: #2e84ea;
  --blue-strong: #2369b9;
  --green: #16845a;
  --shadow: 0 20px 50px rgba(44, 76, 120, 0.12);
  --sidebar-bg-top: rgba(236, 244, 255, 0.94);
  --sidebar-bg-bottom: rgba(247, 250, 255, 0.98);
  --radial-top: rgba(46, 132, 234, 0.14);
  --radial-bottom: rgba(22, 132, 90, 0.08);
  --tabs-bg: rgba(255, 255, 255, 0.72);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top center, var(--radial-top), transparent 22%),
    radial-gradient(circle at bottom left, var(--radial-bottom), transparent 20%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-3) 100%);
}

button,
textarea {
  font: inherit;
}

button {
  transition: transform 160ms ease, background-color 160ms ease, border-color 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 294px minmax(0, 1fr);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--sidebar-bg-top), var(--sidebar-bg-bottom));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 10px;
}

.sidebar-icons,
.topbar-actions,
.query-toolbar,
.toolbar-left,
.toolbar-right,
.decision-actions,
.math-input-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.sidebar-icons {
  justify-content: space-between;
  margin-bottom: 16px;
}

.icon-button,
.ghost-button,
.topbar-button,
.menu-item,
.primary-button,
.secondary-button,
.promo-button,
.mode-tab {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  border-radius: 14px;
}

.icon-button,
.ghost-button,
.topbar-button {
  padding: 10px 14px;
}

.icon-button {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
}

.menu-card,
.promo-card,
.query-card,
.result-card,
.decision-card,
.answer-card,
.math-input-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.menu-card,
.promo-card {
  border-radius: 18px;
  overflow: hidden;
}

.menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  padding: 18px 14px;
  background: transparent;
  cursor: pointer;
  font-size: 1.08rem;
}

.menu-item + .menu-item {
  border-top: 1px solid var(--line);
}

.menu-item.active {
  background: rgba(78, 161, 255, 0.1);
}

.menu-icon {
  color: var(--blue);
  font-size: 1.1rem;
}

.sidebar-section {
  padding: 18px 10px;
}

.recent-chats {
  display: grid;
  gap: 10px;
}

.recent-chat-button {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
}

.recent-chat-button.is-pinned {
  border-color: rgba(78, 161, 255, 0.42);
  background: rgba(78, 161, 255, 0.08);
}

.recent-chat-button span {
  display: block;
}

.recent-chat-title {
  font-weight: 700;
  margin-bottom: 3px;
}

.recent-chat-meta {
  color: var(--muted);
  font-size: 0.88rem;
}

.chat-menu {
  position: fixed;
  min-width: 180px;
  padding: 8px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  z-index: 30;
}

.chat-menu-item {
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.chat-menu-item:hover {
  background: var(--panel-soft);
}

.chat-menu-item-danger {
  color: #ff8a8a;
}

.sidebar-heading,
.card-label,
.promo-badge {
  margin: 0 0 8px;
  color: var(--blue);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sidebar-muted {
  margin: 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.promo-card {
  padding: 18px;
}

.promo-card h3 {
  margin: 0 0 10px;
  font-size: 1.75rem;
  line-height: 1.15;
}

.promo-card p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.65;
}

.promo-button {
  width: 100%;
  padding: 13px 16px;
  background: linear-gradient(135deg, rgba(78, 161, 255, 0.28), rgba(47, 210, 139, 0.18));
  font-weight: 700;
}

.main-panel {
  padding: 14px 28px 42px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.topbar-button {
  padding: 12px 18px;
  background: rgba(78, 161, 255, 0.16);
}

.ghost-button {
  background: transparent;
}

.hero-block {
  max-width: 900px;
  margin: 110px auto 0;
  text-align: center;
}

.hero-mark {
  width: 58px;
  height: 58px;
  margin: 0 auto 20px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--blue), #68b2ff);
  color: white;
  font-size: 2rem;
  font-weight: 800;
  box-shadow: 0 18px 40px rgba(78, 161, 255, 0.25);
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 4.3vw, 4.3rem);
  font-weight: 800;
  line-height: 1.02;
  text-transform: lowercase;
}

.hero-subtitle,
.hero-description,
.mode-description,
.status,
.summary,
.encouragement,
.follow-up,
.next-step {
  color: var(--muted);
}

.hero-subtitle {
  margin: 14px 0 6px;
  font-size: 1.25rem;
  font-weight: 700;
}

.hero-description {
  margin: 0 auto;
  max-width: 760px;
  line-height: 1.75;
  font-size: 1.08rem;
}

.mode-description {
  margin: 18px auto 0;
  max-width: 720px;
  line-height: 1.7;
}

.mode-tabs {
  margin: 24px auto 0;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 8px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--tabs-bg);
}

.mode-tab {
  padding: 12px 18px;
  cursor: pointer;
  background: transparent;
}

.mode-tab.active {
  background: linear-gradient(135deg, var(--blue), var(--blue-strong));
}

.composer-panel {
  max-width: 920px;
  margin: 38px auto 0;
}

.query-card {
  padding: 0;
  border-radius: 24px;
  overflow: hidden;
}

textarea {
  width: 100%;
  min-height: 132px;
  border: 0;
  outline: none;
  resize: vertical;
  padding: 22px 24px 10px;
  background: transparent;
  color: var(--text);
  font-size: 1.8rem;
  line-height: 1.45;
}

textarea::placeholder {
  color: #68809f;
}

.query-toolbar {
  justify-content: space-between;
  padding: 0 14px 14px;
}

.tool-pill {
  padding: 11px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
}

.tool-button {
  cursor: pointer;
}

.tool-button.is-active {
  color: var(--text);
  border-color: rgba(78, 161, 255, 0.4);
  background: rgba(78, 161, 255, 0.12);
}

.primary-button,
.secondary-button {
  padding: 12px 18px;
  cursor: pointer;
}

.primary-button {
  background: linear-gradient(135deg, var(--blue), var(--blue-strong));
  border-color: transparent;
  box-shadow: 0 12px 30px rgba(78, 161, 255, 0.22);
}

.secondary-button {
  background: rgba(255, 255, 255, 0.03);
}

.status {
  min-height: 24px;
  margin: 16px 4px 0;
}

.math-input-panel {
  margin-top: 14px;
  padding: 18px;
  border-radius: 22px;
}

.math-input-header {
  justify-content: space-between;
  margin-bottom: 14px;
}

.math-input-help {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.math-input-mode-label {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.math-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.math-key {
  padding: 12px 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.results {
  max-width: 920px;
  margin: 26px auto 0;
}

.results-grid,
.answer-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.result-card,
.decision-card,
.answer-card {
  border-radius: 22px;
  padding: 22px;
}

.result-highlight {
  background: linear-gradient(135deg, rgba(78, 161, 255, 0.15), rgba(17, 27, 46, 0.95));
}

.result-card h2,
.answer-card h3,
.answer-card h4 {
  margin: 0 0 12px;
}

.bullet-list,
.number-list {
  margin: 0;
  padding-left: 20px;
  line-height: 1.8;
}

.plain-steps {
  display: grid;
  gap: 12px;
  line-height: 1.8;
}

.plain-step {
  margin: 0;
}

.katex {
  font-size: 1.02em;
}

.decision-card,
.answer-card {
  margin-top: 16px;
}

.self-solve-message {
  margin: 14px 0 0;
  color: var(--green);
  font-weight: 700;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 20, 0.62);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 20;
}

.modal-card {
  width: min(540px, 100%);
  padding: 22px;
  border-radius: 24px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.modal-header h2 {
  margin: 0;
}

.modal-body {
  margin: 16px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.hidden,
.visually-hidden {
  display: none;
}

.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;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    gap: 20px;
  }

  .main-panel {
    padding: 18px;
  }

  .hero-block {
    margin-top: 50px;
  }
}

@media (max-width: 760px) {
  .topbar,
  .query-toolbar,
  .decision-actions,
  .toolbar-left,
  .toolbar-right,
  .topbar-actions {
    flex-wrap: wrap;
  }

  .results-grid,
  .answer-grid,
  .math-grid {
    grid-template-columns: 1fr;
  }

  textarea {
    font-size: 1.2rem;
    min-height: 120px;
  }

  h1 {
    font-size: 2rem;
  }
}
