/* MathGPT clone - dark theme styling (static demo build) */

:root {
  --bg: #0b0d14;
  --bg-soft: #12141f;
  --card: #171a28;
  --card-border: #262a3d;
  --input-bg: #1c2032;
  --text: #eef0f8;
  --text-dim: #9aa1b9;
  --accent: #7c5cff;
  --accent-2: #4f8cff;
  --accent-hover: #8f74ff;
  --danger: #ff5c74;
  --success: #38d39f;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over display rules on classes */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  background:
    radial-gradient(1000px 500px at 50% -10%, rgba(124, 92, 255, 0.16), transparent 60%),
    radial-gradient(800px 400px at 90% 10%, rgba(79, 140, 255, 0.10), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  line-height: 1.55;
  min-height: 100vh;
}

button { font-family: inherit; }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* ---------- Static demo banner ---------- */

.static-banner {
  background: linear-gradient(90deg, rgba(124, 92, 255, 0.18), rgba(79, 140, 255, 0.18));
  border-bottom: 1px solid rgba(124, 92, 255, 0.35);
  color: var(--text);
  font-size: 0.85rem;
  text-align: center;
  padding: 8px 16px;
}
.static-banner a { color: #cdc3ff; font-weight: 600; }

/* ---------- Header ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px clamp(16px, 4vw, 48px);
  position: sticky;
  top: 0;
  backdrop-filter: blur(10px);
  background: rgba(11, 13, 20, 0.75);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  font-size: 1.15rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-link {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.95rem;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 8px;
}
.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.06); }

.nav-user { color: var(--text-dim); font-size: 0.95rem; }

/* ---------- Buttons ---------- */

.btn {
  border: none;
  border-radius: 10px;
  padding: 9px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.12); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--card-border);
}
.btn-ghost:hover { background: rgba(255,255,255,0.06); }

.btn-block { width: 100%; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent-2);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }

/* ---------- Layout ---------- */

.page {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 clamp(16px, 4vw, 32px) 80px;
}

.hero { text-align: center; padding: 56px 0 28px; }

.hero-title {
  font-size: clamp(2.6rem, 7vw, 4rem);
  margin: 0 0 10px;
  letter-spacing: -0.02em;
}

.hero-title .grad {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-subtitle {
  color: var(--text-dim);
  font-size: clamp(1rem, 2.4vw, 1.15rem);
  max-width: 560px;
  margin: 0 auto;
}

/* ---------- Solver card ---------- */

.solver-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

#problem-input {
  width: 100%;
  resize: vertical;
  min-height: 74px;
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1.05rem;
  padding: 12px 14px;
  outline: none;
  font-family: inherit;
}
#problem-input:focus { border-color: var(--accent); }
#problem-input::placeholder { color: #5d647e; }

.solver-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.toolbar-left { display: flex; align-items: center; gap: 12px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 0.9rem;
  cursor: pointer;
}
.icon-btn:hover { color: var(--text); background: rgba(255,255,255,0.05); }

.hint { color: #5d647e; font-size: 0.82rem; }

.btn-solve { min-width: 120px; }

.btn-solve.loading #solve-btn-label { visibility: hidden; }
.btn-solve.loading::after {
  content: "";
  position: absolute;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
.btn-solve { position: relative; display: inline-flex; align-items: center; justify-content: center; }

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

.image-preview {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  background: var(--input-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 8px;
}
.image-preview img {
  max-height: 72px;
  max-width: 120px;
  border-radius: 6px;
}
.image-preview-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--text-dim);
  overflow: hidden;
}
#image-preview-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 340px; }

/* ---------- Examples ---------- */

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin: 18px 0 8px;
}

.chip {
  background: rgba(124, 92, 255, 0.10);
  border: 1px solid rgba(124, 92, 255, 0.35);
  color: #cdc3ff;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s ease;
}
.chip:hover { background: rgba(124, 92, 255, 0.22); }

/* ---------- Errors and notices ---------- */

.error-box {
  margin-top: 18px;
  background: rgba(255, 92, 116, 0.10);
  border: 1px solid rgba(255, 92, 116, 0.45);
  color: #ffb3c0;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.95rem;
}

