:root {
  color-scheme: light;
  --bg: #fbf8f1;
  --bg-lavender: #f4f0ff;
  --surface: #ffffff;
  --surface-soft: #faf8ff;
  --surface-tint: #f1edff;
  --text: #29243a;
  --muted: #6f687e;
  --muted-strong: #4a4359;
  --border: #e5deef;
  --accent: #6c5ce7;
  --accent-dark: #4c3cb8;
  --accent-soft: #eeeaff;
  --coral: #ff8066;
  --coral-soft: #fff0ec;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --shadow: 0 28px 70px rgba(76, 60, 184, 0.14);
  --shadow-soft: 0 14px 36px rgba(76, 60, 184, 0.10);
  --solver-sidebar: 260px;
  --conversation-width: 760px;
  --solver-bg: #ffffff;
  --solver-sidebar-bg: #f7f7f5;
  --solver-hover: #ececea;
  --solver-border: #deded9;
  --solver-text: #242424;
  --solver-muted: #686868;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 4%, rgba(108, 92, 231, 0.10), transparent 28rem),
    radial-gradient(circle at 92% 22%, rgba(255, 128, 102, 0.09), transparent 25rem),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-lavender) 100%);
}

body.solver-page {
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--coral);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.subtitle {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.04rem;
  line-height: 1.7;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
}

.login-layout {
  display: grid;
  width: min(1040px, 100%);
  grid-template-columns: minmax(0, 1.15fr) minmax(340px, 0.85fr);
  gap: 18px;
  align-items: stretch;
}

.login-panel {
  border: 1px solid rgba(229, 222, 239, 0.92);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
}

.login-story {
  display: grid;
  align-content: center;
  min-height: 560px;
  padding: 44px;
  background:
    linear-gradient(135deg, rgba(108, 92, 231, 0.10), transparent 26rem),
    linear-gradient(180deg, #ffffff 0%, var(--surface-soft) 100%);
}

.login-story h1 {
  max-width: 620px;
  margin-bottom: 18px;
  font-size: clamp(2.4rem, 5vw, 4.4rem);
  line-height: 1.03;
  letter-spacing: 0;
}

.login-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 34px;
}

.login-metrics div,
.login-steps li {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.78);
}

.login-metrics div {
  display: grid;
  gap: 6px;
  padding: 16px;
}

.login-metrics strong {
  color: var(--text);
  font-size: 1.04rem;
}

.login-metrics span,
.form-note,
.login-steps li,
.panel-header p,
.hero-notes span {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.login-steps {
  display: grid;
  gap: 10px;
  margin: 26px 0 0;
  padding: 0;
  list-style: none;
}

.login-steps li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  color: var(--muted-strong);
  font-weight: 700;
}

.login-steps span {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 800;
}

.login-card {
  display: grid;
  align-content: center;
  padding: 38px;
}

.form-kicker {
  margin-bottom: 10px;
  color: var(--coral);
  font-size: 0.82rem;
  font-weight: 800;
}

.login-card h2 {
  margin-bottom: 10px;
  font-size: 2rem;
  line-height: 1.15;
}

.login-form {
  display: grid;
  gap: 10px;
  margin-top: 26px;
}

.login-form label {
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 800;
}

.login-form input {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0 14px;
  background: #fff;
  color: var(--text);
}

.login-form input:focus {
  outline: 3px solid rgba(108, 92, 231, 0.18);
  border-color: var(--accent-dark);
}

.login-form .primary-button {
  margin-top: 12px;
}

.login-error {
  margin: 22px 0 0;
}

.success-box {
  margin: 22px 0 0;
  border: 1px solid #a8dfc1;
  border-radius: 16px;
  padding: 14px 16px;
  background: #effbf4;
  color: #176b3a;
  font-weight: 700;
  line-height: 1.5;
}

.auth-switch {
  margin: 22px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.auth-switch a {
  color: var(--accent-dark);
  font-weight: 800;
}

.landing-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 42px;
}

.landing-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.brand-mark,
.story-brand,
.nav-login,
.nav-signup,
.primary-link,
.secondary-link {
  text-decoration: none;
}

.brand-mark,
.story-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 800;
}

