:root {
  --bg: #25211f;
  --bg-light: #2f2a28;
  --bg-lighter: #3a3432;
  --dirt: #5d4037;
  --dirt-dark: #3e2b24;
  --dirt-light: #795548;
  --stone: #757575;
  --stone-dark: #616161;
  --stone-light: #9e9e9e;
  --wood: #8d6e63;
  --wood-dark: #6d4c41;
  --ink: #efebe9;
  --muted: #bcaaa4;
  --accent: #4fc3f7;
  --accent-dark: #0288d1;
  --gold: #ffd54f;
  --gold-dark: #ff8f00;
  --positive: #69f0ae;
  --positive-soft: rgba(105, 240, 174, 0.15);
  --negative: #ff8a80;
  --negative-soft: rgba(255, 138, 128, 0.15);
  --shadow: 0 8px 0 rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 4px 0 rgba(0, 0, 0, 0.35);
  --radius: 6px;
  --radius-sm: 4px;
  --max-width: 520px;

  --font-body: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background-color: var(--bg);
  background-image:
    radial-gradient(var(--bg-lighter) 15%, transparent 16%),
    radial-gradient(var(--bg-lighter) 15%, transparent 16%);
  background-size: 16px 16px;
  background-position: 0 0, 8px 8px;
  color: var(--ink);
  line-height: 1.45;
}

.app {
  max-width: var(--max-width);
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: 10px;
}

/* Pixel border helper */
.pixel-box {
  border: 4px solid;
  border-color: var(--stone-light) var(--stone-dark) var(--stone-dark) var(--stone-light);
  box-shadow: var(--shadow);
}

/* Header */
.header {
  background: var(--wood);
  border-bottom: 4px solid var(--wood-dark);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand__logo {
  font-size: 1.8rem;
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  background: var(--dirt-light);
  border: 4px solid;
  border-color: var(--dirt-light) var(--dirt-dark) var(--dirt-dark) var(--dirt-light);
  box-shadow: var(--shadow-sm);
  image-rendering: pixelated;
}

.brand__eyebrow {
  margin: 0 0 2px;
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--gold);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.5);
}

.brand__title {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: -0.01em;
  line-height: 1.1;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
}

.refresh {
  width: 46px;
  height: 46px;
  border: 4px solid;
  border-color: var(--accent) var(--accent-dark) var(--accent-dark) var(--accent);
  border-radius: 0;
  background: var(--stone-light);
  color: var(--ink);
  font-size: 1.5rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
  transition: transform 0.08s ease;
  flex-shrink: 0;
}

.refresh:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
  border-color: var(--accent-dark) var(--accent) var(--accent) var(--accent-dark);
}

.refresh__icon {
  display: inline-block;
}

