/* ==========================================================================
   Math Agent API — Qwen2.5-Math-1.5B-Instruct
   Chạy hoàn toàn trong trình duyệt qua transformers.js + WebGPU
   ========================================================================== */

:root {
  --bg-deep: #0a0a14;
  --bg-mid: #12122a;
  --bg-soft: #1a1a3a;
  --accent: #7c5cff;
  --accent-2: #00d4ff;
  --accent-3: #ff6ec7;
  --text: #e8e8f5;
  --text-dim: #9a9ab8;
  --ok: #00e676;
  --err: #ff5252;
  --radius: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background:
    radial-gradient(ellipse 80% 60% at 20% 0%, rgba(124, 92, 255, 0.18), transparent),
    radial-gradient(ellipse 70% 50% at 80% 20%, rgba(0, 212, 255, 0.12), transparent),
    radial-gradient(ellipse 60% 50% at 50% 100%, rgba(255, 110, 199, 0.10), transparent),
    var(--bg-deep);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  padding: 0 1rem 3rem;
}

.wrap { max-width: 1100px; margin: 0 auto; }

/* ---------- Header ---------- */
header {
  text-align: center;
  padding: 2.5rem 0 1.5rem;
  animation: fadeUp 0.7s ease;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: linear-gradient(135deg, rgba(124,92,255,0.2), rgba(0,212,255,0.15));
  border: 1px solid rgba(124, 92, 255, 0.35);
  border-radius: 100px;
  padding: 0.4rem 1rem;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 1rem;
}

.badge .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
  animation: pulse 2s infinite;
}

h1 {
  font-size: clamp(1.9rem, 5vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(120deg, #fff 10%, var(--accent-2) 45%, var(--accent-3) 80%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.6rem;
}

.subtitle { color: var(--text-dim); font-size: 0.95rem; max-width: 620px; margin: 0 auto; }

/* ---------- Cards ---------- */
.card {
  background: rgba(26, 26, 58, 0.6);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(124, 92, 255, 0.18);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
  animation: fadeUp 0.7s ease both;
  transition: border-color 0.3s, transform 0.3s;
}

.card:hover { border-color: rgba(124, 92, 255, 0.4); }
.card:nth-of-type(2) { animation-delay: 0.08s; }
.card:nth-of-type(3) { animation-delay: 0.16s; }
.card:nth-of-type(4) { animation-delay: 0.24s; }

.card h2 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.9rem;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.card h2 .ico { font-size: 1.15rem; }

/* ---------- Labels & inputs ---------- */
label {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.45rem;
  font-weight: 600;
}

textarea, input[type="number"] {
  width: 100%;
  background: rgba(10, 10, 20, 0.65);
  border: 1px solid rgba(124, 92, 255, 0.25);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.85rem 1rem;
  resize: vertical;
  transition: border-color 0.25s, box-shadow 0.25s;
}

textarea:focus, input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.15);
}

textarea { min-height: 110px; line-height: 1.6; }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; }

/* ---------- Buttons ---------- */
.btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0.8rem 1.6rem;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.25s, filter 0.2s;
  box-shadow: 0 4px 18px rgba(124, 92, 255, 0.35);
  position: relative;
  overflow: hidden;
}

.btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 8px 26px rgba(124, 92, 255, 0.5);
  filter: brightness(1.1);
}

.btn:active:not(:disabled) { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.secondary {
  background: rgba(124, 92, 255, 0.12);
  border: 1px solid rgba(124, 92, 255, 0.35);
  box-shadow: none;
  font-weight: 600;
}

.btn-row { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 1rem; }

/* ---------- Status ---------- */
.status {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.87rem;
  color: var(--text-dim);
  padding: 0.7rem 1rem;
  background: rgba(10, 10, 20, 0.5);
  border-radius: 10px;
  margin-top: 1rem;
}

.status.err { color: var(--err); border: 1px solid rgba(255, 82, 82, 0.3); }

.progress {
  height: 4px;
  background: rgba(124, 92, 255, 0.15);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 0.7rem;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* ---------- Output ---------- */
.output {
  background: rgba(10, 10, 20, 0.65);
  border: 1px solid rgba(124, 92, 255, 0.2);
  border-radius: 12px;
  padding: 1rem 1.15rem;
  font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 90px;
  max-height: 460px;
  overflow-y: auto;
  color: #d6d6e8;
}

.output:empty::before {
  content: 'Kết quả sẽ hiển thị ở đây…';
  color: var(--text-dim);
  font-style: italic;
}

.answer-box {
  margin-top: 1rem;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, rgba(0, 230, 118, 0.1), rgba(0, 212, 255, 0.08));
  border: 1px solid rgba(0, 230, 118, 0.3);
  border-radius: 12px;
  display: none;
  animation: fadeUp 0.4s ease;
}

.answer-box.show { display: block; }

.answer-box .lbl {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--ok);
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.answer-box .val {
  font-size: 1.5rem;
  font-weight: 800;
  font-family: 'JetBrains Mono', monospace;
  color: #fff;
  word-break: break-all;
}

/* ---------- Examples ---------- */
.examples { display: flex; flex-wrap: wrap; gap: 0.55rem; margin-top: 0.8rem; }

.chip {
  background: rgba(124, 92, 255, 0.1);
  border: 1px solid rgba(124, 92, 255, 0.28);
  border-radius: 100px;
  padding: 0.42rem 0.9rem;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.22s;
  color: var(--text-dim);
}

.chip:hover {
  background: rgba(124, 92, 255, 0.24);
  color: #fff;
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* ---------- API block ---------- */
pre {
  background: rgba(10, 10, 20, 0.75);
  border: 1px solid rgba(124, 92, 255, 0.2);
  border-radius: 10px;
  padding: 1rem;
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.7;
  color: #9fe8ff;
  margin-top: 0.7rem;
}

pre .c { color: #6b6b8a; }
pre .k { color: var(--accent-3); }
pre .s { color: var(--ok); }

code {
  font-family: 'JetBrains Mono', Consolas, monospace;
  background: rgba(124, 92, 255, 0.14);
  padding: 0.12rem 0.4rem;
  border-radius: 5px;
  font-size: 0.85em;
}

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; margin-top: 0.7rem; font-size: 0.85rem; }

th, td { padding: 0.6rem 0.7rem; text-align: left; border-bottom: 1px solid rgba(124, 92, 255, 0.14); }

th { color: var(--text-dim); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }

td.mono { font-family: 'JetBrains Mono', monospace; color: #9fe8ff; }

footer { text-align: center; color: var(--text-dim); font-size: 0.8rem; padding: 2rem 0 1rem; }

footer a { color: var(--accent-2); text-decoration: none; }
footer a:hover { text-decoration: underline; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

@media (max-width: 640px) {
  header { padding: 1.8rem 0 1rem; }
  .card { padding: 1.1rem; }
}