.brand-symbol {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, #806ff0, var(--accent));
  color: #fff;
  box-shadow: 0 10px 22px rgba(108, 92, 231, 0.28);
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-signup-form {
  margin: 0;
}

.nav-login,
.nav-signup {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border-radius: 16px;
  padding: 9px 13px;
  font-size: 0.9rem;
  font-weight: 800;
}

.nav-login {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.nav-signup {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(108, 92, 231, 0.22);
  cursor: pointer;
}

.landing-hero {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(330px, 0.92fr);
  gap: 22px;
  align-items: stretch;
}

.landing-copy,
.hero-preview,
.landing-section {
  border: 1px solid rgba(229, 222, 239, 0.92);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-soft);
}

.landing-copy {
  display: grid;
  align-content: center;
  min-height: 520px;
  padding: 44px;
  background:
    linear-gradient(135deg, rgba(108, 92, 231, 0.09), transparent 31rem),
    linear-gradient(180deg, #ffffff 0%, var(--surface-soft) 100%);
}

.landing-copy h1 {
  max-width: 760px;
  margin-bottom: 18px;
  font-size: clamp(2.5rem, 5vw, 4.8rem);
}

.landing-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 30px;
}

.primary-link,
.secondary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border-radius: 16px;
  padding: 0 18px;
  font-weight: 800;
}

.primary-link {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 26px rgba(108, 92, 231, 0.26);
}

.secondary-link {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.hero-preview {
  position: relative;
  display: grid;
  align-content: center;
  min-height: 520px;
  overflow: hidden;
  padding: 34px;
  background: linear-gradient(145deg, #fffdf7, var(--bg-lavender));
}

.hero-preview::before {
  position: absolute;
  width: 330px;
  height: 190px;
  border-radius: 50%;
  background: rgba(255, 128, 102, 0.10);
  content: "";
  right: -90px;
  top: 84px;
  transform: rotate(-14deg);
}

.scan-card,
.equation-card,
.answer-float {
  position: relative;
  border: 1px solid rgba(229, 222, 239, 0.92);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
}

.scan-card {
  display: grid;
  gap: 12px;
  width: min(86%, 360px);
  margin: 34px 0 0 auto;
  padding: 34px 30px;
  transform: rotate(2deg);
}

.scan-card strong {
  font-size: clamp(2rem, 4vw, 3.2rem);
}

.equation-card {
  display: grid;
  gap: 7px;
  width: min(72%, 300px);
  margin: -14px auto 0;
  padding: 20px 24px;
  border-color: rgba(255, 128, 102, 0.28);
  background: var(--coral-soft);
  transform: rotate(1deg);
}

.equation-card small,
.equation-card span {
  color: var(--coral);
  font-weight: 800;
}

.equation-card strong {
  color: var(--text);
  font-size: 1.75rem;
}

.equation-card span {
  font-size: 0.8rem;
}

.scan-label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.scan-corner {
  position: absolute;
  width: 24px;
  height: 24px;
  border-left: 3px solid var(--accent);
  border-top: 3px solid var(--accent);
}

.scan-corner-top {
  top: 14px;
  left: 14px;
}

.scan-corner-bottom {
  right: 14px;
  bottom: 14px;
  transform: rotate(180deg);
}

.answer-float {
  display: grid;
  gap: 8px;
  width: min(70%, 290px);
  margin: -14px auto 0 0;
  padding: 24px;
  transform: rotate(-2deg);
}

.answer-float span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.answer-float strong {
  color: var(--accent-dark);
  font-size: 2rem;
}

.sparkle {
  position: absolute;
  top: -18px;
  right: 22px;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.preview-toolbar {
  display: flex;
  gap: 7px;
}

.preview-toolbar span {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--border);
}

.preview-problem,
.preview-answer {
  border-radius: 16px;
  padding: 18px;
  background: var(--surface-soft);
}

.preview-problem {
  display: grid;
  gap: 8px;
}

.preview-problem span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.preview-problem strong {
  color: var(--text);
  font-size: clamp(2rem, 4vw, 3.3rem);
  line-height: 1;
}

.preview-steps {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 22px;
  color: var(--muted-strong);
  line-height: 1.55;
}

.preview-answer {
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 1.16rem;
  font-weight: 800;
}

.landing-section {
  margin-top: 20px;
  padding: 30px;
}

.section-heading {
  max-width: 620px;
  margin-bottom: 20px;
}

.section-heading h2,
.landing-band h2 {
  margin-bottom: 10px;
  font-size: clamp(1.7rem, 3vw, 2.4rem);
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.feature-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  background: #fff;
}

.feature-card > span {
  color: var(--coral);
  font-size: 0.82rem;
  font-weight: 800;
}

.feature-card h3 {
  margin: 12px 0 8px;
  font-size: 1.1rem;
}

.feature-card p,
.landing-band p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.65;
}

.landing-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background:
    linear-gradient(135deg, rgba(108, 92, 231, 0.11), transparent 34rem),
    #fff;
}

