/* ── BASE & LAYOUT ──────────────────────────────────────────────── */
.tb-body {
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.tb-pg-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
}
.tb-page {
  max-width: min(1520px, 100%);
  margin: 0 auto;
  padding: 1rem 1.25rem 1.25rem;
  width: 100%;
  box-sizing: border-box;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
}

/* ── HEADER ─────────────────────────────────────────────────────── */
.tb-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 0.65rem;
}
.tb-title {
  font-family: var(--font-display);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: clamp(1.15rem, 2.5vw, 1.65rem);
  font-weight: 900;
  letter-spacing: 0.05em;
  margin: 0 0 0.15rem 0;
  text-shadow: 0 0 16px rgba(255, 255, 255, 0.15);
}
.tb-subtitle {
  font-family: var(--font-sans);
  font-size: 0.82rem;
  line-height: 1.38;
  max-width: 48rem;
  color: var(--muted);
  margin: 0.2rem 0 0 0;
}
.tb-pods-section .tb-subtitle {
  max-width: 100%;
}

/* ── MAIN LAYOUT ────────────────────────────────────────────────── */
.tb-layout {
  display: grid;
  grid-template-columns: minmax(200px, 268px) minmax(0, 1fr);
  gap: 1rem;
  flex: 1;
  min-height: 0;
  align-items: start;
}
@media (max-width: 1024px) {
  .tb-layout {
    grid-template-columns: 1fr;
    min-width: 0;
  }
  .tb-layout > * {
    min-width: 0;
    max-width: 100%;
  }
  .tb-page {
    padding: 0.75rem max(0.65rem, env(safe-area-inset-left, 0px)) 1rem
      max(0.65rem, env(safe-area-inset-right, 0px));
  }
}

/* ── LEFT PANEL: SEARCH & PODS ──────────────────────────────────── */
.tb-pods-section {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Search */
.tb-search-wrap {
  position: relative;
  width: 100%;
}
.tb-search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}
.tb-search {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 0.55rem 0.75rem 0.55rem 2.35rem;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.92rem;
  transition: all 0.2s ease;
}
.tb-search:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 15px rgba(100, 200, 255, 0.2);
}
.tb-search-results {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  width: 100%;
  background: rgba(10, 15, 30, 0.95);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.tb-search-results.active {
  display: block;
}
.tb-search-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  transition: background 0.2s ease;
}
.tb-search-item:hover {
  background: rgba(255, 255, 255, 0.1);
}
.tb-search-item-visual {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.tb-search-item-visual img {
  width: 44px;
  height: 44px;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
}
.tb-search-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  min-width: 0;
}
.tb-search-item-name {
  font-family: var(--font-display);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.2;
}
.tb-search-item-form {
  font-family: var(--font-sans);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.92;
}
.tb-search-item-types {
  font-size: 0.75rem;
  color: var(--muted);
}

/* Pods Grid — fixed cell size so the block stays compact on typical laptop heights */
.tb-pods-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 108px));
  gap: 0.45rem;
  justify-content: center;
  width: 100%;
}
.tb-pod {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  aspect-ratio: 1;
  width: 100%;
  max-width: 108px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  transition: all 0.3s ease;
  overflow: hidden;
}
.tb-pod.empty {
  border-style: dashed;
  background: transparent;
}
.tb-pod.empty::after {
  content: '+';
  font-size: 1.35rem;
  color: rgba(255, 255, 255, 0.22);
  font-family: var(--font-display);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.tb-pod.filled {
  /* Sprite flexes in upper region; name + ability stack at bottom */
  justify-content: flex-start;
  padding: 4px 3px 3px;
  box-sizing: border-box;
  min-height: 0;
  background: rgba(20, 30, 50, 0.6);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.5);
}
.tb-pod.filled:hover {
  border-color: var(--accent);
  box-shadow: 0 0 15px rgba(100, 200, 255, 0.2), inset 0 0 20px rgba(0, 0, 0, 0.5);
}
.tb-pod.filled .tb-pod-img {
  flex: 1 1 0;
  min-height: 0;
  width: 84%;
  max-width: 96%;
  height: 100%;
  max-height: 100%;
  margin: 0;
  object-fit: contain;
  object-position: center center;
  align-self: center;
  filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.45));
  z-index: 2;
}
.tb-pod-name {
  font-family: var(--font-display);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.58rem;
  font-weight: 700;
  margin-top: 0;
  flex-shrink: 0;
  width: 100%;
  padding: 2px 2px 0;
  line-height: 1.15;
  text-align: center;
  z-index: 2;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.tb-pod-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 50, 50, 0.2);
  color: #ff5555;
  border: 1px solid rgba(255, 50, 50, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s ease;
  z-index: 10;
}
.tb-pod:hover .tb-pod-remove {
  opacity: 1;
}
.tb-pod-remove:hover {
  background: rgba(255, 50, 50, 0.8);
  color: white;
}
.tb-pod-ability {
  position: relative;
  margin-top: 0.1rem;
  width: 100%;
  text-align: center;
  font-size: 0.5rem;
  color: var(--accent);
  z-index: 2;
  background: rgba(0, 0, 0, 0.55);
  padding: 2px 3px 3px;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
  box-sizing: border-box;
  border-radius: 0 0 6px 6px;
}
.tb-pod-bg-glow {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(255,255,255,0.1) 0%, transparent 70%);
  z-index: 1;
}

