@font-face {
  font-family: "Press Start 2P";
  src: url("../assets/fonts/PressStart2P-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Nunito";
  src: url("../assets/fonts/Nunito-Variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 200 900;
  font-display: swap;
}

:root {
  --ink: #3e2731;
  --parchment: #e4a672;
  --parchment-dark: #c28669;
  --panel-pad: 1.15rem 1.25rem 1.35rem;
  --green: #3e8948;
  --green-soft: #c6e4a8;
  --red: #e43b44;
  --red-soft: #f5c1b8;
  --blue: #1e6dd5;
  --blue-soft: #b9d6f5;
  --hold: #8b5a3c;
  --hold-soft: #debd8e;
  --paper: #fff6df;
  --shadow: #2a181e;
  --max: 1040px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Nunito", "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
  font-size: 1.0625rem;
  font-weight: 600;
  line-height: 1.45;
  background: #4f7f32;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; height: auto; }
h1, h2, h3 { margin: 0; color: var(--ink); }
p { margin: 0; }

.grass {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: url("../assets/grass_background_2.png");
  background-size: 128px 128px;
  background-repeat: repeat;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.page {
  width: min(var(--max), calc(100% - 1.5rem));
  margin: 0 auto;
  padding: 1.25rem 0 3rem;
}

.hero {
  text-align: center;
  padding: 0.5rem 0 1.1rem;
}
.logo {
  width: min(360px, 88vw);
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  filter: drop-shadow(0 3px 0 rgba(42, 24, 30, 0.35));
}
.farm-line {
  margin-top: 0.45rem;
  font-weight: 800;
  font-size: 1.05rem;
  text-shadow: 0 1px 0 rgba(255, 246, 223, 0.7);
}

.pixel {
  font-family: "Press Start 2P", ui-monospace, monospace;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.55;
}

.panel {
  border-style: solid;
  border-width: 8px;
  border-image-source: url("../assets/ui/light_border.png");
  border-image-slice: 2 fill;
  border-image-width: 8px;
  border-image-repeat: stretch;
  background-color: var(--parchment);
  color: var(--ink);
  padding: var(--panel-pad);
  margin-bottom: 1rem;
  image-rendering: pixelated;
}
.panel > .pixel { margin-bottom: 0.7rem; }

h1.pixel { font-size: clamp(0.95rem, 3.4vw, 1.2rem); }
h2.pixel { font-size: clamp(0.72rem, 2.4vw, 0.86rem); }

.today-sub {
  font-size: 1rem;
  font-weight: 700;
  margin: -0.25rem 0 1rem;
  opacity: 0.95;
}
.today-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}
@media (min-width: 840px) {
  .today-grid { grid-template-columns: repeat(3, 1fr); }
}

.action-card {
  background: var(--paper);
  border: 4px solid var(--ink);
  box-shadow: 4px 4px 0 var(--shadow);
  padding: 1rem 0.9rem 1.1rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100%;
}
.action-kicker {
  font-size: 0.78rem;
  padding: 0.4rem 0.7rem 0.3rem;
  color: #fff6df;
  margin-bottom: 0.75rem;
  min-width: 70%;
}
.action-card.vendi .action-kicker { background: var(--green); }
.action-card.compra .action-kicker { background: var(--blue); }
.action-card.accumula .action-kicker { background: #7a5c1e; }
.action-card.tieni .action-kicker { background: var(--hold); }
.action-card.neutro .action-kicker { background: #6b5a4a; }

.action-icon {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  margin-bottom: 0.35rem;
}
.action-name {
  font-size: 1.7rem;
  font-weight: 800;
  line-height: 1.15;
  margin: 0.15rem 0 0.35rem;
}
.action-price {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  flex-wrap: wrap;
}
.action-price .eur {
  font-size: 1rem;
  font-weight: 700;
  opacity: 0.85;
}
.tok {
  width: 22px;
  height: 22px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.action-why {
  margin-top: 0.55rem;
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.35;
  max-width: 22rem;
}
.hold-icons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.2rem;
  margin-bottom: 0.35rem;
  min-height: 96px;
  align-items: center;
}
.hold-icons img {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.legend ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.legend li { font-weight: 700; }

.arrow { font-weight: 800; font-variant-numeric: tabular-nums; }
.arrow.up { color: var(--green); }
.arrow.down { color: var(--red); }
.ch {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  white-space: nowrap;
}
.ch.up { color: var(--green); }
.ch.down { color: var(--red); }
.ch.flat { color: #6b5a4a; }

.pill {
  display: inline-block;
  font-family: "Nunito", "Segoe UI", sans-serif;
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1.2;
  padding: 0.22rem 0.5rem 0.2rem;
  color: #fff6df;
  vertical-align: middle;
}
.pill.vendi { background: var(--green); }
.pill.compra { background: var(--blue); }
.pill.accumula { background: #7a5c1e; }
.pill.tieni { background: var(--hold); }
.pill.neutro { background: #8a7a6a; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}
.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem 0.85rem;
  align-items: center;
  margin-bottom: 0.9rem;
}
.tool {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 800;
  font-size: 0.95rem;
}
.search, select {
  border-style: solid;
  border-width: 6px;
  border-image-source: url("../assets/ui/input_box_border.png");
  border-image-slice: 3 fill;
  border-image-width: 6px;
  border-image-repeat: stretch;
  background-color: var(--paper);
  padding: 0.4rem 0.65rem;
  min-height: 44px;
  image-rendering: pixelated;
}
.search {
  flex: 1 1 200px;
  min-width: min(100%, 200px);
  max-width: 320px;
}
.search:focus, select:focus {
  outline: 3px solid #1e6dd5;
  outline-offset: 1px;
}

.btn {
  appearance: none;
  border-style: solid;
  border-width: 9px 9px 12px 9px;
  border-image-source: url("../assets/ui/card_button.png");
  border-image-slice: 3 3 4 3 fill;
  border-image-width: 9px 9px 12px 9px;
  border-image-repeat: stretch;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
  font-size: 1rem;
  padding: 0.2rem 0.7rem 0.35rem;
  min-height: 44px;
  line-height: 1.15;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.btn.is-on { border-image-source: url("../assets/ui/selected_button.png"); }
.btn:active { transform: translateY(1px); }
.btn-small { min-height: 40px; font-size: 0.92rem; padding: 0.1rem 0.5rem 0.2rem; }

.market-head,
.market-row {
  display: grid;
  grid-template-columns: 48px minmax(8rem, 1.4fr) 8.2rem 6.6rem 6.4rem 6.4rem 6.2rem;
  gap: 0.4rem 0.55rem;
  align-items: center;
}
.market-head {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  opacity: 0.8;
  padding: 0 0.55rem 0.35rem;
  border-bottom: 3px solid var(--parchment-dark);
  margin-bottom: 0.25rem;
}
.market-row {
  width: 100%;
  text-align: left;
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0.45rem 0.55rem;
  border-bottom: 2px solid rgba(62, 39, 49, 0.12);
  font-weight: 700;
  border-radius: 0;
}
.market-row:hover,
.market-row:focus-visible {
  background: var(--paper);
  outline: none;
}
.market-row.is-open { background: var(--paper); }
.icon {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  flex-shrink: 0;
}
.name-cell { min-width: 0; }
.name-cell strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.2;
}
.name-cell small {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  opacity: 0.75;
}
.price-cell, .eur-cell {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}
.tok-sm {
  width: 16px;
  height: 16px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.sig-cell { text-align: left; }
.market-empty { margin: 0.8rem 0 0.2rem; font-weight: 700; }

.chart-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.7rem;
}
.chart-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}
.chart-price {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.15rem;
  margin: 0.35rem 0 0.7rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.8rem;
  align-items: center;
}
.ranges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.7rem;
}
.chart-frame {
  position: relative;
  background: var(--paper);
  border: 3px solid var(--ink);
  padding: 0.4rem 0.4rem 0.2rem;
}
#chart-svg { width: 100%; height: 220px; display: block; }
.chart-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  pointer-events: none;
}
.chart-status:empty { display: none; }
.chart-note {
  margin-top: 0.6rem;
  font-size: 0.92rem;
  font-weight: 700;
}

.foot p + p { margin-top: 0.45rem; }
.foot p { font-size: 0.92rem; font-weight: 700; opacity: 0.95; }

.season-ic {
  width: 28px;
  height: 32px;
  vertical-align: middle;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  margin-right: 0.25rem;
}
.status-dot {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  margin-right: 0.3rem;
  vertical-align: middle;
  background: #6b5a4a;
}
.status-dot.live { background: var(--green); }
.status-dot.baked { background: #c9a227; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 800px) {
  .market-head { display: none; }
  .market-row {
    grid-template-columns: 56px 1fr auto;
    grid-template-areas:
      "icon name sig"
      "icon price price"
      "icon ch ch";
    gap: 0.15rem 0.65rem;
    padding: 0.7rem 0.4rem;
  }
  .market-row .icon { grid-area: icon; width: 56px; height: 56px; }
  .name-cell { grid-area: name; }
  .sig-cell { grid-area: sig; justify-self: end; }
  .price-wrap {
    grid-area: price;
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem 0.8rem;
    align-items: baseline;
  }
  .ch-wrap {
    grid-area: ch;
    display: flex;
    flex-wrap: wrap;
    gap: 0.15rem 1rem;
    font-size: 0.95rem;
  }
  .ch-wrap .ch::after { font-weight: 700; color: var(--ink); opacity: 0.7; }
  /* labels added in JS for mobile via data-attr? we'll put small labels in markup */
}

@media (min-width: 801px) {
  .price-wrap, .ch-wrap { display: contents; }
  .mob-label { display: none; }
}

@media (max-width: 800px) {
  .mob-label {
    display: inline;
    font-weight: 700;
    opacity: 0.7;
    margin-right: 0.2rem;
  }
  body { font-size: 1rem; }
  .action-name { font-size: 1.5rem; }
  .page { width: min(var(--max), calc(100% - 1rem)); }
  .search { max-width: none; width: 100%; flex-basis: 100%; }
  .tool { width: 100%; }
  .tool select { flex: 1; min-width: 0; }
}
