/* Terraria Tracker - hand-written CSS recreation of the in-game Bestiary UI,
   shared across every tracked tab (Bestiary, Achievements, ...). Real game
   fonts/textures aren't available to us, so this approximates the look with
   a self-hosted webfont + a dark-navy/gold palette + the real creature/filter
   icons scraped from terraria.wiki.gg. */

@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/Nunito-Variable.woff2') format('woff2');
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('../fonts/Nunito-Variable.woff2') format('woff2');
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('../fonts/Nunito-Variable.woff2') format('woff2');
}
@font-face {
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url('../fonts/Nunito-Variable.woff2') format('woff2');
}

:root {
  --font-ui: 'Nunito', 'Trebuchet MS', 'Segoe UI', sans-serif;

  --color-bg: #0b1120;
  --color-panel: #1a2540;
  --color-panel-alt: #232f52;
  --color-cell-bg: #26335a;
  --color-cell-hover: #303f6c;
  --color-border: #3c4f80;
  --color-border-light: #6478b0;
  --color-gold: #f2c96d;
  --color-gold-dim: #c7a256;
  --color-selected: #ffdd7a;
  --color-text: #e8ebf5;
  --color-text-dim: #93a0c4;
  --color-done: #4caf6f;
  --color-done-bg: #1c3a29;
  --color-not-done: #c96a6a;

  --radius: 4px;
  --gap: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #16213d 0%, var(--color-bg) 70%);
  color: var(--color-text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.4;
}

img {
  image-rendering: crisp-edges;
  image-rendering: pixelated;
}

button,
select,
input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.panel {
  background: var(--color-panel);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    inset 0 -2px 0 rgba(0, 0, 0, 0.35),
    0 2px 6px rgba(0, 0, 0, 0.4);
}

.app {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ---- Tab bar ---- */
.tab-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px;
}
.tab-bar-tabs {
  display: flex;
  gap: 4px;
}
.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 18px;
  cursor: pointer;
  font-weight: 700;
  color: var(--color-text-dim);
}
.tab-btn:hover {
  color: var(--color-text);
  border-color: var(--color-border);
}
.tab-btn.active {
  background: var(--color-panel-alt);
  border-color: var(--color-gold-dim);
  color: var(--color-gold);
}
.tab-panel[hidden] {
  display: none;
}
.tab-panel {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  padding: 10px 14px;
}

.icon-btn {
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-panel-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  cursor: pointer;
  transition: background 0.1s ease, border-color 0.1s ease;
}
.icon-btn:hover:not(:disabled) {
  background: var(--color-cell-hover);
  border-color: var(--color-border-light);
}
.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 6px;
}
.page-range {
  margin-left: 4px;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-dim);
  white-space: nowrap;
}

.progress-summary {
  display: flex;
  align-items: center;
  gap: 8px;
}
.progress-bar-track {
  width: 80px;
  height: 8px;
  background: var(--color-panel-alt);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--color-done);
  transition: width 0.2s ease;
}
.progress-summary-text {
  color: var(--color-text-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.sort-control select {
  background: var(--color-panel-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 6px 10px;
  cursor: pointer;
}
.sort-control select:hover {
  border-color: var(--color-border-light);
}

.filters-toggle-btn {
  background: var(--color-panel-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 7px 14px;
  cursor: pointer;
  font-weight: 600;
}
.filters-toggle-btn:hover,
.filters-toggle-btn[aria-expanded='true'] {
  border-color: var(--color-gold-dim);
  color: var(--color-gold);
}

.search-control {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--color-panel-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 5px 8px;
}
.search-control::before {
  content: '\1F50D';
  opacity: 0.6;
  font-size: 13px;
}
.search-label {
  color: var(--color-text-dim);
  white-space: nowrap;
}
.search-control input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--color-text);
  width: 150px;
}
.search-control .icon-btn {
  width: 22px;
  height: 22px;
  background: transparent;
  border: none;
}
.search-control .icon-btn:hover {
  color: var(--color-not-done);
  background: transparent;
}

/* ---- Filter bar ---- */
.filter-bar[hidden] {
  display: none;
}
.filter-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
}
.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.filter-group:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.filter-group-label {
  width: 100%;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-dim);
  margin-bottom: 2px;
}
.filter-icon-btn {
  width: 36px;
  height: 36px;
  padding: 5px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--color-cell-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  position: relative;
}
.filter-icon-btn img,
.filter-icon-btn svg {
  max-width: 100%;
  max-height: 100%;
}
.filter-icon-btn:hover {
  border-color: var(--color-border-light);
  background: var(--color-cell-hover);
}
.filter-icon-btn.active {
  border-color: var(--color-selected);
  background: rgba(242, 201, 109, 0.18);
  box-shadow: 0 0 6px rgba(242, 201, 109, 0.5);
}

