/* ============================================================
   Cân bằng Phương trình Hoá học — giao diện
   Phong cách: sáng, tông xanh lá (emerald), thân thiện học sinh
   ============================================================ */
:root {
  --bg:        #eef6f1;
  --bg-2:      #e2efe7;
  --surface:   #ffffff;
  --line:      #dcece3;
  --ink:       #14312a;
  --ink-2:     #506861;
  --ink-3:     #83988f;

  --primary:   #059669;   /* emerald */
  --primary-d: #047857;
  --primary-l: #d9f5e8;

  --accent:    #ea9a2e;
  --err:       #e5484d;
  --err-bg:    #fdecec;
  --err-line:  #f3b4b0;

  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(20,49,42,.06), 0 3px 12px rgba(20,49,42,.05);
  --shadow-md: 0 8px 26px rgba(20,49,42,.10);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 480px at 82% -12%, #d9f7e6 0%, transparent 58%),
    radial-gradient(900px 440px at -6% 0%, #dbf1f2 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.page { max-width: 820px; margin: 0 auto; padding: 16px 18px 56px; }

/* ---------- Nút quay lại ---------- */
.topbar { display: flex; margin-bottom: 14px; }
.back {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font); font-size: 14.5px; font-weight: 700;
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 15px 8px 12px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: color .15s, background .15s, transform .05s;
}
.back:hover { color: var(--primary); }
.back:active { transform: scale(.97); }
.back:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(5,150,105,.3); }

/* ---------- Tiêu đề ---------- */
.hero { text-align: center; margin: 6px 0 22px; }
.hero__title {
  font-size: clamp(1.7rem, 4.4vw, 2.4rem);
  font-weight: 900; letter-spacing: -.02em; line-height: 1.12;
  background: linear-gradient(120deg, #047857, #059669 50%, #0891b2);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero__desc {
  max-width: 620px; margin: 10px auto 0;
  font-size: clamp(.95rem, 2.3vw, 1.05rem);
  font-weight: 500; color: var(--ink-2); line-height: 1.55;
}

/* ---------- Nhập phương trình ---------- */
.builder {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: end;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}
.builder__side { display: flex; flex-direction: column; gap: 9px; min-width: 0; }
.builder__label { font-size: 13px; font-weight: 800; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.builder__input {
  font-family: var(--font);
  font-size: 1.15rem; font-weight: 800;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  padding: 13px 15px; width: 100%;
}
.builder__input::placeholder { color: var(--ink-3); font-weight: 700; }
.builder__input:focus-visible { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(5,150,105,.16); }
.builder__arrow { display: grid; place-items: center; width: 44px; height: 50px; color: var(--primary); }

/* ---------- Xem trước ---------- */
.preview {
  text-align: center;
  min-height: 30px;
  margin: 16px 0 4px;
  font-size: clamp(1.15rem, 4vw, 1.5rem);
  font-weight: 800;
  color: var(--ink);
}
.preview sub { font-size: .62em; font-weight: 700; }
.preview .arrow { color: var(--primary); margin: 0 .35em; }

/* ---------- Nút ---------- */
.actions { display: flex; justify-content: center; margin: 8px 0 20px; }
.btn {
  font-family: var(--font); font-weight: 800; font-size: 16px;
  border: none; border-radius: var(--r-sm); cursor: pointer;
  transition: background .15s, transform .05s, box-shadow .15s;
}
.btn--primary {
  background: var(--primary); color: #fff;
  padding: 14px 32px;
  box-shadow: 0 3px 10px rgba(5,150,105,.35);
}
.btn--primary:hover { background: var(--primary-d); }
.btn--primary:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(5,150,105,.35); }

/* ---------- Chip ví dụ ---------- */
.chips { display: flex; flex-direction: column; gap: 10px; align-items: center; margin-bottom: 16px; }
.chips__label { font-size: 13px; font-weight: 800; color: var(--ink-3); }
.chips__list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  font-family: var(--font); font-weight: 700; font-size: 13.5px;
  color: var(--ink-2);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all .15s;
}
.chip:hover { border-color: var(--primary); color: var(--primary-d); }
.chip sub { font-size: .7em; }

.hint {
  font-size: 13px; font-weight: 500; color: var(--ink-3);
  text-align: center; line-height: 1.6; max-width: 620px;
  margin: 0 auto 8px;
}
.hint code {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 12px; background: var(--bg-2);
  border-radius: 5px; padding: 1px 6px; color: var(--ink-2);
}

/* ---------- Kết quả ---------- */
.result { margin-top: 20px; animation: fade .25s ease; }
.result[hidden], .check[hidden], .alert[hidden] { display: none; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.result__eq {
  text-align: center;
  font-size: clamp(1.5rem, 6vw, 2.2rem);
  font-weight: 900;
  color: var(--ink);
  background: var(--primary-l);
  border: 1px solid #b6ecd3;
  border-radius: var(--r-lg);
  padding: 24px 18px;
  line-height: 1.5;
  word-break: break-word;
}
.result__eq .coef { color: var(--primary-d); margin-right: .04em; }
.result__eq sub { font-size: .6em; font-weight: 800; }
.result__eq .arrow { color: var(--primary); margin: 0 .3em; }
.result__eq .plus { color: var(--ink-3); margin: 0 .28em; }

/* ---------- Bảng đối chiếu ---------- */
.check { margin-top: 22px; animation: fade .25s ease; }
.section__title { font-size: 1.1rem; font-weight: 900; margin-bottom: 14px; }
.check__table {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.acell {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  padding: 13px 16px;
  box-shadow: var(--shadow-sm);
}
.acell__el { font-size: 15px; font-weight: 900; color: var(--primary-d); margin-bottom: 6px; }
.acell__cmp { display: flex; align-items: baseline; gap: 8px; font-variant-numeric: tabular-nums; }
.acell__n { font-size: 1.35rem; font-weight: 900; color: var(--ink); }
.acell__lbl { font-size: 12px; font-weight: 700; color: var(--ink-3); }
.acell__eq { margin: 0 2px; color: var(--primary); font-weight: 900; }

/* ---------- Cảnh báo ---------- */
.alert {
  margin-top: 18px;
  font-size: 14px; font-weight: 600; line-height: 1.5;
  color: var(--err);
  background: var(--err-bg);
  border: 1px solid var(--err-line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  text-align: center;
}

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .page { padding: 12px 12px 40px; }
  .builder { grid-template-columns: 1fr; gap: 12px; padding: 18px 16px; }
  .builder__arrow { transform: rotate(90deg); height: 32px; }
  .check__table { grid-template-columns: 1fr 1fr; gap: 10px; }
}

@media (max-width: 380px) {
  .check__table { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .result, .check, .chip, .back, .btn { transition: none; animation: none; }
}