@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Patrick+Hand&display=swap');

/* ── Theme variables ─────────────────────────── */

:root {
  --tooltip-font: 'Patrick Hand', cursive;
  --bg: #1a1a2e;
  --bg-secondary: #16213e;
  --text: #e0e0e0;
  --text-heading: #fff;
  --text-muted: #888;
  --text-subtle: #666;
  --border: #333;
  --accent: #96FF96;
  --search-bg: #16213e;
  --search-text: #fff;
  --search-border: #333;
  --search-focus-shadow: rgba(150, 255, 150, 0.2);
  --hover-bg: rgba(255, 255, 255, 0.05);
  --badge-bg: #16213e;
  --badge-text: #888;
  --stat-bg: #16213e;
  --stat-text: #ccc;
  --tooltip-text: #aaa;
  --crafting-bg: #0f3460;
  --crafting-text: #96FF96;
  --tree-border: #333;
  --drops-bg: #3d1f0a;
  --drops-text: #ffb070;
  --toggle-color: #888;
  --toggle-hover: #fff;
  --error-color: #FF6B6B;
  --scrollbar-track: #1a1a2e;
  --scrollbar-thumb: #333;
  --scrollbar-thumb-hover: #555;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #fff;
    --bg-secondary: #f1f3f4;
    --text: #202124;
    --text-heading: #202124;
    --text-muted: #5f6368;
    --text-subtle: #9aa0a6;
    --border: #dfe1e5;
    --accent: #1a73e8;
    --search-bg: #fff;
    --search-text: #202124;
    --search-border: #dfe1e5;
    --search-focus-shadow: rgba(26, 115, 232, 0.2);
    --hover-bg: rgba(0, 0, 0, 0.04);
    --badge-bg: #f1f3f4;
    --badge-text: #5f6368;
    --stat-bg: #f1f3f4;
    --stat-text: #5f6368;
    --tooltip-text: #5f6368;
    --crafting-bg: #e8f0fe;
    --crafting-text: #1a73e8;
    --tree-border: #dadce0;
    --drops-bg: #fef7e0;
    --drops-text: #b06000;
    --toggle-color: #5f6368;
    --toggle-hover: #202124;
    --error-color: #d93025;
    --scrollbar-track: #f1f3f4;
    --scrollbar-thumb: #dadce0;
    --scrollbar-thumb-hover: #bdc1c6;
  }
}

/* ── Reset ────────────────────────────────────── */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Google-style centered layout ─────────────── */

.container {
  max-width: 580px;
  margin: 0 auto;
  padding: 28vh 20px 20px;
  transition: padding-top 0.4s ease;
}

body.has-results .container {
  padding-top: 30px;
}

/* ── Hero (logo + subtitle) ──────────────────── */

.hero {
  text-align: center;
  margin-bottom: 28px;
  transition: margin-bottom 0.3s ease;
}

body.has-results .hero {
  margin-bottom: 16px;
}

.logo {
  display: block;
  margin: 0 auto 12px;
  image-rendering: pixelated;
}

body.has-results .logo {
  height: 70px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  max-height: 2em;
  overflow: hidden;
  transition: opacity 0.3s ease, max-height 0.3s ease, margin 0.3s ease;
}

body.has-results .subtitle {
  opacity: 0;
  max-height: 0;
  margin: 0;
}

/* ── Search (Google-style pill) ──────────────── */

.search-wrapper {
  position: relative;
  margin-bottom: 16px;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 14px 80px 14px 46px;
  font-size: 1rem;
  border: 1px solid var(--search-border);
  border-radius: 24px;
  background: var(--search-bg);
  color: var(--search-text);
  outline: none;
  transition: box-shadow 0.2s, border-color 0.2s;
}

#search:hover {
  box-shadow: 0 1px 6px 0 rgba(0, 0, 0, 0.2);
}

#search:focus {
  box-shadow: 0 1px 6px 0 var(--search-focus-shadow);
  border-color: var(--accent);
}

#search::placeholder {
  color: var(--text-subtle);
}

#search-status {
  position: absolute;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ── Item list ────────────────────────────────── */

#item-list {
  list-style: none;
}

#item-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

#item-list li:hover {
  background: var(--hover-bg);
}