.refresh.spinning .refresh__icon {
  animation: spin 0.7s steps(8) infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Main */
.main {
  padding: 20px 14px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Chest hero */
.chest {
  background: var(--dirt);
  border: 4px solid;
  border-color: var(--dirt-light) var(--dirt-dark) var(--dirt-dark) var(--dirt-light);
  border-radius: var(--radius);
  padding: 22px 18px 20px;
  box-shadow: var(--shadow);
  position: relative;
}

.chest::before {
  content: '';
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  height: 8px;
  background: var(--gold);
  border: 2px solid var(--gold-dark);
  border-radius: 2px;
  opacity: 0.85;
}

.chest__label {
  margin: 0 0 6px;
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.4);
}

.chest__value {
  display: block;
  font-family: var(--font-mono);
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: #fff;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.35);
}

/* Totem stat chips */
.totems {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.totem {
  background: var(--bg-lighter);
  border: 4px solid;
  border-color: var(--bg-lighter) #1f1c1a #1f1c1a var(--bg-lighter);
  border-radius: var(--radius);
  padding: 16px 10px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 5px;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.totem::before {
  content: '';
  position: absolute;
  top: -4px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 6px;
  border-radius: 2px;
}

.totem--today::before {
  background: var(--accent);
  box-shadow: 0 0 10px rgba(79, 195, 247, 0.35);
}

.totem--overall::before {
  background: var(--gold);
  box-shadow: 0 0 10px rgba(255, 213, 79, 0.3);
}

.totem__label {
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.totem__value {
  font-family: var(--font-mono);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.totem__badge {
  font-size: 0.74rem;
  font-weight: 900;
  padding: 4px 9px;
  border-radius: var(--radius-sm);
  min-width: 56px;
}

/* Backpack inventory */
.backpack__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 4px;
}

.backpack__header h2 {
  margin: 0;
  font-family: var(--font-body);
  font-size: 1.15rem;
  font-weight: 900;
  color: var(--ink);
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.35);
}

.backpack__count {
  background: var(--bg-lighter);
  color: var(--muted);
  font-weight: 900;
  font-size: 0.8rem;
  padding: 5px 11px;
  border: 3px solid;
  border-color: var(--bg-lighter) #1f1c1a #1f1c1a var(--bg-lighter);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.backpack__grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Slot / item cards */
.slot {
  background: var(--bg-lighter);
  border: 4px solid;
  border-color: var(--bg-lighter) #1f1c1a #1f1c1a var(--bg-lighter);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  grid-template-columns: 52px 1fr auto;
  grid-template-rows: auto auto auto auto auto;
  gap: 4px 12px;
  align-items: start;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.slot--positive {
  border-color: var(--positive) #1f1c1a #1f1c1a var(--positive);
  background: linear-gradient(135deg, rgba(105, 240, 174, 0.08), var(--bg-lighter));
}

.slot--negative {
  border-color: var(--negative) #1f1c1a #1f1c1a var(--negative);
  background: linear-gradient(135deg, rgba(255, 138, 128, 0.08), var(--bg-lighter));
}

.slot__icon {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  background: var(--bg);
  border: 3px solid;
  border-color: var(--stone-light) var(--stone-dark) var(--stone-dark) var(--stone-light);
  border-radius: var(--radius-sm);
  font-size: 1.5rem;
  overflow: hidden;
}

.slot__icon > * {
  grid-column: 1;
  grid-row: 1;
}

.slot__logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 4px;
  background: #fff;
  border-radius: 2px;
}

.slot__symbol {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.slot__name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: #fff;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot__ticker {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  text-transform: uppercase;
}

.slot__qty {
  grid-column: 2;
  grid-row: 2;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.slot__value {
  grid-column: 3;
  grid-row: 1 / span 2;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  align-self: center;
  color: #fff;
}

.slot__badge {
  grid-column: 1;
  grid-row: 3;
  justify-self: start;
  font-size: 0.65rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 7px;
  border-radius: var(--radius-sm);
  margin-top: 2px;
  border: 2px solid;
}

.slot__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 3px dashed rgba(255, 255, 255, 0.08);
  font-size: 0.86rem;
  font-weight: 700;
}

.slot__row--overall {
  grid-column: 1 / -1;
  grid-row: 4;
}

.slot__row--today {
  grid-column: 1 / -1;
  grid-row: 5;
}

.slot__label {
  color: var(--muted);
}

.slot__amounts {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
}

.slot__pct {
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-weight: 900;
  font-family: var(--font-body);
  border: 2px solid;
}

/* Rarity / status badges */
.badge-legendary {
  background: rgba(255, 213, 79, 0.16);
  color: var(--gold);
  border-color: var(--gold-dark);
}

.badge-epic {
  background: rgba(179, 136, 255, 0.14);
  color: #b388ff;
  border-color: #7c4dff;
}

.badge-rare {
  background: rgba(79, 195, 247, 0.14);
  color: var(--accent);
  border-color: var(--accent-dark);
}

.badge-common {
  background: rgba(143, 163, 184, 0.12);
  color: var(--muted);
  border-color: var(--stone);
}

.badge-loss {
  background: var(--negative-soft);
  color: var(--negative);
  border-color: #b33939;
}

/* State utilities */
.positive {
  color: var(--positive);
}

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

.neutral {
  color: var(--muted);
}

.badge-positive {
  background: var(--positive-soft);
  color: var(--positive);
  border-color: #2e7d32;
}

.badge-negative {
  background: var(--negative-soft);
  color: var(--negative);
  border-color: #c62828;
}

.badge-neutral {
  background: rgba(143, 163, 184, 0.12);
  color: var(--muted);
  border-color: var(--stone);
}

/* Status / empty / error states */
.status,
.error-state {
  text-align: center;
  padding: 32px 20px;
  background: var(--bg-lighter);
  border: 4px solid;
  border-color: var(--bg-lighter) #1f1c1a #1f1c1a var(--bg-lighter);
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 700;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}

.error-state {
  color: var(--negative);
  background: var(--negative-soft);
  border-color: var(--negative) #1f1c1a #1f1c1a var(--negative);
}

.error-state small {
  display: block;
  margin-top: 8px;
  font-weight: 700;
  opacity: 0.9;
  color: var(--negative);
}

/* Chart section */
.chart-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chart-block {
  background: var(--bg-lighter);
  border: 4px solid;
  border-color: var(--bg-lighter) #1f1c1a #1f1c1a var(--bg-lighter);
  border-radius: var(--radius);
  padding: 14px 12px 12px;
  box-shadow: var(--shadow-sm);
}

.chart-container {
  width: 100%;
  height: 180px;
  overflow: hidden;
}

.chart-container svg {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-grid {
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.chart-area {
  stroke-width: 3;
  fill-opacity: 0.12;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-area--positive {
  stroke: var(--positive);
  fill: var(--positive);
}

.chart-area--negative {
  stroke: var(--negative);
  fill: var(--negative);
}

.chart-axis {
  stroke: var(--stone);
  stroke-width: 2;
}

.chart-label {
  fill: var(--muted);
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 700;
}

.chart-legend {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 10px;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--muted);
}

.chart-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chart-legend__swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  display: inline-block;
}

.chart-empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 60px 10px;
}

/* Hotbar footer */
.hotbar {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  gap: 8px;
  padding: 10px 14px 0;
}

.hotbar__slot {
  background: var(--bg-lighter);
  border: 4px solid;
  border-color: var(--bg-lighter) #1f1c1a #1f1c1a var(--bg-lighter);
  border-radius: var(--radius-sm);
  min-height: 52px;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-sm);
}

.hotbar__slot--selected {
  background: var(--wood);
  border-color: var(--wood) var(--wood-dark) var(--wood-dark) var(--wood);
  outline: 3px solid var(--gold);
  outline-offset: -6px;
}

.hotbar__text {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
  padding: 0 6px;
}

.hotbar__slot span[aria-hidden] {
  font-size: 1.4rem;
  filter: grayscale(0.4);
}

.hotbar__slot--selected span[aria-hidden] {
  filter: grayscale(0);
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .refresh.spinning .refresh__icon {
    animation: none;
  }
}

/* Wider screens */
@media (min-width: 400px) {
  .chest__value {
    font-size: 3rem;
  }

  .totem__value {
    font-size: 1.3rem;
  }
}

@media (min-width: 500px) {
  .main {
    padding: 26px 18px 30px;
  }

  .chest__value {
    font-size: 3.4rem;
  }
}
