/* Variables */
:root {
  --page-bg: #f4f0ea;
  --accent: #3c2f2f;
  --muted: #68635d;
  --card-bg: #f8f8f8;
  --card-width: 220px;
  --site-max-width: 1200px;
  --shop-max-width: 1000px;
  --gutter: 0.8rem;

  --card-border: rgba(60, 47, 47, 0.12);
  --card-meta-bg: rgba(60, 47, 47, 0.05);
  --danger: #7a2f2f;

  --rarity-common-glow: rgba(255, 255, 255, 0.55);
  --rarity-uncommon-glow: rgba(74, 163, 99, 0.58);
  --rarity-rare-glow: rgba(70, 120, 255, 0.62);
  --rarity-very-rare-glow: rgba(146, 93, 255, 0.66);
  --rarity-legendary-glow: rgba(212, 164, 52, 0.72);
}

/* Base */
* {
  box-sizing: border-box;
}

html {
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

html,
body {
  min-height: 100%;
  margin: 0;
  padding: 0;
  background-color: var(--page-bg);
  font-family: Georgia, serif;
  color: #222;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
}

h2 {
  text-align: center;
  margin-top: 2.5rem;
  margin-bottom: 2.5rem;
  font-size: 1.8rem;
}

/* Navigation */
nav {
  position: sticky;
  top: 0;
  z-index: 1000;
  background-color: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 3rem max(2rem, calc((100% - var(--shop-max-width)) / 2));
  gap: 1.25rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
}

nav h1 {
  margin: 0;
  flex: 1 1 auto;
  text-align: left;
  font-size: 1.4rem;
}

nav ul {
  list-style: none;
  display: flex;
  justify-content: center;
  flex: 1 1 100%;
  gap: 1rem;
  margin: 0;
  padding: 0;
}

nav a {
  color: #fff;
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

nav a:hover {
  color: #ffd700;
}

.site-brand {
  margin: 0;
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: #fff;
}

.logo-link {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
}

.logo-link:hover {
  opacity: 0.85;
}

.brand-logo {
  width: 42px;
  height: 42px;
  display: block;
  object-fit: contain;
}

/* Gold Tracker */
.gold-tracker {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  flex: 1 1 auto;
}

#gold-amount {
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
}

#gold-input {
  width: 96px;
  height: 24px;
  padding: 0 0.45rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background-color: #fff;
  color: #222;
  font-family: inherit;
  font-size: 0.75rem;
}

#gold-input::placeholder {
  color: #777;
}

#gold-input:focus {
  outline: 2px solid #ffd700;
  outline-offset: 2px;
}

#update-gold {
  height: 24px;
  border: none;
  padding: 0 0.55rem;
  border-radius: 4px;
  background-color: #fff;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 700;
  transition: background-color 0.16s ease;
}

#update-gold:hover {
  background-color: #ffd700;
}

#update-gold:focus {
  outline: 2px solid #ffd700;
  outline-offset: 2px;
}

/* Layout */
.about {
  padding: 2rem;
  max-width: 700px;
  margin: 0 auto;
}

.container {
  max-width: var(--site-max-width);
  margin: 0 auto;
  padding: 0 1rem;
}

footer {
  background-color: var(--accent);
  color: #fff;
  padding: 1rem 2rem;
  text-align: center;
  margin-top: 2em;
}

/* Shop Sections */
.shop-section {
  margin: 2rem auto;
  max-width: var(--shop-max-width);
  background: #fff;
  border: 2px solid rgba(60, 47, 47, 0.14);
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(16, 24, 40, 0.09);
  overflow: hidden;
}

.shop-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  min-height: 150px;
  padding: 1.5rem 2.25rem;
  cursor: pointer;
}

.shop-toggle-btn {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font: inherit;
  color: inherit;
  pointer-events: none;
  flex: 1 1 auto;
  text-align: left;
}

.shop-toggle-btn h3 {
  margin: 0;
  font: inherit;
  font-size: 1.17rem;
  font-weight: 700;
  line-height: 1.2;
}

.shop-title {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.shop-icon {
  width: 1.5rem;
  height: 100%;
  display: inline-block;
  object-fit: contain;
  flex-shrink: 0;
}

.triangle {
  display: inline-block;
  color: var(--accent);
  font-size: 0.95rem;
  line-height: 1;
  transform-origin: center;
  transition: transform 0.2s ease;
  flex: 0 0 auto;
}

.shop-toggle-btn[aria-expanded="true"] .triangle {
  transform: rotate(90deg);
}

.tier-select {
  flex: 0 0 auto;
  width: 110px;
  min-width: 110px;
  max-width: 110px;
  height: 38px;
  padding: 0 0.65rem;
  border-radius: 6px;
  border: 1px solid #ccc;
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 38px;
  background: #fff;
  color: #222;
  cursor: pointer;
  position: relative;
  z-index: 2;
  align-self: center;
  text-align: center;
  text-align-last: center;
}

/* Grids */
.shop-items,
.cart-grid,
.inventory-grid,
#cart-container,
#inventory-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, var(--card-width));
  gap: var(--gutter);
  justify-content: center;
  align-items: stretch;
  max-width: var(--site-max-width);
  margin: 0 auto;
}