.landing-band > div {
  max-width: 720px;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 0 0 34px;
}

.workspace {
  display: grid;
  gap: 20px;
}

.solver-layout {
  display: grid;
  width: 100%;
  height: 100dvh;
  grid-template-columns: var(--solver-sidebar) minmax(0, 1fr);
  gap: 0;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--solver-bg);
  color: var(--solver-text);
}

.solver-main {
  display: grid;
  min-width: 0;
  height: 100dvh;
  min-height: 100dvh;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
}

.solver-topbar {
  display: grid;
  min-width: 0;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  border-bottom: 1px solid var(--solver-border);
  padding: 10px 20px;
  background: rgba(255, 255, 255, 0.96);
}

.solver-topbar strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-scroll {
  min-height: 0;
  overflow-y: auto;
}

.conversation-stream {
  width: min(var(--conversation-width), calc(100% - 40px));
  margin: 0 auto;
  padding: 48px 0 32px;
}

.user-message,
.assistant-message {
  margin: 0 0 24px;
}

.user-message {
  display: flex;
  justify-content: flex-end;
}

.user-message .history-result-image-wrap {
  width: min(82%, 560px);
  border-color: var(--solver-border);
  background: #f7f7f5;
  box-shadow: none;
}

.assistant-message {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.assistant-avatar {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--solver-border);
  border-radius: 50%;
  background: #f7f7f5;
  color: var(--solver-text);
  font-size: 0.72rem;
  font-weight: 800;
}

.structured-answer {
  min-width: 0;
}

.structured-answer .result-block,
.structured-answer .final-answer {
  border-color: var(--solver-border);
  background: #fff;
  box-shadow: none;
}

.structured-answer .final-answer {
  background: #f7f7f5;
  color: var(--solver-text);
}

.structured-answer .final-answer p {
  color: var(--solver-text);
}

