/* ============================================================
   Bảng tuần hoàn nguyên tố hoá học — giao diện
   Phong cách: sáng, nhiều màu phân loại, sạch sẽ, hiện đại
   ============================================================ */
:root {
  --bg:        #eef2f7;
  --surface:   #ffffff;
  --line:      #e2e8f0;
  --ink:       #1b2436;
  --ink-2:     #56617a;
  --ink-3:     #8792a8;
  --primary:   #3f6fe0;
  --primary-d: #2f57bd;
  --primary-l: #e8f0ff;

  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --shadow-sm: 0 1px 2px rgba(27,36,54,.06), 0 3px 12px rgba(27,36,54,.05);
  --shadow-md: 0 10px 30px rgba(27,36,54,.14);

  /* Màu phân loại (nền sáng, chữ đậm dễ đọc) */
  --c-alkali:      #ff6b6b;
  --c-alkaline:    #f7a63b;
  --c-transition:  #35bdd6;
  --c-post:        #22c39a;
  --c-metalloid:   #a06be0;
  --c-nonmetal:    #3fb56b;
  --c-halogen:     #ec6ea3;
  --c-noble:       #f0b429;
  --c-lanthanide:  #7b7bf0;
  --c-actinide:    #17b3a0;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 82% -12%, #e6efff 0%, transparent 58%),
    radial-gradient(1000px 460px at -6% 0%, #eafaf3 0%, transparent 55%),
    var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.page { max-width: 1180px; margin: 0 auto; padding: 16px 18px 48px; }

/* ---------- Nút quay lại ---------- */
.topbar { display: flex; margin-bottom: 12px; }
.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, transform .05s;
}
.back:hover { color: var(--primary); }
.back:active { transform: scale(.97); }
.back:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(63,111,224,.3); }

/* ---------- Tiêu đề ---------- */
.hero { text-align: center; margin: 4px 0 20px; }
.hero__title {
  font-size: clamp(1.6rem, 4vw, 2.4rem);
  font-weight: 900; letter-spacing: -.02em; line-height: 1.12;
  background: linear-gradient(120deg, #2f57bd, #6b4de0 55%, #17b3a0);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.hero__desc {
  max-width: 660px; margin: 10px auto 0;
  font-size: clamp(.92rem, 2.2vw, 1.02rem);
  font-weight: 500; color: var(--ink-2); line-height: 1.55;
}

/* ---------- Điều khiển ---------- */
.controls {
  display: flex; flex-wrap: wrap; gap: 10px;
  justify-content: center; align-items: center;
  margin-bottom: 18px;
}
.fgroup { display: flex; flex-wrap: wrap; gap: 6px; }
.fbtn {
  font-family: var(--font); font-size: 13.5px; font-weight: 800;
  color: var(--ink-2);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px; cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all .15s;
}
.fbtn:hover { border-color: var(--primary); color: var(--primary-d); }
.fbtn.is-on { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(63,111,224,.4); }
.fbtn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(63,111,224,.32); }
.search {
  font-family: var(--font); font-size: 14px; font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 9px 16px; min-width: 240px;
  box-shadow: var(--shadow-sm);
}
.search:focus-visible { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(63,111,224,.16); }

/* ---------- Bảng ---------- */
.table-scroll { overflow-x: auto; padding-bottom: 8px; }
.table {
  display: grid;
  grid-template-columns: repeat(18, minmax(46px, 1fr));
  gap: 3px;
  min-width: 900px;
}

.el {
  position: relative;
  aspect-ratio: 1;
  border: none;
  border-radius: 7px;
  cursor: pointer;
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  color: #fff;
  font-family: var(--font);
  padding: 2px;
  transition: transform .12s, box-shadow .12s, opacity .2s;
  overflow: hidden;
}
.el:hover { transform: scale(1.14); box-shadow: var(--shadow-md); z-index: 5; }
.el:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; z-index: 5; }
.el.dim { opacity: .16; pointer-events: none; }
.el__z { position: absolute; top: 3px; left: 5px; font-size: 9.5px; font-weight: 700; opacity: .9; }
.el__sym { font-size: clamp(.85rem, 1.5vw, 1.15rem); font-weight: 900; line-height: 1; }
.el__name { font-size: 8.5px; font-weight: 700; opacity: .92; text-align: center; line-height: 1.05; margin-top: 2px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.el--marker { cursor: default; opacity: .9; }
.el--marker:hover { transform: none; box-shadow: none; }
.el--marker .el__sym { font-size: .7rem; }

/* Màu theo phân loại */
.alkali-metal { background: var(--c-alkali); }
.alkaline-earth-metal { background: var(--c-alkaline); }
.transition-metal { background: var(--c-transition); }
.post-transition-metal { background: var(--c-post); }
.metalloid { background: var(--c-metalloid); }
.nonmetal { background: var(--c-nonmetal); }
.halogen { background: var(--c-halogen); }
.noble-gas { background: var(--c-noble); }
.lanthanide { background: var(--c-lanthanide); }
.actinide { background: var(--c-actinide); }

/* ---------- Chú giải ---------- */
.legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px 16px;
  margin-top: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.legend__item { display: flex; align-items: center; gap: 9px; font-size: 13.5px; font-weight: 700; color: var(--ink-2); }
.dot { width: 16px; height: 16px; border-radius: 5px; flex-shrink: 0; }

/* ---------- Panel thông tin ---------- */
.scrim {
  position: fixed; inset: 0;
  background: rgba(27,36,54,.42);
  z-index: 40;
}
.panel {
  position: fixed;
  top: 0; right: 0; height: 100%;
  width: 360px; max-width: 88vw;
  background: var(--surface);
  box-shadow: -10px 0 40px rgba(27,36,54,.18);
  padding: 24px 22px;
  overflow-y: auto;
  z-index: 50;
  transform: translateX(100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
}
.panel.open { transform: translateX(0); }
.panel__close {
  position: absolute; top: 16px; right: 16px;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink-2); border-radius: 10px; cursor: pointer;
  transition: color .15s, background .15s;
}
.panel__close:hover { color: var(--ink); background: var(--bg); }
.panel__title { font-size: 1.3rem; font-weight: 900; margin: 4px 44px 16px 0; line-height: 1.2; }
.panel__badge { margin-bottom: 14px; }
.tag {
  display: inline-block; color: #fff;
  font-size: 12.5px; font-weight: 800;
  padding: 5px 12px; border-radius: 999px;
}

.panel__body .row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 14px; padding: 11px 0;
  border-bottom: 1px dashed var(--line);
}
.panel__body .row:last-child { border-bottom: none; }
.row__k { font-size: 13.5px; font-weight: 700; color: var(--ink-2); flex-shrink: 0; }
.row__v { font-size: 14.5px; font-weight: 800; color: var(--ink); text-align: right; }
.row__v sup { font-size: .7em; }

/* ---------- Responsive ---------- */
@media (max-width: 620px) {
  .page { padding: 12px 12px 36px; }
  .search { min-width: 0; width: 100%; }
  .controls { gap: 8px; }
  .table { min-width: 720px; gap: 2px; }
  .el__z { font-size: 8px; top: 2px; left: 3px; }
  .el__name { display: none; }
  .legend { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .el, .panel, .back, .fbtn { transition: none; }
}