#cart-container {
  max-width: var(--shop-max-width);
}

.shop-items {
  padding: 0 1.25rem 1.5rem;
}

.cart-grid,
.inventory-grid,
#cart-container,
#inventory-list {
  padding: 0.5rem;
}

.is-collapsed {
  display: none;
}

/* Empty States */
.empty-state {
  grid-column: 1 / -1;
  width: 100%;
  margin: 2rem auto 3rem;
  padding: 1rem;
  text-align: center;
  color: var(--muted);
}

.empty-state h3 {
  margin: 0;
  color: var(--danger);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.2;
}

.empty-state p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

#cart-container > p,
#inventory-list > p {
  grid-column: 1 / -1;
  width: 100%;
  margin: 2rem auto 3rem;
  padding: 1rem;
  text-align: center;
  color: var(--danger);
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.5;
}

/* Cards */
.item,
.cart-item,
.inventory-item {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 10px;
  padding: 0.8rem;
  width: var(--card-width);
  max-width: var(--card-width);
  min-height: 100%;
  display: flex;
  flex-direction: column;
  text-align: left;
  position: relative;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  animation: cardGlowPulse 2.8s ease-in-out infinite;
}

.item:hover,
.cart-item:hover,
.inventory-item:hover {
  transform: translateY(-4px);
}

.item img,
.cart-item img,
.inventory-item img {
  width: 100%;
  height: 155px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
  margin-bottom: 0.55rem;
}

.item h4,
.cart-item h4,
.inventory-item h4 {
  margin: 0.3rem 0 0.55rem;
  font-size: 1rem;
  line-height: 1.25;
  text-align: center;
}

.item-description,
.cart-item-description,
.inventory-item-description,
.cart-description,
.inventory-description {
  margin: 0 0 0.65rem;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-meta,
.cart-item-meta,
.inventory-item-meta,
.cart-meta,
.inventory-meta {
  margin-bottom: 0.7rem;
  display: grid;
  gap: 0.4rem;
}

.meta-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.42rem 0.55rem;
  background: var(--card-meta-bg);
  border-radius: 8px;
  font-size: 0.82rem;
  color: #4a4540;
}

.meta-label {
  font-weight: 700;
}

.item-price,
.cart-item-price,
.inventory-item-price,
.cart-price,
.inventory-price {
  margin-top: auto;
  margin-bottom: 0.55rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent);
}

.cart-item,
.inventory-item {
  min-height: 100%;
}

.cart-item .remove-btn,
.inventory-item .remove-btn {
  margin-top: 0;
}

/* Rarity Effects */
.rarity-common {
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.08),
    0 0 0 1px rgba(255, 255, 255, 0.4),
    0 0 16px var(--rarity-common-glow);
}

.rarity-common:hover {
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.12),
    0 0 0 1px rgba(255, 255, 255, 0.55),
    0 0 24px rgba(255, 255, 255, 0.72);
}

.rarity-uncommon {
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.08),
    0 0 0 1px rgba(74, 163, 99, 0.16),
    0 0 18px var(--rarity-uncommon-glow);
}

.rarity-uncommon:hover {
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.12),
    0 0 0 1px rgba(74, 163, 99, 0.22),
    0 0 26px rgba(74, 163, 99, 0.72);
}

.rarity-rare {
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.08),
    0 0 0 1px rgba(70, 120, 255, 0.16),
    0 0 18px var(--rarity-rare-glow);
}

.rarity-rare:hover {
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.12),
    0 0 0 1px rgba(70, 120, 255, 0.22),
    0 0 28px rgba(70, 120, 255, 0.75);
}

.rarity-very-rare {
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.08),
    0 0 0 1px rgba(146, 93, 255, 0.16),
    0 0 20px var(--rarity-very-rare-glow);
}

.rarity-very-rare:hover {
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.12),
    0 0 0 1px rgba(146, 93, 255, 0.22),
    0 0 30px rgba(146, 93, 255, 0.8);
}

.rarity-legendary {
  box-shadow:
    0 3px 8px rgba(0, 0, 0, 0.08),
    0 0 0 1px rgba(212, 164, 52, 0.2),
    0 0 22px var(--rarity-legendary-glow);
}