.composer-dock {
  padding: 12px 20px 20px;
  background: linear-gradient(transparent, #fff 24%);
}

.composer-shell {
  width: min(var(--conversation-width), 100%);
  margin: 0 auto;
}

.intro {
  max-width: none;
}

.hero-strip {
  display: grid;
  gap: 0;
  border: 1px solid rgba(229, 222, 239, 0.92);
  border-radius: 24px;
  padding: 8px 12px;
  background:
    linear-gradient(135deg, rgba(108, 92, 231, 0.10), transparent 34rem),
    var(--surface);
  box-shadow: var(--shadow-soft);
}

.hero-strip > .eyebrow {
  margin: 0;
}

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

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-account {
  display: flex;
  min-width: 0;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.topbar-account .user-badge {
  flex: 0 0 auto;
  white-space: nowrap;
}

.sidebar-menu-button,
.sidebar-close {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.sidebar-menu-button {
  align-content: center;
  gap: 4px;
}

.sidebar-menu-button span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.topbar .eyebrow {
  margin: 0;
}

.topbar form {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}

.user-badge {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 11px;
  background: var(--surface-soft);
  color: var(--muted-strong);
  font-size: 0.84rem;
  font-weight: 800;
}

.logout-button {
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 800;
  cursor: pointer;
}

.hero-copy {
  display: grid;
  max-width: 780px;
  gap: 12px;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(2.2rem, 5vw, 4.1rem);
  line-height: 1.03;
  letter-spacing: 0;
}

.hero-notes {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.hero-notes span {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 11px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--muted-strong);
  font-weight: 700;
}

.panel-grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(360px, 1.08fr);
  gap: 20px;
  align-items: start;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 0;
}

.panel-header h2 {
  margin-bottom: 5px;
  font-size: 1.08rem;
}

.panel-header p {
  margin-bottom: 0;
}

#mobile-new-problem {
  display: none;
}

.file-note,
.status-pill {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--coral-soft);
  color: var(--coral);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-pill {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.solve-form {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 286px;
  overflow: hidden;
  padding: 26px;
  border: 2px dashed #b8acef;
  border-radius: 16px;
  background:
    linear-gradient(180deg, #ffffff 0%, var(--surface-soft) 100%);
  cursor: pointer;
  text-align: center;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.drop-prompt {
  display: grid;
  place-items: center;
}

.drop-zone.has-preview .drop-prompt {
  visibility: hidden;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.drag-over {
  outline: none;
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.18);
  transform: translateY(-1px);
}

.solver-layout *:focus-visible {
  outline: 3px solid var(--accent-dark);
  outline-offset: 3px;
}

.upload-icon {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  margin-bottom: 16px;
  border-radius: 16px;
  background: var(--accent-soft);
  color: var(--accent);
}

.upload-icon svg {
  width: 30px;
  height: 30px;
  fill: currentColor;
}

.drop-title {
  display: block;
  margin-bottom: 7px;
  font-size: 1.12rem;
  font-weight: 800;
}

.drop-subtitle {
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.55;
}

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

.primary-button,
.secondary-button,
.remove-button {
  min-height: 46px;
  border: 0;
  border-radius: 16px;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 12px 26px rgba(108, 92, 231, 0.26);
}

.primary-link:hover,
.primary-link:focus-visible,
.primary-button:hover:not(:disabled),
.primary-button:focus-visible:not(:disabled) {
  background: var(--accent-dark);
}

.nav-login:focus-visible,
.nav-signup:focus-visible,
.auth-switch a:focus-visible,
.primary-link:focus-visible,
.secondary-link:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.remove-button:focus-visible,
.logout-button:focus-visible {
  outline: 3px solid rgba(108, 92, 231, 0.18);
  outline-offset: 2px;
}

.nav-signup:hover,
.nav-signup:focus-visible {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

.primary-button:hover:not(:disabled),
.secondary-button:hover:not(:disabled),
.remove-button:hover:not(:disabled),
.logout-button:hover {
  transform: translateY(-1px);
}

.secondary-link:hover,
.secondary-link:focus-visible,
.nav-login:hover,
.nav-login:focus-visible,
.secondary-button:hover:not(:disabled),
.secondary-button:focus-visible:not(:disabled),
.remove-button:hover:not(:disabled),
.remove-button:focus-visible:not(:disabled),
.logout-button:hover,
.logout-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.primary-button:disabled {
  cursor: not-allowed;
  background: #aaa3c6;
  box-shadow: none;
}

.secondary-button,
.remove-button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.secondary-button:disabled,
.remove-button:disabled {
  cursor: not-allowed;
  color: var(--muted);
}

.preview-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-tint);
}

.drop-zone .preview-wrap {
  position: absolute;
  inset: 0;
  border: 0;
  border-radius: 14px;
}

.preview-wrap img {
  display: block;
  width: 100%;
  height: 100%;
  max-height: 360px;
  object-fit: contain;
}

.remove-button {
  position: absolute;
  top: 12px;
  right: 12px;
  min-height: 36px;
  background: rgba(255, 255, 255, 0.94);
}

.empty-state,
.loading-state {
  display: grid;
  place-items: center;
  min-height: 500px;
  padding: 34px;
  color: var(--muted);
  text-align: center;
}

.empty-state h3 {
  margin-bottom: 8px;
  color: var(--text);
  font-size: 1.12rem;
}

.empty-state p,
.loading-state p {
  margin-bottom: 0;
  line-height: 1.6;
}

.math-mark {
  display: grid;
  width: 88px;
  height: 88px;
  place-items: center;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #fff;
  color: var(--accent);
  font-size: 3rem;
  font-weight: 800;
  box-shadow: var(--shadow-soft);
}

.loading-state {
  align-content: center;
  gap: 18px;
}

.spinner {
  width: 54px;
  height: 54px;
  border: 5px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.error-box {
  margin: 24px;
  border: 1px solid #ffcdc8;
  border-radius: 16px;
  padding: 14px 16px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 700;
  line-height: 1.5;
}

.solution-output {
  display: grid;
  gap: 14px;
  padding: 24px;
}

.result-block,
.final-answer {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  background: #fff;
}

.result-block h3,
.final-answer h3 {
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.solution-steps-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 700;
  list-style: none;
}

.solution-steps-summary::-webkit-details-marker {
  display: none;
}

.solution-steps-summary:focus-visible {
  border-radius: 8px;
  outline: 3px solid rgba(108, 92, 231, 0.22);
  outline-offset: 4px;
}

.solution-steps-icon {
  display: inline-grid;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 1.15rem;
  transition: transform 180ms ease;
}

.solution-steps[open] .solution-steps-icon {
  transform: rotate(180deg);
}

.solution-steps[open] .content-list {
  margin-top: 14px;
}

.result-block p,
.final-answer p,
.content-list {
  margin-bottom: 0;
  color: var(--muted-strong);
  line-height: 1.68;
}

.content-list {
  display: grid;
  gap: 8px;
  padding-left: 20px;
}

.content-list li,
.final-answer p,
#detected-problem {
  overflow-x: auto;
  overflow-y: hidden;
  line-height: 1.9;
}

.final-answer {
  border-color: rgba(108, 92, 231, 0.30);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.final-answer p {
  color: var(--accent-dark);
  font-size: 1.14rem;
  font-weight: 800;
}

@media (prefers-reduced-motion: reduce) {
  .solver-layout *,
  .solver-layout *::before,
  .solver-layout *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }

  .solution-steps-icon {
    transition: none;
  }

  html {
    scroll-behavior: auto;
  }
}

.history-panel {
  overflow: hidden;
  border: 1px solid rgba(229, 222, 239, 0.92);
  border-radius: 24px;
  padding: 24px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-soft);
}

.history-header,
.history-actions,
.history-item,
.history-detail-heading {
  display: flex;
  align-items: center;
}

.history-header,
.history-detail-heading {
  justify-content: space-between;
  gap: 20px;
}

.history-header h2 {
  margin-bottom: 6px;
}

.history-header p,
.history-detail-heading time {
  margin-bottom: 0;
  color: var(--muted);
}

.history-actions {
  flex: 0 0 auto;
  gap: 10px;
}

.history-select-all-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 800;
}

.history-select-all-label input,
.history-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.history-delete-button,
.history-open-button {
  min-height: 38px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0 13px;
  background: #fff;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}

.history-delete-button:not(:disabled) {
  border-color: #ffcdc8;
  color: var(--danger);
}

.history-delete-button:disabled {
  cursor: not-allowed;
  color: var(--muted);
}

.history-list {
  display: grid;
  gap: 10px;
  margin-top: 22px;
}

.history-item {
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  background: var(--surface-soft);
}

.history-summary {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 4px;
}

.history-summary time,
.history-summary span {
  color: var(--muted);
  font-size: 0.84rem;
}

.history-summary strong,
.history-summary span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-empty {
  margin: 22px 0 0;
  border: 1px dashed var(--border);
  border-radius: 16px;
  padding: 32px;
  color: var(--muted);
  text-align: center;
}

.history-error {
  margin: 20px 0 0;
}

.history-detail {
  margin-top: 22px;
  border-top: 1px solid var(--border);
  padding-top: 22px;
}

.history-detail-grid {
  display: grid;
  grid-template-columns: minmax(240px, 0.78fr) minmax(0, 1.22fr);
  gap: 18px;
  margin-top: 18px;
  align-items: start;
}

.history-image-wrap {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-tint);
}

.history-image-wrap img {
  display: block;
  width: 100%;
  max-height: 520px;
  object-fit: contain;
}

.history-solution {
  display: grid;
  gap: 12px;
}

.history-result-image-wrap {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-tint);
}