/* ---- Main content ---- */
.content {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--gap);
  align-items: start;
}

.grid-panel {
  padding: 12px;
}

.bestiary-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  user-select: none; /* shift-click is a native text-selection gesture in most browsers; this is a click target, not text */
}

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--color-cell-bg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.08s ease, border-color 0.08s ease;
}
.cell:hover {
  background: var(--color-cell-hover);
  border-color: var(--color-border-light);
}
.cell.selected {
  border-color: var(--color-selected);
  box-shadow: 0 0 0 1px var(--color-selected), 0 0 8px rgba(255, 221, 122, 0.6);
}
.cell img {
  width: 78%;
  height: 78%;
  object-fit: contain;
}
.cell .cell-number {
  position: absolute;
  top: 2px;
  left: 3px;
  font-size: 10px;
  color: var(--color-text-dim);
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}
.cell .tick-badge {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: 1px solid var(--color-border-light);
  background: rgba(10, 14, 28, 0.65);
  color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.cell .tick-badge:hover {
  border-color: var(--color-gold);
}
.cell .tick-badge.done {
  background: var(--color-done);
  border-color: var(--color-done);
  color: #0b1120;
}
.cell .tick-badge.done::after {
  content: '\2713';
}

/* tooltip: native title attribute is used for the hover name label */

/* ---- Detail panel ---- */
.detail-panel {
  padding: 16px;
  min-height: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.detail-panel .empty-state {
  margin: auto;
  color: var(--color-text-dim);
  text-align: center;
  font-style: italic;
}
.detail-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--color-gold);
  margin: 0;
}
.detail-name a {
  color: inherit;
  text-decoration: none;
}
.detail-name a:hover,
.detail-name a:focus-visible {
  color: var(--color-selected);
  text-decoration: underline;
}
.star-row {
  display: flex;
  gap: 2px;
  font-size: 16px;
  letter-spacing: 1px;
}
.star-row .star.filled {
  color: var(--color-gold);
}
.star-row .star.empty {
  color: var(--color-border);
}
.detail-picture {
  background: var(--color-panel-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.detail-picture img {
  max-width: 65%;
  max-height: 85%;
}
.detail-description {
  color: var(--color-text);
  line-height: 1.55;
  font-size: 14px;
}
.achievement-quote {
  color: var(--color-text);
  line-height: 1.55;
  font-size: 14px;
  font-style: italic;
  margin: 0;
}
.achievement-notes {
  margin: 0;
  padding-left: 18px;
  color: var(--color-text-dim);
  font-size: 13px;
  line-height: 1.5;
}
.achievement-notes li {
  margin-bottom: 4px;
}
.detail-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  padding: 8px;
  background: var(--color-panel-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.stat {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}
.stat-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.stat-value {
  color: var(--color-text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.detail-subheading {
  margin: 0 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-dim);
}
.drops-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-panel-alt);
}
.drops-list li {
  padding: 4px 8px;
  font-size: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.drops-list li:last-child {
  border-bottom: none;
}
.drop-main {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
}
.drop-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}
.mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--color-text-dim);
  flex-shrink: 0;
  white-space: nowrap;
}
.mode-badge img {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}
.drop-name {
  color: var(--color-text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
a.drop-name {
  text-decoration: none;
}
a.drop-name:hover,
a.drop-name:focus-visible {
  color: var(--color-gold);
  text-decoration: underline;
}
.drop-qty {
  color: var(--color-text-dim);
  white-space: nowrap;
  flex-shrink: 0;
}
.drop-rate {
  color: var(--color-gold-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.filter-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--color-panel-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 3px 8px 3px 4px;
  font-size: 12px;
  color: var(--color-text-dim);
}
.filter-chip img,
.filter-chip svg {
  width: 18px;
  height: 18px;
}
.done-toggle {
  margin-top: auto;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-panel-alt);
  cursor: pointer;
  font-weight: 700;
  text-align: center;
}
.done-toggle:hover {
  border-color: var(--color-gold-dim);
}
.done-toggle.done {
  background: var(--color-done-bg);
  border-color: var(--color-done);
  color: #bdf2cf;
}

/* ---- Bulk selection (Ctrl/Shift-click multi-select) ---- */
.bulk-hint {
  font-size: 12px;
  color: var(--color-text-dim);
  line-height: 1.45;
  margin: 0;
}
.bulk-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bulk-actions .done-toggle {
  margin-top: 0;
}
.bulk-mark-done:hover {
  border-color: var(--color-done);
  color: #bdf2cf;
}
.bulk-mark-not-done:hover {
  border-color: var(--color-not-done);
  color: #ffd9d9;
}
.bulk-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-panel-alt);
}
.bulk-list li {
  padding: 5px 8px;
  font-size: 12px;
  color: var(--color-text-dim);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.bulk-list li:last-child {
  border-bottom: none;
}
.bulk-list li.done {
  color: var(--color-done);
}
.bulk-clear {
  margin-top: auto;
  align-self: flex-start;
}

/* ---- Footer ---- */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 6px 4px 0;
  color: var(--color-text-dim);
  font-size: 12px;
}
.text-btn {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text-dim);
  padding: 5px 10px;
  cursor: pointer;
}
.text-btn:hover {
  color: var(--color-not-done);
  border-color: var(--color-not-done);
}
.app-footer a {
  color: var(--color-text-dim);
}

