/* ===== Thanh công cụ, tiến độ, thông báo, mục lục ===== */

/* ---------- Thanh công cụ ---------- */
#toolbar {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 2px;
  max-width: calc(100vw - 32px);
  overflow-x: auto;
  padding: 6px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(16, 23, 42, 0.86), rgba(7, 11, 23, 0.9));
  border: 1px solid rgba(150, 205, 232, 0.28);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: opacity 0.35s ease, transform 0.35s ease;
  scrollbar-width: none;
}
body.idle #toolbar:not(:hover):not(:focus-within) {
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
}

#toolbar button {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #d8e3ef;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
}
#toolbar button:hover { background: rgba(150, 205, 232, 0.12); color: #ffffff; }
#toolbar button:focus-visible { outline: 2px solid var(--plat); outline-offset: -2px; }
#toolbar button.active {
  background: linear-gradient(135deg, #f2f7fc, #9db2c8);
  color: #07131f;
  box-shadow: 0 0 18px rgba(150, 205, 232, 0.45);
}
#toolbar svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#toolbar svg .fill { fill: currentColor; }

.count { font-variant-numeric: tabular-nums; white-space: nowrap; }
.count b { font-family: var(--display); font-weight: 700; font-size: 16px; letter-spacing: 0.04em; color: #e2f3ff; }
.count span { margin-left: 4px; font-size: 12px; color: var(--muted); }
#counter { flex: none; min-width: 64px; text-align: center; }

.sep {
  flex: none;
  width: 1px;
  height: 22px;
  margin: 0 6px;
  background: linear-gradient(180deg, transparent, rgba(150, 205, 232, 0.4), transparent);
}

.swatches { display: flex; gap: 1px; margin-left: 4px; }
#toolbar .swatch { width: 26px; }
#toolbar .swatch::before {
  content: "";
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
}
#toolbar .swatch.active { background: rgba(150, 205, 232, 0.14); box-shadow: none; }
#toolbar .swatch.active::before { box-shadow: 0 0 0 2px var(--plat-bright); }

/* ---------- Thanh tiến độ: sợi chỉ vàng ---------- */
#progress {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  height: 2px;
  background: rgba(150, 205, 232, 0.1);
  transition: opacity 0.4s ease;
}
#progress .fill {
  position: relative;
  display: block;
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, rgba(120, 150, 180, 0.25), #cbe9fb);
  box-shadow: 0 0 10px rgba(190, 228, 248, 0.55);
  transition: width 0.7s cubic-bezier(0.22, 0.8, 0.16, 1);
}
#progress .fill::after {
  content: "";
  position: absolute;
  right: -3px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #ffffff;
  transform: translateY(-50%);
  box-shadow: 0 0 10px 3px rgba(190, 228, 248, 0.8);
}
#progress i {
  position: absolute;
  top: -3px;
  width: 1px;
  height: 8px;
  background: rgba(190, 228, 248, 0.55);
}
body.idle #progress { opacity: 0.35; }

/* ---------- Toast + nhảy slide ---------- */
#toast, #goto {
  position: fixed;
  left: 50%;
  z-index: 60;
  transform: translateX(-50%);
  padding: 11px 18px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(16, 23, 42, 0.92), rgba(7, 11, 23, 0.94));
  border: 1px solid rgba(150, 205, 232, 0.35);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.5);
  font-size: 14px;
  color: #e3ecf6;
  pointer-events: none;
}
#toast { top: 18px; opacity: 0; transition: opacity 0.3s ease, transform 0.3s ease; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 4px); }
#goto { top: 50%; padding: 16px 26px; font-family: var(--display); font-size: 24px; font-weight: 700; letter-spacing: 0.08em; color: #e2f3ff; }
#goto[hidden] { display: none; }

/* ---------- Mục lục (G) ---------- */
#grid {
  position: fixed;
  inset: 0;
  z-index: 35;
  overflow-y: auto;
  padding: 40px 16px 64px;
  background: radial-gradient(ellipse at 50% 0%, rgba(20, 38, 78, 0.97), rgba(4, 7, 15, 0.98) 70%);
  animation: grid-in 0.4s ease;
}
#grid[hidden] { display: none; }
@keyframes grid-in { from { opacity: 0; } }

.grid-head { text-align: center; margin-bottom: 28px; }
.grid-head .eyebrow {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.42em;
  text-transform: uppercase;
  color: #9aabc6;
}
.grid-head h2 {
  margin: 6px 0 0;
  font-family: var(--display);
  font-size: clamp(26px, 3vw, 40px);
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: linear-gradient(100deg, #9db2c8, #ffffff 45%, #b4c7da);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.grid-inner { max-width: 1280px; margin: 0 auto; }
.grid-chapter + .grid-chapter { margin-top: 30px; }
.grid-chapter h3 {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 14px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--plat-bright);
}
.grid-chapter h3::before,
.grid-chapter h3::after { content: ""; height: 1px; background: linear-gradient(90deg, rgba(150, 205, 232, 0.6), transparent); }
.grid-chapter h3::before { width: 28px; background: linear-gradient(90deg, transparent, rgba(150, 205, 232, 0.6)); }
.grid-chapter h3::after { flex: 1; }

.grid-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
}
.thumb {
  position: relative;
  padding: 0;
  border: 1px solid rgba(150, 205, 232, 0.2);
  border-radius: 6px;
  overflow: hidden;
  background: #0b1224;
  cursor: pointer;
  aspect-ratio: 16 / 9;
  opacity: 0;
  animation: rise 0.55s cubic-bezier(0.2, 0.7, 0.1, 1) forwards;
  animation-delay: calc(var(--i) * 28ms);
  transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb span {
  position: absolute;
  left: 8px;
  bottom: 8px;
  padding: 1px 9px;
  border-radius: 999px;
  background: rgba(5, 9, 20, 0.78);
  border: 1px solid rgba(150, 205, 232, 0.35);
  font-family: var(--display);
  font-weight: 700;
  font-size: 12px;
  color: #cbe9fb;
}
.thumb:hover, .thumb:focus-visible {
  outline: none;
  transform: translateY(-3px);
  border-color: rgba(214, 238, 252, 0.8);
  box-shadow: 0 14px 34px -12px rgba(0, 0, 0, 0.8), 0 0 22px rgba(150, 205, 232, 0.25);
}
.thumb.current {
  border-color: var(--plat-bright);
  box-shadow: 0 0 0 1px var(--plat-bright), 0 0 28px rgba(190, 228, 248, 0.35);
}

@media (prefers-reduced-motion: reduce) {
  .thumb { animation: none; opacity: 1; }
  #grid { animation: none; }
}