.history-result-image-wrap img {
  display: block;
  width: 100%;
  max-height: 420px;
  object-fit: contain;
}

.sidebar-overlay {
  position: fixed;
  z-index: 90;
  inset: 0;
  width: 100%;
  border: 0;
  background: rgba(29, 24, 48, 0.42);
  cursor: default;
}

.history-sidebar {
  position: fixed;
  z-index: 100;
  top: 0;
  bottom: 0;
  left: 0;
  display: grid;
  width: min(360px, calc(100vw - 28px));
  grid-template-rows: auto auto auto auto minmax(0, 1fr) auto;
  gap: 16px;
  padding: 20px;
  border-right: 1px solid var(--border);
  background: #fff;
  box-shadow: 24px 0 60px rgba(41, 36, 58, 0.18);
  transform: translateX(-105%);
  transition: transform 220ms ease;
}

.solver-layout .history-sidebar {
  position: sticky;
  inset: 0 auto 0 0;
  width: var(--solver-sidebar);
  height: 100dvh;
  transform: none;
  visibility: visible;
  background: var(--solver-sidebar-bg);
  border-right: 1px solid var(--solver-border);
  box-shadow: none;
}

.solver-layout .sidebar-menu-button,
.solver-layout .sidebar-overlay,
.solver-layout .sidebar-close {
  display: none;
}

