:root {
  --bg: #050805;
  --panel: #0b120c;
  --panel2: #0f1810;
  --line: #2f8f4a;
  --text: #d6f2d8;
  --muted: #8baa8f;
  --accent: #6bff89;
  --gold: #95d39f;
  --danger: #ff7575;
  --detail-fr: 62fr;
  --cards-fr: 38fr;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at 20% 10%, #102114 0%, var(--bg) 45%),
              radial-gradient(circle at 80% 90%, #132718 0%, var(--bg) 42%),
              var(--bg);
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  position: relative;
  overflow-x: hidden;
}

.scanlines {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.02) 0,
    rgba(255,255,255,0.02) 1px,
    rgba(0,0,0,0) 3px,
    rgba(0,0,0,0) 5px
  );
  opacity: 0.23;
}

.bg-orb {
  position: fixed;
  width: 340px;
  height: 340px;
  border-radius: 50%;
  filter: blur(80px);
  z-index: -1;
}

.orb-a { top: -70px; left: -80px; background: #197038; }
.orb-b { bottom: -70px; right: -80px; background: #2e8f4a; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  padding: 18px 20px 12px;
}

.dragon-badge {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid #2f6a3e;
  object-fit: cover;
  opacity: 0.9;
}

h1, h2 {
  font-family: "Copperplate", "Palatino Linotype", serif;
  letter-spacing: 0.04em;
  margin: 0;
}

h1 { font-size: 1.9rem; color: var(--accent); }
h2 { font-size: 1.2rem; color: var(--gold); }

.subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.md-link {
  color: var(--line);
  text-decoration: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: rgba(12, 24, 13, 0.85);
}

.controls {
  margin: 0 16px;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  border: 1px solid #225330;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(13, 25, 15, 0.92), rgba(9, 16, 10, 0.98));
}

label {
  font-size: 0.73rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

select, input, .btn {
  background: #090f0a;
  color: var(--text);
  border: 1px solid #2b6b3c;
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 0.84rem;
  width: 100%;
  min-width: 0;
}

.music-panel {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(130px, 190px) minmax(120px, 180px);
  gap: 8px;
  align-items: end;
  justify-content: end;
}

.volume-wrap {
  transition: opacity 140ms ease, transform 140ms ease;
}

.volume-wrap.hidden {
  opacity: 0;
  transform: translateY(-2px);
  pointer-events: none;
}

.btn {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  width: auto;
  padding: 6px 10px;
  background: #0b120c;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn.subtle {
  color: #9ac6a4;
  border-color: #255234;
  background: #0a100b;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.layout {
  padding: 14px 16px 18px;
  display: grid;
  grid-template-columns: minmax(320px, var(--detail-fr)) 10px minmax(220px, var(--cards-fr));
  grid-template-areas: "detail resizer cards";
  gap: 14px;
}

.cards-panel, .detail-panel {
  border: 1px solid #1f5e34;
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(12, 22, 14, 0.96), rgba(9, 14, 10, 0.98));
  min-height: 65vh;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px 8px;
}

.count { color: var(--muted); font-size: 0.85rem; }

.card-grid {
  padding: 8px 12px 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 10px;
  max-height: 74vh;
  overflow: auto;
}

.card-item {
  border: 1px solid #2a6d3b;
  border-radius: 10px;
  padding: 8px;
  background: linear-gradient(180deg, #0e1a10, #090f09);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
}

.card-item:hover { transform: translateY(-2px); border-color: #74e98a; }
.card-item.active { border-color: var(--accent); box-shadow: 0 0 0 1px #74ff93 inset; }

.thumb {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #2d5b38;
  animation: thumbPulse 6s ease-in-out infinite;
}

.card-name { margin-top: 6px; font-size: 0.88rem; color: var(--text); }
.card-type { font-size: 0.76rem; color: var(--gold); text-transform: uppercase; letter-spacing: 0.08em; }

.detail-panel {
  grid-area: detail;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cards-panel {
  grid-area: cards;
}

.panel-resizer {
  grid-area: resizer;
  width: 10px;
  border-radius: 8px;
  background: linear-gradient(180deg, #16351f, #1f5e34, #16351f);
  border: 1px solid #2d6f42;
  cursor: col-resize;
  align-self: stretch;
  min-height: 65vh;
}

.meta { margin: 0; color: var(--muted); min-height: 1.2rem; }
.meta-link {
  color: #aef5ba;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.meta-link:hover {
  color: #d6ffe0;
}

.meta-text {
  color: #9db9a3;
}

.meta-sep {
  color: #7ea788;
}

.meta-chip {
  appearance: none;
  border: 1px solid #2b6b3c;
  border-radius: 999px;
  background: #0a120c;
  color: #a9d5b3;
  font-size: 0.74rem;
  line-height: 1.2;
  padding: 2px 8px;
  cursor: pointer;
}

.meta-chip:hover {
  border-color: #6bff89;
  color: #d7ffe1;
}

#detailImage {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #2f673f;
  background: #070c08;
  max-height: none;
  aspect-ratio: 3 / 4;
  object-fit: contain;
  animation: cardFloat 5s ease-in-out infinite;
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.card-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.card-pos {
  color: #96b79d;
  font-size: 0.8rem;
  min-width: 62px;
  text-align: center;
}

.detail-actions .btn {
  font-size: 0.78rem;
  padding: 5px 9px;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.stat-pill {
  appearance: none;
  padding: 5px 8px;
  border: 1px solid #2f6a3e;
  border-radius: 999px;
  font-family: Menlo, Monaco, "Courier New", monospace;
  font-size: 0.8rem;
  color: var(--gold);
  background: #0a120c;
  cursor: pointer;
}

.stat-pill:hover {
  border-color: #6bff89;
  color: #c6ffd2;
}

.stat-pill.active {
  border-color: #6bff89;
  box-shadow: 0 0 0 1px rgba(107, 255, 137, 0.35) inset;
  color: #d8ffe0;
}

.stat-help {
  border: 1px solid #2b6b3c;
  border-radius: 10px;
  background: #0a120c;
  color: #b5cfba;
  font-size: 0.84rem;
  line-height: 1.4;
  padding: 8px 10px;
}

.desc { margin: 0; color: #b8d2bd; line-height: 1.4; }

.about {
  margin: 0 16px 16px;
  padding: 12px;
  border: 1px solid #1f5e34;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(10, 16, 10, 0.98), rgba(8, 12, 8, 1));
}

.about p {
  margin: 8px 0;
  color: #a8c5ad;
  font-size: 0.9rem;
  line-height: 1.45;
}

.about-links {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.about a {
  color: #8ce6a1;
  text-decoration: none;
  border-bottom: 1px dotted #5fbf72;
}

.about .copyright {
  color: #84a88b;
  font-size: 0.8rem;
}

@keyframes cardFloat {
  0% { transform: translateY(0) scale(1); filter: drop-shadow(0 0 0 rgba(110, 255, 137, 0)); }
  50% { transform: translateY(-4px) scale(1.005); filter: drop-shadow(0 8px 10px rgba(110, 255, 137, 0.08)); }
  100% { transform: translateY(0) scale(1); filter: drop-shadow(0 0 0 rgba(110, 255, 137, 0)); }
}

@keyframes thumbPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.012); }
  100% { transform: scale(1); }
}

@media (max-width: 980px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .music-panel { grid-template-columns: 1fr; justify-content: stretch; }
  .layout { grid-template-columns: 1fr; grid-template-areas: "detail" "cards"; }
  .panel-resizer { display: none; }
  .card-grid { max-height: 40vh; }
  #detailImage { max-height: 56vh; }
}

@media (max-width: 640px) {
  .controls { grid-template-columns: 1fr; }
}

@media (orientation: portrait) {
  .layout {
    grid-template-columns: 1fr;
    grid-template-areas: "detail" "cards";
  }
  .panel-resizer { display: none; }
  .card-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    max-height: 33vh;
  }
  #detailImage {
    max-height: 60vh;
  }
}
