/* ============================================================
   Chuyển đổi đơn vị Toán học — giao diện
   Phong cách: sáng, tông teal/emerald, thân thiện học sinh
   ============================================================ */
:root {
  --bg:        #eef5f4;
  --bg-2:      #e2eeec;
  --surface:   #ffffff;
  --line:      #dde8e6;
  --ink:       #12312f;
  --ink-2:     #4d635f;
  --ink-3:     #849792;

  --primary:   #0ea5a4;   /* teal tươi */
  --primary-d: #0b8382;
  --primary-l: #e2f7f6;

  --accent:    #f2a53b;   /* cam ấm cho điểm nhấn */
  --ok:        #14a35a;

  --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(18,49,47,.06), 0 3px 12px rgba(18,49,47,.05);
  --shadow-md: 0 8px 26px rgba(18,49,47,.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%, #e2f7ec 0%, transparent 58%),
    radial-gradient(900px 440px at -6% 0%, #dff2f8 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.page { max-width: 900px; 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(14,165,164,.3); }

/* ---------- Tiêu đề ---------- */
.hero { text-align: center; margin: 6px 0 22px; }
.hero__title {
  font-size: clamp(1.7rem, 4.4vw, 2.5rem);
  font-weight: 900;
  letter-spacing: -.02em;
  line-height: 1.12;
  background: linear-gradient(120deg, #0b8382, #12a3b0 50%, #2fae7a);
  -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;
}

/* ---------- Chip chọn loại ---------- */
.cats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 22px;
}
.cat {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 800;
  color: var(--ink-2);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 9px 15px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all .16s;
}
.cat:hover { border-color: var(--primary); color: var(--primary-d); transform: translateY(-1px); }
.cat.is-on { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 5px 16px rgba(14,165,164,.4); }
.cat:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(14,165,164,.32); }

/* ---------- Khối chuyển đổi ---------- */
.converter { animation: fade .25s ease; }
.converter[hidden], .allunits[hidden], .note[hidden], .banner[hidden] { display: none; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.conv {
  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;
}
.conv__side { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.conv__label { font-size: 13px; font-weight: 800; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }
.conv__value {
  font-family: var(--font);
  font-size: clamp(1.3rem, 4.5vw, 1.7rem);
  font-weight: 900;
  color: var(--ink);
  background: var(--bg);
  border: 2px solid var(--line);
  border-radius: var(--r-md);
  padding: 13px 15px;
  width: 100%;
  font-variant-numeric: tabular-nums;
}
.conv__value:focus-visible { outline: none; border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(14,165,164,.16); }
.conv__value--out {
  display: flex; align-items: center;
  color: var(--primary-d);
  background: var(--primary-l);
  border-color: transparent;
  overflow-x: auto; white-space: nowrap;
  min-height: 60px;
}

.swap {
  display: grid; place-items: center;
  width: 46px; height: 46px;
  margin-bottom: 6px;
  color: var(--primary-d);
  background: var(--primary-l);
  border: none; border-radius: 50%;
  cursor: pointer;
  transition: transform .2s, background .15s;
}
.swap:hover { background: #cdeeed; }
.swap:active { transform: rotate(180deg); }
.swap:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(14,165,164,.32); }

/* Select tùy biến */
.select { position: relative; }
.select select {
  width: 100%;
  appearance: none;
  font-family: var(--font);
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-sm);
  padding: 11px 38px 11px 13px;
  cursor: pointer;
}
.select select:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,165,164,.16); }
.select__caret { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }

.banner {
  margin-top: 14px;
  text-align: center;
  font-size: clamp(1.05rem, 3.6vw, 1.35rem);
  font-weight: 800;
  color: var(--ink);
  background: var(--bg);
  border-radius: var(--r-md);
  padding: 14px 16px;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}
.banner strong { color: var(--primary-d); }

/* ---------- Bảng mọi đơn vị ---------- */
.allunits { margin-top: 22px; animation: fade .25s ease; }
.section__title { font-size: 1.1rem; font-weight: 900; margin-bottom: 14px; }
.allunits__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}
.ucell {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px 16px;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, transform .15s;
}
.ucell:hover { transform: translateY(-2px); }
.ucell__unit { font-size: 13px; font-weight: 800; color: var(--ink-3); margin-bottom: 4px; }
.ucell__val { font-size: 1.15rem; font-weight: 900; color: var(--ink); font-variant-numeric: tabular-nums; word-break: break-word; }
.ucell.is-from { border-color: var(--accent); background: #fff7ec; }
.ucell.is-to   { border-color: var(--primary); background: var(--primary-l); }
.ucell.is-from .ucell__val { color: #b9741a; }
.ucell.is-to   .ucell__val { color: var(--primary-d); }

/* ---------- Ghi chú ---------- */
.note {
  margin-top: 22px;
  background: var(--primary-l);
  border: 1px solid #c7ecea;
  border-radius: var(--r-lg);
  padding: 18px 20px;
}
.note__title { font-size: 1rem; font-weight: 900; margin-bottom: 6px; color: var(--primary-d); }
.note__body { font-size: .96rem; font-weight: 600; color: var(--ink-2); line-height: 1.6; }

/* ---------- Responsive ---------- */
@media (max-width: 620px) {
  .page { padding: 12px 12px 40px; }
  .conv {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 18px 16px;
  }
  .swap {
    justify-self: center;
    margin: -2px 0;
    transform: rotate(90deg);
  }
  .swap:active { transform: rotate(270deg); }
  .conv__value { font-size: 1.35rem; }
  .allunits__grid { grid-template-columns: 1fr 1fr; gap: 10px; }
}

@media (max-width: 380px) {
  .cat { font-size: 13px; padding: 8px 12px; }
  .allunits__grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .converter, .allunits, .cat, .ucell, .back, .swap { transition: none; animation: none; }
}