/* ====== Global CRT Aesthetic ====== */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Lucida Console", monospace;
  background: #191B1A;
  color: #EDF6D6;
  overflow: hidden;
}

.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0.15) 0px,
    rgba(0, 0, 0, 0.15) 2px,
    rgba(255, 255, 255, 0.03) 2px,
    rgba(255, 255, 255, 0.03) 4px
  );
  mix-blend-mode: multiply;
  z-index: 999;
}

.crt-vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at center, transparent 45%, rgba(0,0,0,0.8) 100%);
  z-index: 998;
}

/* ====== Basic Panels ====== */

.crt-panel {
  border: 2px solid #579C9A;
  background: radial-gradient(circle at top left, #294257 0%, #191B1A 55%, #000000 100%);
  box-shadow:
    0 0 8px rgba(87,156,154,0.7),
    inset 0 0 6px rgba(0,0,0,0.8);
  position: relative;
  overflow: hidden;
}

.crt-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.08), transparent 60%);
  mix-blend-mode: screen;
  opacity: 0.25;
  pointer-events: none;
}

.animated-border {
  position: relative;
}

.animated-border::after {
  content: "";
  position: absolute;
  inset: -1px;
  border: 1px solid #99C9B3;
  opacity: 0.7;
  pointer-events: none;
  animation: borderGlow 2.4s infinite linear;
}

@keyframes borderGlow {
  0% { box-shadow: 0 0 2px #579C9A; opacity: 0.35; }
  50% { box-shadow: 0 0 10px #99C9B3; opacity: 0.9; }
  100% { box-shadow: 0 0 2px #579C9A; opacity: 0.35; }
}

#dex-app {
  position: relative;
  z-index: 1;
  padding: 10px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ====== Header / Tabs ====== */

#dex-header {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr) 260px;
  align-items: center;
  padding: 6px 10px;
  gap: 8px;
}

#dex-header h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 4px;
}

#dex-header p {
  margin: 0;
  font-size: 11px;
  opacity: 0.85;
}

.header-center {
  position: relative;
}

#dex-tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.dex-tab {
  position: relative;
  background: transparent;
  border: none;
  color: #EDF6D6;
  padding: 4px 12px;
  font-family: inherit;
  font-size: 11px;
  letter-spacing: 2px;
  cursor: pointer;
  text-transform: uppercase;
  opacity: 0.7;
}

.dex-tab::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -4px;
  height: 2px;
  background: linear-gradient(to right, transparent, #99C9B3, transparent);
  opacity: 0;
  transition: opacity 0.2s;
}

.dex-tab.active {
  opacity: 1;
  text-shadow: 0 0 6px #EDF6D6;
}

.dex-tab.active::before {
  opacity: 1;
}

.tab-underline {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -6px;
  height: 1px;
  background: linear-gradient(to right, transparent, #579C9A, #99C9B3, transparent);
}

.header-right {
  display: flex;
  gap: 16px;
  justify-content: flex-end;
  align-items: center;
  font-size: 11px;
}

.search-label {
  font-size: 11px;
}

#dex-search {
  margin-left: 4px;
  padding: 3px 6px;
  background: #191B1A;
  border: 1px solid #579C9A;
  color: #EDF6D6;
  font-family: inherit;
  font-size: 11px;
}

#dex-search:focus {
  outline: none;
  box-shadow: 0 0 4px #99C9B3;
}

#dex-count {
  font-size: 11px;
  opacity: 0.9;
}

/* ====== Tab Panels ====== */

#dex-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tab-panel {
  display: none;
  height: 100%;
}

.tab-panel.active {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 8px;
  min-height: 0;
}

#tab-lore,
#tab-chart,
#tab-logs {
  grid-template-columns: 1fr;
}

/* ====== ENTRIES TAB LAYOUT ====== */

#dex-list-panel {
  padding: 8px;
  display: flex;
  flex-direction: column;
}

.panel-title {
  font-size: 11px;
  letter-spacing: 2px;
  margin: 0 0 4px 0;
}

.panel-title.small {
  margin-top: 8px;
}