.item-icon-small {
  width: 32px;
  height: 32px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

#item-list .item-name {
  flex: 1;
  font-weight: 500;
}

.item-type-badge {
  font-size: 0.7rem;
  color: var(--badge-text);
  background: var(--badge-bg);
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: capitalize;
}

/* ── Item view ────────────────────────────────── */

.item-view {
  padding-top: 30px;
  max-width: 800px;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.back-link:hover {
  opacity: 0.8;
  text-decoration: underline;
}

/* ── Item header ─────────────────────────────── */

.item-header {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 20px;
}

.item-icon-large {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-radius: 8px;
  padding: 6px;
}

.item-header-info h2 {
  font-size: 1.4rem;
  margin-bottom: 4px;
}

.wiki-link {
  font-size: 0.75rem;
  text-decoration: none;
  vertical-align: middle;
  opacity: 0.6;
  transition: opacity 0.15s;
}

.wiki-link:hover {
  opacity: 1;
}

.item-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 6px;
  font-size: 0.8rem;
}

.type-label {
  color: var(--tooltip-text);
  text-transform: capitalize;
}

.hardmode-badge {
  background: #FF2864;
  color: #fff;
  padding: 1px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
}

.tooltip-text {
  color: var(--tooltip-text);
  font-style: italic;
  font-size: 0.85rem;
  margin-bottom: 6px;
  white-space: pre-line;
}

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

.stat {
  font-size: 0.8rem;
  color: var(--stat-text);
  background: var(--stat-bg);
  padding: 3px 10px;
  border-radius: 6px;
}

/* ── Crafting tree ────────────────────────────── */

.loading, .no-recipe, .error {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.error {
  color: var(--error-color);
}

.recipe-block {
  margin-bottom: 20px;
}

.crafting-station {
  background: var(--crafting-bg);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--crafting-text);
}

.tree-root {
  padding-left: 4px;
}

.tree-node {
  position: relative;
  margin-left: 20px;
  border-left: 2px solid var(--tree-border);
  padding-left: 14px;
  margin-bottom: 2px;
}

.tree-node::before {
  content: '';
  position: absolute;
  left: -2px;
  top: 16px;
  width: 12px;
  height: 0;
  border-top: 2px solid var(--tree-border);
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  transition: background 0.15s;
  flex-wrap: nowrap;
}

.tree-item:hover {
  background: var(--hover-bg);
}

.tree-icon {
  width: 24px;
  height: 24px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.quantity {
  font-weight: 700;
  color: #FFD700;
  font-size: 0.85rem;
  min-width: 30px;
}

@media (prefers-color-scheme: light) {
  .quantity {
    color: #B8860B;
  }
}

.tree-item .item-name {
  font-weight: 500;
  font-size: 0.9rem;
}

.tree-item .item-name:hover {
  text-decoration: underline;
}

.toggle {
  cursor: pointer;
  font-size: 0.65rem;
  color: var(--toggle-color);
  user-select: none;
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}

.toggle:hover {
  color: var(--toggle-hover);
}

.leaf-icon {
  font-size: 0.55rem;
  flex-shrink: 0;
  width: 16px;
  text-align: center;
}

.tree-station {
  font-size: 0.65rem;
  color: var(--crafting-text);
  opacity: 0.7;
  margin-left: 4px;
}

.tree-children {
  transition: max-height 0.2s ease;
}

.tree-children.collapsed {
  display: none;
}

/* ── Drop sources ────────────────────────────── */

.drops-section {
  margin-top: 8px;
}

.drops-title {
  background: var(--drops-bg);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--drops-text);
}

.drop-entry {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 6px;
  margin-bottom: 4px;
  flex-wrap: wrap;
  transition: background 0.15s;
}

.drop-entry:hover {
  background: var(--hover-bg);
}

.drop-source-name {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--drops-text);
}

.drop-details {
  font-size: 0.8rem;
  color: var(--tooltip-text);
}

.drop-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  color: #fff;
}

.drop-badge.expert {
  background: #d47b00;
}

.drop-badge.master {
  background: #c0392b;
}

/* ── Attribution ─────────────────────────────── */

.attribution {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-top: 40px;
}

.attribution a {
  color: var(--text-muted);
  text-decoration: none;
}