.notice {
  background: rgba(79, 140, 255, 0.10);
  border: 1px solid rgba(79, 140, 255, 0.4);
  color: #b9d2ff;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.88rem;
}

/* ---------- Solution ---------- */

.solution {
  margin-top: 26px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 22px clamp(16px, 3vw, 28px);
  box-shadow: var(--shadow);
}

.solution-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.solution-head h2 { margin: 0 0 6px; font-size: 1.35rem; }

.source-tag {
  font-size: 0.75rem;
  color: var(--text-dim);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}

.interpreted { color: var(--text-dim); font-size: 0.95rem; margin: 6px 0 18px; }
.interpreted-label { color: var(--text); font-weight: 600; }

.steps {
  list-style: none;
  counter-reset: step;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.step {
  counter-increment: step;
  background: var(--bg-soft);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 14px 16px 14px 56px;
  position: relative;
}

.step::before {
  content: counter(step);
  position: absolute;
  left: 14px;
  top: 14px;
  width: 28px; height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}

.step-title { font-weight: 600; margin: 0 0 2px; }
.step-detail { color: var(--text-dim); font-size: 0.92rem; margin: 0 0 8px; }
.step-math { overflow-x: auto; padding: 4px 0; }

.answer-card {
  margin-top: 20px;
  border: 1px solid rgba(56, 211, 159, 0.45);
  background: rgba(56, 211, 159, 0.07);
  border-radius: 10px;
  padding: 14px 18px;
}

.answer-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--success);
  margin-bottom: 6px;
}

.answer-latex { font-size: 1.15rem; overflow-x: auto; }
.answer-text { color: var(--text-dim); font-size: 0.92rem; margin-top: 4px; }

.graph-wrap { margin-top: 22px; }
.graph-wrap h3 { margin: 0 0 10px; font-size: 1.05rem; color: var(--text-dim); }

/* ---------- Features ---------- */

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px;
  margin-top: 56px;
}

.feature {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 18px;
}
.feature h3 { margin: 0 0 6px; font-size: 1rem; }
.feature p { margin: 0; color: var(--text-dim); font-size: 0.88rem; }

/* ---------- Footer ---------- */

.site-footer {
  text-align: center;
  color: #5d647e;
  font-size: 0.85rem;
  padding: 26px 16px 40px;
}
.site-footer a { color: #8d94ab; }

/* ---------- History drawer ---------- */

.drawer {
  position: fixed;
  top: 0; right: 0;
  height: 100vh;
  width: min(380px, 92vw);
  background: var(--bg-soft);
  border-left: 1px solid var(--card-border);
  z-index: 40;
  padding: 18px;
  overflow-y: auto;
  box-shadow: -20px 0 60px rgba(0,0,0,0.5);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.drawer-head h2 { margin: 0; font-size: 1.2rem; }
.drawer-head-actions { display: flex; align-items: center; gap: 14px; }

.drawer-backdrop, .modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 10, 0.65);
  z-index: 30;
}

.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.history-item {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-item-main {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  padding: 0;
  overflow: hidden;
}
.history-problem {
  display: block;
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-answer {
  display: block;
  color: var(--text-dim);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-date { display: block; color: #5d647e; font-size: 0.72rem; margin-top: 2px; }

.history-delete {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}
.history-delete:hover { color: var(--danger); background: rgba(255,92,116,0.1); }

.history-empty { color: var(--text-dim); font-size: 0.92rem; }

/* ---------- KaTeX sizing ---------- */

.katex { font-size: 1.05em; }
.answer-latex .katex { font-size: 1.2em; }

/* ---------- Responsive ---------- */

@media (max-width: 560px) {
  .site-nav .btn { padding: 7px 12px; font-size: 0.85rem; }
  .hero { padding: 36px 0 20px; }
  .solver-toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left { justify-content: space-between; }
  .btn-solve { width: 100%; }
  .step { padding-left: 50px; }
  .static-banner { font-size: 0.78rem; }
}