#dex-list {
  flex: 1;
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  overflow-y: auto;
  font-size: 11px;
}

#dex-list li {
  padding: 4px 6px;
  margin-bottom: 2px;
  border-left: 2px solid transparent;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

#dex-list li span.name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#dex-list li span.rarity-badge {
  font-size: 9px;
  opacity: 0.8;
}

#dex-list li:hover {
  background: rgba(87,156,154,0.25);
  border-left-color: #99C9B3;
}

#dex-list li.active {
  background: rgba(66,110,93,0.9);
  border-left-color: #EDF6D6;
  color: #EDF6D6;
}

#dex-hint {
  margin-top: 4px;
  font-size: 9px;
  opacity: 0.8;
}

#dex-entry-wrapper {
  position: relative;
  min-height: 0;
}

/* Navigation arrows */

.nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid #579C9A;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  cursor: pointer;
  font-size: 16px;
  user-select: none;
  transition: background 0.15s, box-shadow 0.15s;
}

#nav-left { left: 6px; }
#nav-right { right: 6px; }

.nav-arrow:hover {
  background: rgba(87,156,154,0.7);
  box-shadow: 0 0 8px #99C9B3;
}

/* Entry Panel */

#entry-panel {
  position: absolute;
  inset: 0;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.entry-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid rgba(153,201,179,0.4);
  padding-bottom: 4px;
  margin-bottom: 6px;
}

.entry-id-name {
  display: flex;
  gap: 8px;
  align-items: baseline;
}

.entry-id {
  font-size: 11px;
  padding: 2px 4px;
  border: 1px solid #579C9A;
  background: rgba(0,0,0,0.6);
}

.entry-name {
  font-size: 18px;
  letter-spacing: 2px;
}

.entry-title {
  font-size: 11px;
  opacity: 0.9;
}

.entry-header-right {
  text-align: right;
}

.entry-type {
  font-size: 11px;
  opacity: 0.9;
  margin-top: 2px;
}

.entry-species {
  font-size: 10px;
  opacity: 0.8;
  margin-top: 2px;
}

/* Rarity stars */

.rarity-stars {
  font-size: 14px;
  letter-spacing: 1px;
}

.rarity-stars .star {
  opacity: 0.25;
}

.rarity-stars .star.filled {
  opacity: 1;
  text-shadow: 0 0 6px #EDF6D6;
}

/* Entry body */

.entry-body {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 10px;
  flex: 1;
  min-height: 0;
}