.history-sidebar.is-open {
  transform: translateX(0);
}

.sidebar-open {
  overflow: hidden;
}

.sidebar-heading,
.sidebar-history-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sidebar-close {
  flex: 0 0 auto;
  font-size: 1.55rem;
}

.sidebar-new-problem {
  min-height: 46px;
  border: 1px solid var(--accent);
  border-radius: 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.sidebar-history-heading h2 {
  margin: 0;
  font-size: 1.12rem;
}

.history-manage-toggle {
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  font-weight: 800;
  cursor: pointer;
}

.history-sidebar .history-actions,
.history-sidebar .history-checkbox {
  display: none;
}

.history-sidebar.is-managing .history-actions {
  display: flex;
}

.history-sidebar.is-managing .history-checkbox {
  display: block;
  flex: 0 0 auto;
}

.history-sidebar .history-list {
  min-height: 0;
  margin-top: 0;
  overflow-y: auto;
  align-content: start;
  padding-right: 3px;
}

.history-sidebar .history-item {
  gap: 10px;
  padding: 12px;
}

.history-sidebar .history-open-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.8rem;
}

.history-sidebar .history-empty {
  margin: 0;
  padding: 24px 14px;
}

@media (max-width: 900px) {
  .solver-layout {
    grid-template-columns: 1fr;
  }

  .solver-layout .history-sidebar {
    position: fixed;
    width: min(340px, 88vw);
    transform: translateX(-100%);
    visibility: hidden;
  }

  .solver-layout .history-sidebar.is-open {
    transform: translateX(0);
    visibility: visible;
  }

  .solver-layout .sidebar-menu-button,
  .solver-layout .history-sidebar .sidebar-close {
    display: grid;
  }

  .conversation-stream {
    width: min(var(--conversation-width), calc(100% - 32px));
    padding-top: 32px;
  }

  .empty-state,
  .loading-state {
    min-height: 280px;
  }

  .login-shell {
    padding: 18px;
  }

  .login-layout,
  .landing-hero,
  .feature-grid,
  .panel-grid,
  .history-detail-grid {
    grid-template-columns: 1fr;
  }

  .login-story {
    min-height: auto;
    padding: 30px;
  }

  .app-shell {
    width: min(100% - 24px, 720px);
    padding: 0 0 24px;
  }

  .landing-shell {
    width: min(100% - 24px, 720px);
  }

  .landing-copy,
  .hero-preview {
    min-height: auto;
    padding: 30px;
  }

}

