:root {
  --ink: #1a2332;
  --ink-soft: #3d4a5c;
  --paper: #f0f4f8;
  --paper-elevated: rgba(255, 255, 255, 0.88);
  --accent: #0d7a6f;
  --accent-hover: #0a6259;
  --accent-soft: rgba(13, 122, 111, 0.12);
  --error: #b42318;
  --error-bg: #fef3f2;
  --line: rgba(26, 35, 50, 0.12);
  --shadow: 0 12px 40px rgba(26, 35, 50, 0.1);
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
  --radius: 10px;
  --max: 46rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.6;
  color: var(--ink);
  background: var(--paper);
  display: flex;
  flex-direction: column;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(13, 122, 111, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 40% at 90% 0%, rgba(45, 90, 140, 0.14), transparent 50%),
    linear-gradient(165deg, #e8eef5 0%, #f0f4f8 40%, #e4ebe8 100%);
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.site-header {
  padding: 1.25rem 1.5rem;
  max-width: calc(var(--max) + 3rem);
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
}

.auth-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.65rem;
  opacity: 0;
  animation: fade-up 0.6s ease 0.1s forwards;
}

.quota-label {
  font-size: 0.85rem;
  color: var(--ink-soft);
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.quota-label strong {
  color: var(--accent);
  font-weight: 700;
}

.quota-role {
  font-weight: 600;
  color: var(--ink);
}

.quota-sep {
  opacity: 0.45;
}

.quota-used {
  opacity: 0.75;
  font-size: 0.8rem;
}

.quota-warn {
  color: #b42318;
  font-size: 0.78rem;
}

.auth-status {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  max-width: 10rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-btn.is-hidden,
.auth-btn[hidden] {
  display: none !important;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: -0.02em;
  opacity: 0;
  animation: fade-up 0.6s ease 0.05s forwards;
}

main {
  flex: 1;
  width: 100%;
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1.5rem 3rem;
}

.hero {
  padding-top: 2rem;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.4rem, 7vw, 3.5rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin: 0 0 0.75rem;
  color: var(--ink);
  opacity: 0;
  animation: fade-up 0.7s ease 0.15s forwards;
}

.lede {
  margin: 0 0 2rem;
  color: var(--ink-soft);
  font-size: 1.125rem;
  max-width: 34rem;
  opacity: 0;
  animation: fade-up 0.7s ease 0.28s forwards;
}

.solver {
  opacity: 0;
  animation: fade-up 0.7s ease 0.4s forwards;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Math keyboard panel */
.math-keyboard {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: fade-up 0.25s ease;
}

.kb-top {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid var(--line);
  background: #f7fafb;
}

.suite-tabs {
  display: flex;
  flex: 1;
  flex-wrap: wrap;
  gap: 0;
  overflow-x: auto;
}

.suite-tab {
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.75rem 0.85rem;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.suite-tab:hover {
  color: var(--ink);
  background: rgba(13, 122, 111, 0.06);
}

.suite-tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.kb-close {
  width: 2.75rem;
  border: none;
  border-left: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.kb-close:hover {
  color: var(--ink);
  background: rgba(0, 0, 0, 0.04);
}

.suite-panels {
  padding: 0.85rem;
}

.suite-panel[hidden] {
  display: none;
}

.symbol-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(3.4rem, 1fr));
  gap: 0.45rem;
}

.sym-btn {
  font-family: var(--font-body);
  min-height: 2.7rem;
  padding: 0.35rem 0.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafcfd;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}

.sym-btn .katex {
  font-size: 1.05em;
}

.sym-btn:hover:not(:disabled) {
  background: var(--accent-soft);
  border-color: rgba(13, 122, 111, 0.35);
}

.sym-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.sym-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* Composer (chat-style input) */
.composer {
  background: var(--paper-elevated);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 0.85rem 1rem 0.75rem;
}

.composer textarea {
  width: 100%;
  border: none;
  resize: none;
  outline: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 1.05rem;
  line-height: 1.5;
  color: var(--ink);
  min-height: 2.8rem;
  padding: 0.25rem 0.15rem;
}

.composer textarea::placeholder {
  color: #8a96a5;
}

.math-field-wrap {
  margin-top: 0.35rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--line);
}

.photo-upload {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--line);
}

.photo-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.photo-btn {
  cursor: pointer;
}

.photo-name {
  font-size: 0.85rem;
  color: var(--ink-soft);
  max-width: 14rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.photo-hint {
  margin: 0.45rem 0 0;
  font-size: 0.8rem;
  color: #7a8796;
}

.photo-preview {
  display: block;
  margin-top: 0.65rem;
  max-width: 100%;
  max-height: 180px;
  border-radius: 8px;
  border: 1px solid var(--line);
  object-fit: contain;
  background: #fff;
}

.math-field-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: #7a8796;
  margin-bottom: 0.35rem;
}

math-field {
  display: block;
  width: 100%;
  min-height: 2.75rem;
  padding: 0.45rem 0.55rem;
  font-size: 1.35rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  outline: none;
}

math-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

.composer-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.tool-btn {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tool-btn:hover {
  color: var(--ink);
  background: #f4f7f8;
}

.tool-btn.is-active,
.math-input-btn.is-active {
  color: var(--accent);
  border-color: rgba(13, 122, 111, 0.45);
  background: var(--accent-soft);
}

.tool-icon {
  font-family: var(--font-display);
  font-weight: 700;
}

.send-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.55rem 0.95rem 0.55rem 1.1rem;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.send-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.send-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.send-btn.is-loading .send-label {
  opacity: 0.9;
}

.send-btn.is-loading .send-arrow {
  animation: pulse-arrow 0.9s ease-in-out infinite;
}

.loading-panel {
  margin-top: 1.5rem;
  padding: 1.5rem 1.25rem;
  background: var(--paper-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-align: center;
  animation: fade-up 0.35s ease;
}

.loading-spinner {
  display: flex;
  justify-content: center;
  gap: 0.45rem;
  margin-bottom: 0.85rem;
}

.loading-spinner span {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce-dot 1.1s ease-in-out infinite;
}

.loading-spinner span:nth-child(2) {
  animation-delay: 0.15s;
}

.loading-spinner span:nth-child(3) {
  animation-delay: 0.3s;
}

.loading-text {
  margin: 0 0 1rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.loading-bar {
  width: 100%;
  max-width: 16rem;
  height: 4px;
  margin: 0 auto 0.75rem;
  border-radius: 999px;
  background: rgba(13, 122, 111, 0.15);
  overflow: hidden;
}

.loading-bar-fill {
  width: 40%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #1a9e90);
  animation: loading-slide 1.35s ease-in-out infinite;
}

.loading-hint {
  margin: 0;
  font-size: 0.875rem;
  color: var(--ink-soft);
}

@keyframes bounce-dot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  40% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

@keyframes loading-slide {
  0% {
    transform: translateX(-120%);
  }
  100% {
    transform: translateX(320%);
  }
}

@keyframes pulse-arrow {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(0.88);
    opacity: 0.7;
  }
}

.send-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  font-size: 0.95rem;
  line-height: 1;
}

.result {
  margin-top: 2.5rem;
  padding-top: 2rem;
  border-top: 1px solid var(--line);
  animation: fade-up 0.5s ease forwards;
}

.result h2 {
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 1rem;
  letter-spacing: -0.02em;
}

.solution {
  margin: 0;
  padding: 1.25rem 1.35rem;
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-wrap: break-word;
  background: var(--paper-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--ink);
  overflow-x: auto;
}

.solution .katex-display {
  margin: 0.75rem 0;
  overflow-x: auto;
  overflow-y: hidden;
}

.error {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  background: var(--error-bg);
  color: var(--error);
  border-radius: 8px;
  font-size: 0.95rem;
  animation: fade-up 0.35s ease forwards;
}

.site-footer {
  padding: 1.5rem;
  text-align: center;
  color: var(--ink-soft);
  font-size: 0.875rem;
}

.site-footer p {
  margin: 0;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 560px) {
  .hero {
    padding-top: 1rem;
  }

  .symbol-grid {
    grid-template-columns: repeat(auto-fill, minmax(2.9rem, 1fr));
  }

  .suite-tab {
    font-size: 0.8rem;
    padding: 0.65rem 0.55rem;
  }

  .send-label {
    display: none;
  }

  .send-btn {
    padding: 0.45rem;
    border-radius: 50%;
  }

  .send-arrow {
    width: 2.2rem;
    height: 2.2rem;
  }
}