.entry-left {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Sprite */

.sprite-frame {
  flex: 0 0 auto;
  border-radius: 2px;
  padding: 6px;
  background: radial-gradient(circle at center, #294257 0%, #000 85%);
}

.sprite-inner {
  border: 1px solid #426E5D;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
}

.sprite-inner img {
  image-rendering: pixelated;
  max-width: 128px;
  max-height: 128px;
}

/* Species accent (color hint per class could be added via JS if you want later) */
.species-accent {
  box-shadow: 0 0 8px rgba(153,201,179,0.6);
}

/* Alignment & Temperament */

.crt-subpanel {
  background: rgba(0,0,0,0.35);
  border-radius: 2px;
}

.alignment-section {
  font-size: 11px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.alignment-label {
  margin-bottom: 2px;
}

.alignment-meter,
.temperament-meter {
  display: flex;
  align-items: center;
  gap: 4px;
}

.alignment-end {
  font-size: 9px;
  opacity: 0.8;
  width: 50px;
  text-align: center;
}

.alignment-bar {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: linear-gradient(to right, #579C9A, #99C9B3, #579C9A);
  position: relative;
  overflow: hidden;
}

.alignment-bar.vertical {
  width: 8px;
  height: 40px;
  background: linear-gradient(to bottom, #579C9A, #99C9B3, #579C9A);
}

#alignment-marker {
  position: absolute;
  top: -2px;
  width: 2px;
  height: 12px;
  background: #EDF6D6;
  box-shadow: 0 0 6px #EDF6D6;
}

#temperament-marker {
  position: absolute;
  left: -2px;
  width: 12px;
  height: 2px;
  background: #EDF6D6;
  box-shadow: 0 0 6px #EDF6D6;
}

/* Right side */

.entry-right {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.lore-panel {
  padding: 6px;
  flex: 0 0 auto;
  max-height: 50%;
  overflow-y: auto;
  font-size: 12px;
}

.stats-tags-row {
  flex: 1;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
  min-height: 0;
}

.stats-panel,
.tags-panel {
  padding: 6px;
  font-size: 11px;
  overflow-y: auto;
}

/* Stats grid */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 10px;
}

.stat-item {
  display: flex;
  justify-content: space-between;
}

.stat-name {
  text-transform: uppercase;
  opacity: 0.85;
}

.stat-value {
  font-weight: bold;
}

/* Tags & behaviors */

.tags-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 4px;
}

.tag-chip {
  padding: 2px 5px;
  border-radius: 2px;
  border: 1px solid #579C9A;
  font-size: 10px;
  background: rgba(0,0,0,0.5);
}

.behaviors-list {
  list-style: square;
  padding-left: 16px;
  margin: 4px 0 0;
  font-size: 10px;
}

/* ====== LORE TAB ====== */

.lore-layout {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
}

.lore-section {
  background: rgba(0,0,0,0.35);
  padding: 8px;
  border-radius: 2px;
  font-size: 12px;
}

.lore-section h3 {
  margin: 4px 0;
  font-size: 11px;
}

.lore-list {
  margin: 4px 0 0;
  padding-left: 16px;
  font-size: 11px;
}

.lore-section.two-col {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
}

.rarity-label.common { color: #99C9B3; }
.rarity-label.uncommon { color: #579C9A; }
.rarity-label.rare { color: #EDF6D6; text-shadow: 0 0 4px #579C9A; }
.rarity-label.ultra { color: #EDF6D6; text-shadow: 0 0 6px #FF5C5C; }

/* ====== TEMPERAMENT CHART TAB ====== */

.chart-layout {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chart-header {
  font-size: 11px;
}

.chart-header p {
  margin: 2px 0 6px;
  opacity: 0.9;
}

.chart-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.chart-filters span {
  margin-right: 4px;
}

.chart-filter {
  background: rgba(0,0,0,0.6);
  border: 1px solid #579C9A;
  color: #EDF6D6;
  font-size: 10px;
  padding: 2px 6px;
  cursor: pointer;
}

.chart-filter.active {
  background: #426E5D;
  box-shadow: 0 0 6px #99C9B3;
}

.chart-grid-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  min-height: 0;
}

.chart-grid {
  position: relative;
  flex: 1;
  margin-left: 40px;
  margin-top: 20px;
  background:
    linear-gradient(to right, rgba(153,201,179,0.15) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(153,201,179,0.15) 1px, transparent 1px);
  background-size: 20px 20px;
  border: 1px solid #579C9A;
  overflow: hidden;
}

.chart-axis {
  position: absolute;
  color: #EDF6D6;
  font-size: 9px;
  opacity: 0.85;
  pointer-events: none;
}

.chart-axis-x {
  left: 40px;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  padding: 2px 4px;
}

.chart-axis-y {
  left: 0;
  top: 20px;
  bottom: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 2px 0 2px 2px;
}

/* Chart dots */

.chart-dot {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid #EDF6D6;
  background: #579C9A;
  box-shadow: 0 0 6px #99C9B3;
  cursor: pointer;
  transform: translate(-50%, -50%);
}

.chart-dot:hover {
  transform: translate(-50%, -50%) scale(1.2);
}

/* Legend */

.chart-legend {
  margin-top: 6px;
  font-size: 11px;
  opacity: 0.9;
}

/* ====== LOGS TAB ====== */

.logs-layout {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.logs-header p {
  margin: 2px 0 0;
  font-size: 11px;
  opacity: 0.9;
}

.logs-list {
  flex: 1;
  font-size: 11px;
  background: rgba(0,0,0,0.35);
  border-radius: 2px;
  padding: 6px;
  overflow-y: auto;
}

.log-entry {
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px dashed rgba(153,201,179,0.3);
}

.log-entry:last-child {
  border-bottom: none;
  margin-bottom: 0;
}

.log-meta {
  font-size: 9px;
  opacity: 0.7;
}

.log-message {
  white-space: pre-wrap;
}

/* ====== Transitions for Entry Panel ====== */

.transition-slide-out {
  animation: slideOut 0.25s forwards;
}
.transition-slide-in {
  animation: slideIn 0.25s forwards;
}

@keyframes slideOut {
  from { transform: translateX(0); opacity: 1; }
  to   { transform: translateX(-30px); opacity: 0; }
}
@keyframes slideIn {
  from { transform: translateX(30px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* Fade */

.transition-fade-out {
  animation: fadeOut 0.18s forwards;
}
.transition-fade-in {
  animation: fadeIn 0.18s forwards;
}

@keyframes fadeOut {
  from { opacity: 1; filter: none; }
  to   { opacity: 0; filter: brightness(0); }
}

@keyframes fadeIn {
  from { opacity: 0; filter: brightness(0); }
  to   { opacity: 1; filter: none; }
}

/* CRT collapse */

.transition-crt-out {
  animation: crtOut 0.2s forwards;
}
.transition-crt-in {
  animation: crtIn 0.2s forwards;
}

@keyframes crtOut {
  0% { transform: scaleY(1); opacity: 1; }
  100% { transform: scaleY(0.05); opacity: 0; filter: blur(1px); }
}

@keyframes crtIn {
  0% { transform: scaleY(0.05); opacity: 0; filter: blur(1px); }
  100% { transform: scaleY(1); opacity: 1; }
}

/* Static flash overlay */

.transition-static-out,
.transition-static-in {
  background-image:
    repeating-linear-gradient(0deg, #EDF6D6 0px, #EDF6D6 1px, #191B1A 1px, #191B1A 2px);
  mix-blend-mode: screen;
}

.transition-static-out {
  animation: staticOut 0.16s forwards;
}
.transition-static-in {
  animation: staticIn 0.16s forwards;
}

@keyframes staticOut {
  from { opacity: 0; }
  50% { opacity: 0.6; }
  to { opacity: 0; }
}
@keyframes staticIn {
  from { opacity: 0; }
  50% { opacity: 0.6; }
  to { opacity: 0; }
}

/* ====== New Drivel Popup ====== */

#new-drivel-popup {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

#new-drivel-popup.hidden {
  display: none;
}

.popup-inner {
  min-width: 260px;
  max-width: 380px;
  padding: 10px;
  text-align: center;
  animation: popupIn 0.4s ease-out;
}

@keyframes popupIn {
  0% { transform: scale(0.8); opacity: 0; }
  60% { transform: scale(1.05); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

.popup-title {
  font-size: 14px;
  letter-spacing: 2px;
  margin-bottom: 6px;
}

#new-drivel-list {
  list-style: none;
  padding: 0;
  margin: 0 0 8px 0;
  font-size: 11px;
}

#new-drivel-list li {
  padding: 2px 0;
}

#popup-close {
  padding: 4px 10px;
  background: #191B1A;
  border: 1px solid #579C9A;
  color: #EDF6D6;
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
}

#popup-close:hover {
  box-shadow: 0 0 6px #99C9B3;
}

/* ====== Scrollbars ====== */

::-webkit-scrollbar {
  width: 6px;
}
::-webkit-scrollbar-track {
  background: #191B1A;
}
::-webkit-scrollbar-thumb {
  background: #426E5D;
}
::-webkit-scrollbar-thumb:hover {
  background: #579C9A;
}

/* ====== Responsive ====== */

@media (max-width: 880px) {
  .tab-panel.active {
    grid-template-columns: 1fr;
  }
  #dex-list-panel {
    order: 2;
    height: 32vh;
  }
  #dex-entry-wrapper {
    order: 1;
    height: 55vh;
  }
  .entry-body {
    grid-template-columns: 1fr;
  }
}