/* While slide-to-clear runs: originals in pods fade (flying clones are separate layer) */
.tb-pods-section.is-clearing .tb-pod.filled .tb-pod-img,
.tb-pods-section.is-clearing .tb-pod.filled .tb-pod-name,
.tb-pods-section.is-clearing .tb-pod.filled .tb-pod-ability,
.tb-pods-section.is-clearing .tb-pod.filled .tb-pod-bg-glow {
  opacity: 0;
  transition: opacity 0.52s ease-out;
  pointer-events: none;
}
.tb-pods-section.is-clearing .tb-pod.filled .tb-pod-remove {
  opacity: 0 !important;
  pointer-events: none;
  transition: opacity 0.25s ease-out;
}

/* Slide-to-clear */
.tb-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.tb-slide-clear-wrap {
  margin-top: 0.25rem;
  user-select: none;
  -webkit-user-select: none;
}
.tb-slide-clear-wrap.is-disabled {
  opacity: 0.38;
  pointer-events: none;
}
.tb-slide-clear-wrap.is-busy {
  pointer-events: none;
  opacity: 0.85;
}
.tb-slide-clear-track {
  position: relative;
  height: 38px;
  border-radius: 19px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 100, 100, 0.25);
  box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  touch-action: none;
}
.tb-slide-clear-label {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  text-align: center;
  font-family: var(--font-display);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: rgba(255, 180, 180, 0.85);
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.08s linear;
}
.tb-slide-clear-progress {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  max-width: 100%;
  background: linear-gradient(90deg, rgba(255, 80, 80, 0.15), rgba(255, 120, 80, 0.22));
  border-radius: 19px 0 0 19px;
  z-index: 0;
  pointer-events: none;
  transition: width 0.06s linear;
}
.tb-slide-clear-thumb {
  position: absolute;
  left: 3px;
  top: 50%;
  margin-top: -17px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid rgba(255, 120, 120, 0.7);
  background: linear-gradient(145deg, #3a2528, #1a1218);
  box-shadow:
    0 0 14px rgba(255, 80, 80, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.12);
  cursor: grab;
  z-index: 3;
  padding: 0;
  transform: translateX(0);
  will-change: transform;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tb-slide-clear-thumb:active {
  cursor: grabbing;
}
.tb-slide-clear-thumb-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(255, 160, 160, 0.75);
  pointer-events: none;
  transition: color 0.2s ease, filter 0.2s ease;
}
.tb-slide-clear-thumb.is-hot .tb-slide-clear-thumb-icon {
  color: #ff8a8a;
  filter: drop-shadow(0 0 6px rgba(255, 100, 100, 0.85));
}
.tb-slide-clear-thumb.is-hot {
  border-color: rgba(255, 140, 140, 0.95);
  box-shadow:
    0 0 18px rgba(255, 90, 90, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.14);
}

/* Flying sprites → trash */
.tb-fly-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10050;
  overflow: visible;
}
.tb-fly-sprite {
  position: fixed;
  pointer-events: none;
  z-index: 10051;
  border-radius: 8px;
  overflow: hidden;
  will-change: transform, opacity;
}
.tb-fly-sprite img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.5));
}

/* ── RIGHT COLUMN: radar card + trainer notes card (separate) ───── */
.tb-right-column {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
  width: 100%;
  align-self: stretch;
}