.attribution a:hover {
  text-decoration: underline;
}

.version-info {
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-subtle);
  margin-top: 4px;
}

/* ── Favourite button (item header) ──────────── */

.fav-btn {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-muted);
  cursor: pointer;
  vertical-align: middle;
  margin-left: 8px;
  transition: background 0.15s, color 0.15s;
}

.fav-btn:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.fav-btn.favourited {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.fav-btn.favourited:hover {
  opacity: 0.85;
}

/* ── Favourites nav (search view) ────────────── */

.favs-nav {
  text-align: center;
  margin-bottom: 12px;
}

.favs-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  transition: opacity 0.15s;
}

.favs-link:hover {
  opacity: 0.8;
  text-decoration: underline;
}

.favs-count {
  display: inline-block;
  background: var(--accent);
  color: #000;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 4px;
  vertical-align: middle;
}

/* ── Favourites view ─────────────────────────── */

.favs-view {
  padding-top: 30px;
  max-width: 800px;
}

.favs-title {
  color: var(--text-heading);
  font-size: 1.3rem;
  margin-bottom: 20px;
}

/* ── Favourites grid ─────────────────────────── */

.favs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}

.fav-grid-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-secondary);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  text-align: center;
  outline: none;
}

.fav-grid-card:hover {
  background: var(--hover-bg);
  border-color: var(--accent);
  transform: translateY(-2px);
}

.fav-grid-card.kb-selected {
  background: var(--hover-bg);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  border-color: var(--accent);
}

.fav-grid-icon {
  width: 40px;
  height: 40px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.fav-grid-name {
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-heading);
  word-break: break-word;
  line-height: 1.2;
}

/* ── Owned checkbox ─────────────────────────── */

.owned-checkbox {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  margin-left: auto;
  cursor: pointer;
  accent-color: var(--accent);
}

/* ── Owned tree node ─────────────────────────── */

.tree-node.owned > .tree-item {
  opacity: 0.55;
}

.tree-node.owned > .tree-item .item-name {
  text-decoration: line-through;
}

/* ── Favourite progress ──────────────────────── */

.fav-progress {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 6px 12px;
  border-radius: 6px;
  margin-top: 10px;
}

/* ── Scrollbar ────────────────────────────────── */

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background: var(--scrollbar-thumb);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--scrollbar-thumb-hover);
}

/* ── Game tooltip (Terraria-style) ────────────── */

.game-tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 10000;
  background: rgba(30, 15, 50, 0.95);
  border: 2px solid rgba(120, 90, 160, 0.6);
  border-radius: 2px;
  padding: 8px 12px;
  font-family: var(--tooltip-font);
  font-size: 1rem;
  color: #e0e0e0;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
  max-width: 320px;
  opacity: 0;
  transition: opacity 0.12s ease;
  display: none;
  line-height: 1.35;
}

.game-tooltip.visible {
  opacity: 1;
}

.game-tooltip-name {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.game-tooltip-stat {
  font-size: 0.9rem;
  color: #ccc;
}

.game-tooltip-flavor {
  font-size: 0.9rem;
  font-style: italic;
  color: #a0a0a0;
  margin-top: 4px;
  white-space: pre-line;
}

.game-tooltip-sell {
  font-size: 0.85rem;
  color: #e8c84a;
  margin-top: 4px;
}

/* ── Keyboard navigation highlight ───────────── */

#item-list li.kb-selected {
  background: var(--hover-bg);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.tree-item.kb-selected {
  background: var(--hover-bg);
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ── Keybinds help overlay ───────────────────── */

.keybinds-help {
  position: fixed;
  bottom: 16px;
  right: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.8rem;
  color: var(--text);
  z-index: 9000;
  display: none;
  min-width: 180px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.keybinds-help.visible {
  display: block;
}

.keybinds-help-title {
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.keybinds-help-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.keybinds-help-row kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  color: var(--text-heading);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.keybinds-help-row span {
  color: var(--text-muted);
}

.keybinds-hint {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  z-index: 8999;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, color 0.15s;
  opacity: 0.6;
}

.keybinds-hint:hover {
  opacity: 1;
  color: var(--text);
}

.keybinds-hint.hidden {
  display: none;
}