.rarity-legendary:hover {
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.12),
    0 0 0 1px rgba(212, 164, 52, 0.28),
    0 0 32px rgba(212, 164, 52, 0.85);
}

@keyframes cardGlowPulse {
  0%,
  100% {
    filter: brightness(1);
  }

  50% {
    filter: brightness(1.06);
  }
}

/* Icons */
.icon {
  width: 20px;
  height: 20px;
  display: inline-block;
  flex: 0 0 20px;
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
}

.icon-type {
  background-image: url("../icons/type.svg");
}

.icon-attunement {
  background-image: url("../icons/attunement.svg");
}

.icon-cost {
  background-image: url("../icons/cost.svg");
}

/* Buttons */
.buy-btn,
.remove-btn,
.checkout-btn {
  border: none;
  padding: 0.45rem 0.8rem;
  border-radius: 8px;
  cursor: pointer;
  color: #fff;
  transition: background 0.16s ease;
  font-size: 0.9rem;
}

.buy-btn,
.remove-btn {
  display: block;
  width: fit-content;
  margin: 0 auto;
}

.buy-btn {
  background-color: var(--accent);
}

.buy-btn:hover {
  background-color: #523035;
}

.remove-btn {
  background-color: var(--danger);
}

.remove-btn:hover {
  background-color: #9a3d3d;
}

.checkout-btn {
  display: block;
  margin: 2rem auto 0;
  background-color: var(--accent);
}

/* Toasts */
.toast {
  position: fixed;
  left: 50%;
  bottom: 2rem;
  z-index: 9999;
  max-width: min(90%, 420px);
  padding: 0.85rem 1.1rem;
  background-color: var(--accent);
  color: #fff;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(60, 47, 47, 0.28);
  font-size: 0.95rem;
  line-height: 1.4;
  text-align: center;
  transform: translate(-50%, 1rem);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 0.25s ease,
    transform 0.25s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast-success {
  background-color: var(--accent);
}

.toast-error {
  background-color: var(--danger);
}

/* Mobile Navigation */
#menu-toggle {
  display: none;
  font-size: 1.8rem;
  background: none;
  border: none;
  color: white;
  cursor: pointer;
}

.nav-row {
  display: contents;
}

/* Responsive */
@media (max-width: 768px) {
  nav {
    padding: 1.75rem 1rem;
    flex-direction: column;
    align-items: stretch;
  }

  nav h1 {
    text-align: center;
    width: 100%;
  }

  .site-brand {
    justify-content: center;
    text-align: center;
  }

  .brand-logo {
    width: 36px;
    height: 36px;
  }

  .nav-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    margin-top: 0.5rem;
  }

  .gold-tracker {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  #gold-amount {
    font-size: 0.85rem;
  }

  #gold-input {
    width: 92px;
    height: 24px;
    font-size: 0.72rem;
  }

  #update-gold {
    height: 24px;
    font-size: 0.72rem;
  }

  #menu-toggle {
    display: block;
  }

  #nav-links {
    display: none;
    flex: unset;
    width: 100%;
    max-width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    margin-top: 1rem;
    padding: 0;
    gap: 0.5rem;
  }

  #nav-links.active {
    display: flex;
  }

  #nav-links a {
    display: block;
    width: 100%;
    padding: 0.5rem;
  }

  .shop-section {
    margin: 1.25rem 0.75rem;
  }

  .shop-header {
    min-height: 96px;
    padding: 1.15rem;
    gap: 0.75rem;
  }

  .shop-toggle-btn h3 {
    font-size: 1.05rem;
  }

  .tier-select {
    width: 110px;
    min-width: 110px;
    max-width: 110px;
    height: 38px;
    line-height: 38px;
    font-size: 0.95rem;
  }

  .shop-items {
    padding: 0 0.75rem 1rem;
  }

  .empty-state,
  #cart-container > p,
  #inventory-list > p {
    margin-top: 1.5rem;
    padding: 0.75rem;
  }

  .empty-state h3 {
    font-size: 1.2rem;
  }

  .toast {
    bottom: 1rem;
  }
}

@media (max-width: 520px) {
  :root {
    --card-width: 180px;
  }

  .item,
  .cart-item,
  .inventory-item {
    padding: 0.7rem;
  }

  .item img,
  .cart-item img,
  .inventory-item img {
    height: 125px;
  }

  .item h4,
  .cart-item h4,
  .inventory-item h4 {
    font-size: 0.95rem;
  }

  .item-description,
  .cart-description,
  .inventory-description {
    font-size: 0.82rem;
  }

  .meta-row {
    font-size: 0.76rem;
  }
}