/* Radar panel — square uses full column width; old min(...,780px) capped below column and kept radar small */
.tb-radar-panel {
  position: relative;
  overflow: hidden;
  background: rgba(10, 15, 25, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 0.5rem 0.65rem 0.75rem;
  box-sizing: border-box;
  min-height: 0;
}
.tb-radar-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px) 0 0 / 40px 40px,
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px) 0 0 / 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* Narrow: no card frame around radar — full bleed + largest square that fits viewport */
@media (max-width: 1024px) {
  .tb-right-column {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    gap: 0.55rem;
    overflow-x: visible;
  }
  /* Undo page inset; strip panel chrome (grid, border, padding) so chart isn’t boxed in */
  .tb-radar-panel {
    --tb-mob-pad-l: max(0.65rem, env(safe-area-inset-left, 0px));
    --tb-mob-pad-r: max(0.65rem, env(safe-area-inset-right, 0px));
    margin-left: calc(-1 * var(--tb-mob-pad-l));
    margin-right: calc(-1 * var(--tb-mob-pad-r));
    width: min(100vw, calc(100% + var(--tb-mob-pad-l) + var(--tb-mob-pad-r)));
    min-width: 0;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
    box-sizing: border-box;
  }
  .tb-radar-panel::before {
    content: none;
    display: none;
  }
  .tb-radar-container {
    width: min(
      calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)),
      99vh
    );
    max-width: 100%;
  }
  @supports (height: 1dvh) {
    .tb-radar-container {
      width: min(
        calc(100vw - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)),
        99dvh
      );
    }
  }
  .tb-terminal {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    height: auto;
    max-height: clamp(104px, 28vh, 200px);
    align-self: stretch;
    box-sizing: border-box;
  }
  .tb-terminal-body {
    overflow-x: hidden;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}

/* Radar — side = min(column width, viewport height) so it grows with the layout (no low px ceiling) */
.tb-radar-container {
  position: relative;
  width: min(100%, 96vh);
  height: auto;
  aspect-ratio: 1;
  max-width: 100%;
  margin-inline: auto;
  flex-shrink: 0;
  z-index: 1;
  overflow: hidden;
  box-sizing: border-box;
}

/* Trainer notes — separate card; natural height, scroll inside */
.tb-terminal {
  background: rgba(5, 10, 15, 0.8);
  border: 1px solid rgba(100, 200, 255, 0.3);
  border-radius: 8px;
  overflow: hidden;
  z-index: 1;
  box-shadow: 0 0 14px rgba(0, 0, 0, 0.45);
  min-height: 0;
  width: 100%;
  max-height: clamp(140px, 32vh, 260px);
  height: auto;
  display: flex;
  flex-direction: column;
  align-self: stretch;
}
.tb-terminal-header {
  background: rgba(100, 200, 255, 0.1);
  padding: 0.35rem 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border-bottom: 1px solid rgba(100, 200, 255, 0.2);
  flex-shrink: 0;
}
.tb-terminal-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #00ffcc;
  box-shadow: 0 0 8px #00ffcc;
  animation: blink 2s infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
.tb-terminal-title {
  font-family: var(--font-display);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: #00ffcc;
}
.tb-terminal-body {
  padding: 0.55rem 0.7rem;
  font-family: 'Courier New', Courier, monospace;
  font-size: 0.78rem;
  line-height: 1.42;
  color: #aaddff;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overflow-wrap: break-word;
  flex: 1;
}
.tb-terminal-line {
  margin-bottom: 0.35rem;
}
.tb-terminal-line.alert-critical {
  color: #ff4444;
  text-shadow: 0 0 5px rgba(255, 68, 68, 0.5);
}
.tb-terminal-line.alert-warning {
  color: #ffaa00;
}
.tb-terminal-line.alert-optimal {
  color: #00ffcc;
  text-shadow: 0 0 5px rgba(0, 255, 204, 0.5);
}
.tb-terminal-line.alert-strength {
  color: #5cff9d;
  text-shadow: 0 0 6px rgba(92, 255, 157, 0.35);
}
.tb-terminal-line.alert-synergy {
  color: #00e676;
  text-shadow: 0 0 5px rgba(0, 230, 118, 0.4);
}
.tb-terminal-line.alert-note {
  color: #7ecbff;
}
.tb-terminal-line.alert-advice {
  color: #ffb74d;
}
.tb-terminal-line.alert-standby {
  color: rgba(170, 221, 255, 0.75);
}

/* Tên hệ trong terminal (tiếng Việt + màu chuẩn Pokémon) */
.tb-type-tag {
  display: inline;
  font-weight: 800;
  padding: 0 0.12em;
  border-radius: 3px;
  text-shadow: 0 0 10px color-mix(in srgb, currentColor 45%, transparent);
}
.tb-type-normal   { color: #a8a878; }
.tb-type-fighting { color: #c03028; }
.tb-type-flying   { color: #a890f0; }
.tb-type-poison   { color: #a040a0; }
.tb-type-ground   { color: #e0c068; }
.tb-type-rock     { color: #b8a038; }
.tb-type-bug      { color: #a8b820; }
.tb-type-ghost    { color: #705898; }
.tb-type-steel    { color: #b8b8d0; }
.tb-type-fire     { color: #f08030; }
.tb-type-water    { color: #6890f0; }
.tb-type-grass    { color: #78c850; }
.tb-type-electric { color: #f8d030; }
.tb-type-psychic  { color: #f85888; }
.tb-type-ice      { color: #98d8d8; }
.tb-type-dragon   { color: #7038f8; }
.tb-type-dark     { color: #705848; }
.tb-type-fairy    { color: #ee99ac; }