/* ---- Sync modal ---- */
.modal-overlay[hidden] {
  display: none;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 18, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h2 {
  margin: 0;
  font-size: 17px;
  color: var(--color-gold);
}
.sync-summary {
  margin: 0;
  color: var(--color-text-dim);
  font-size: 13px;
}
.sync-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--color-border);
}
.sync-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.sync-hint {
  margin: 0;
  color: var(--color-text-dim);
  font-size: 12px;
}
.sync-code {
  flex: 1;
  background: var(--color-panel-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  padding: 6px 8px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.4;
  resize: vertical;
  word-break: break-all;
}
.sync-status {
  margin: 0;
  min-height: 16px;
  font-size: 13px;
}
.sync-status.success {
  color: var(--color-done);
}
.sync-status.error {
  color: var(--color-not-done);
}

@media (max-width: 860px) {
  .content {
    grid-template-columns: 1fr;
  }
  .search-control {
    margin-left: 0;
  }
  /* Covers the whole stacked-layout range (tablet through phone) so there's
     no gap width where the grid still shows 8 shrunken columns: each cell
     is guaranteed at least 84px regardless of viewport, with auto-fill
     picking however many of those fit (naturally fewer on a narrower
     phone), rather than a fixed column count that only looks right at one
     specific width. */
  .bestiary-grid {
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
  }
}

@media (max-width: 600px) {
  .app {
    padding: 8px;
    gap: 6px;
  }
  .tab-bar {
    padding: 4px;
  }
  .tab-btn {
    padding: 8px 12px;
  }
  .topbar {
    gap: 8px;
    padding: 8px 10px;
  }
  .search-control {
    flex-basis: 100%;
  }
  .search-control input {
    flex: 1;
    width: auto;
  }
  .grid-panel {
    padding: 8px;
  }
  .bestiary-grid {
    gap: 8px;
  }
  .cell .tick-badge {
    width: 20px;
    height: 20px;
  }
  .filter-bar {
    padding: 10px;
  }
  .filter-icon-btn {
    width: 42px;
    height: 42px;
  }
  .detail-panel {
    min-height: 0;
    padding: 12px;
  }
  .modal {
    padding: 12px;
  }
  .sync-row {
    flex-wrap: wrap;
  }
}