@media (max-width: 560px) {
  .solver-topbar {
    min-height: 58px;
    padding: 8px 12px;
  }

  .conversation-stream {
    width: calc(100% - 24px);
    padding: 22px 0 16px;
  }

  .composer-dock {
    padding: 8px 12px 12px;
  }

  .composer-shell {
    min-width: 0;
  }

  .user-message .history-result-image-wrap {
    width: 92%;
  }
  .workspace.mobile-solution-mode #mobile-new-problem {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    border-color: var(--accent);
    padding: 0 18px;
    color: var(--accent-dark);
    white-space: nowrap;
  }

  .workspace.mobile-solution-mode .solution-output {
    display: grid;
  }

  .workspace.mobile-solution-mode .history-result-image-wrap {
    order: -2;
  }

  .workspace.mobile-solution-mode .final-answer {
    order: -1;
  }

  .login-card,
  .login-story {
    padding: 24px;
  }

  .login-metrics {
    grid-template-columns: 1fr;
  }

  .landing-copy,
  .hero-preview,
  .landing-section {
    padding: 24px;
  }

  .hero-strip {
    padding: 6px 10px;
  }

  .solve-form,
  .solution-output {
    padding: 20px;
  }

  .landing-band {
    align-items: flex-start;
    flex-direction: column;
  }

  .landing-actions,
  .button-row,
  .primary-link,
  .secondary-link,
  .button-row > button {
    width: 100%;
  }

  .scan-card,
  .equation-card,
  .answer-float {
    width: 100%;
    margin: 12px 0 0;
    transform: none;
  }

  .topbar {
    align-items: center;
  }

  .history-sidebar {
    width: min(340px, calc(100vw - 18px));
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .history-panel {
    padding: 20px;
  }

  .history-header,
  .history-detail-heading,
  .history-item {
    align-items: stretch;
    flex-direction: column;
  }

  .history-actions {
    justify-content: space-between;
  }

  .history-open-button {
    width: 100%;
  }

  .button-row {
    grid-template-columns: 1fr;
  }

  .drop-zone {
    min-height: 230px;
  }
}

/* Multimodal math chat */
.chat-message-list {
  display: grid;
  gap: 24px;
}

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 22px;
}

.suggestion-chips button {
  border: 1px solid var(--solver-border);
  border-radius: 999px;
  padding: 9px 13px;
  background: #fff;
  color: var(--solver-muted);
  cursor: pointer;
}

.composer-shell {
  position: relative;
  gap: 8px;
}

.chat-composer-input {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
  min-height: 58px;
  border: 1px solid var(--solver-border);
  border-radius: 24px;
  padding: 8px;
  background: #fff;
  box-shadow: 0 5px 22px rgba(0, 0, 0, 0.08);
}

#message-input {
  width: 100%;
  max-height: 160px;
  resize: none;
  border: 0;
  padding: 10px 4px;
  background: transparent;
  color: var(--solver-text);
  line-height: 1.5;
  outline: 0;
}

.attachment-control { position: relative; }

.attachment-menu-button,
.chat-send-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.3rem;
}

.attachment-menu-button { background: var(--solver-hover); color: var(--solver-text); }
.chat-send-button { background: var(--solver-text); color: #fff; }
.chat-send-button:disabled { opacity: 0.35; cursor: not-allowed; }

.attachment-menu {
  position: absolute;
  z-index: 20;
  left: 0;
  bottom: calc(100% + 12px);
  display: grid;
  min-width: 180px;
  overflow: hidden;
  border: 1px solid var(--solver-border);
  border-radius: 14px;
  padding: 6px;
  background: #fff;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.14);
}

.attachment-menu button {
  border: 0;
  border-radius: 9px;
  padding: 11px 12px;
  background: transparent;
  color: var(--solver-text);
  cursor: pointer;
  text-align: left;
}

.attachment-menu button:hover,
.attachment-menu button:focus-visible { background: var(--solver-hover); }

.composer-attachment-preview {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: min(100%, 360px);
  border: 1px solid var(--solver-border);
  border-radius: 14px;
  padding: 8px;
  background: #fff;
}

.composer-image-thumb,
.composer-image-thumb img {
  display: block;
  width: 48px;
  height: 48px;
  border-radius: 9px;
  object-fit: cover;
}

.composer-image-name {
  overflow: hidden;
  color: var(--solver-muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer-attachment-preview .remove-button {
  position: static;
  width: 34px;
  min-height: 34px;
  padding: 0;
}

.chat-user-row,
.chat-assistant-row {
  display: flex;
  gap: 10px;
}

.chat-user-row { justify-content: flex-end; }
.chat-user-bubble { max-width: min(78%, 620px); border-radius: 18px 18px 5px 18px; padding: 12px 15px; background: var(--solver-hover); white-space: pre-wrap; }
.chat-assistant-row { align-items: flex-start; }
.chat-assistant-bubble { min-width: 0; max-width: calc(100% - 40px); line-height: 1.7; white-space: pre-wrap; }
.chat-message-image { display: block; max-width: min(320px, 100%); max-height: 300px; margin-bottom: 8px; border-radius: 14px; object-fit: contain; }

@media (max-width: 560px) {
  .composer-dock { padding-inline: 10px; }
  .conversation-stream { width: calc(100% - 24px); }
  .suggestion-chips { display: grid; width: 100%; }
  .attachment-menu { max-width: calc(100vw - 32px); }
  .chat-user-bubble { max-width: 88%; }
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}

.profile-control { position: relative; justify-self: end; }

.profile-menu-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: transparent;
  cursor: pointer;
}

.profile-avatar {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  overflow: hidden;
  place-items: center;
  border: 1px solid var(--solver-border);
  border-radius: 50%;
  background: linear-gradient(145deg, var(--accent-soft), #fff);
  color: var(--accent-dark);
  font-weight: 800;
}

.profile-avatar img { width: 100%; height: 100%; object-fit: cover; }

.profile-menu {
  position: absolute;
  z-index: 40;
  top: calc(100% + 8px);
  right: 0;
  width: min(280px, calc(100vw - 24px));
  overflow: hidden;
  border: 1px solid var(--solver-border);
  border-radius: 16px;
  padding: 8px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(36, 36, 36, 0.16);
}

.profile-menu-identity {
  display: grid;
  gap: 3px;
  border-bottom: 1px solid var(--solver-border);
  padding: 10px 12px 12px;
}

.profile-menu-label { color: var(--solver-muted); font-size: 0.76rem; }

.profile-menu button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  padding: 0 12px;
  background: transparent;
  color: var(--solver-text);
  cursor: pointer;
  text-align: left;
}

.profile-menu button:hover,
.profile-menu button:focus-visible { background: var(--solver-hover); }
.profile-menu form { margin: 0; }

.profile-menu-error,
.profile-crop-error {
  margin: 6px 8px;
  color: var(--danger);
  font-size: 0.82rem;
  line-height: 1.45;
}

.profile-crop-dialog {
  width: min(540px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  overflow: auto;
  border: 0;
  border-radius: 22px;
  padding: 0;
  background: #fff;
  color: var(--solver-text);
  box-shadow: 0 28px 80px rgba(29, 24, 48, 0.28);
}

.profile-crop-dialog::backdrop { background: rgba(29, 24, 48, 0.64); }

.profile-crop-shell {
  display: grid;
  gap: 18px;
  padding: 24px;
}

.profile-crop-heading,
.profile-crop-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.profile-crop-heading h2,
.profile-crop-heading .eyebrow,
.profile-crop-help { margin-bottom: 0; }

.profile-crop-close {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 50%;
  background: var(--solver-hover);
  cursor: pointer;
  font-size: 1.4rem;
}

.profile-crop-help { color: var(--solver-muted); line-height: 1.55; }

.profile-crop-stage {
  position: relative;
  width: min(100%, 420px);
  aspect-ratio: 1;
  justify-self: center;
  overflow: hidden;
  border-radius: 18px;
  background: #eceaf2;
  cursor: grab;
  touch-action: none;
}

.profile-crop-stage:active { cursor: grabbing; }

.profile-crop-image {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  transform-origin: center;
  user-select: none;
  pointer-events: none;
}

.profile-crop-guide {
  position: absolute;
  inset: 8%;
  border: 2px solid rgba(255, 255, 255, 0.96);
  border-radius: 50%;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.56);
  pointer-events: none;
}

.profile-crop-actions { justify-content: flex-end; }

.profile-crop-actions button {
  min-width: 96px;
  min-height: 46px;
  border: 1px solid var(--solver-border);
  border-radius: 12px;
  padding: 0 18px;
  background: #fff;
  cursor: pointer;
  font-weight: 800;
}

#profile-crop-save {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.profile-menu-button:focus-visible,
.profile-crop-close:focus-visible,
.profile-crop-actions button:focus-visible {
  outline: 3px solid rgba(108, 92, 231, 0.28);
  outline-offset: 2px;
}

@media (max-width: 560px) {
  .profile-crop-dialog {
    width: calc(100% - 24px);
    max-height: calc(100dvh - 24px);
  }

  .profile-crop-shell { gap: 14px; padding: 18px; }

  .profile-crop-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .profile-crop-actions button { width: 100%; }
}
