:root {
  --bg: #101215;
  --bg-soft: #171a1f;
  --panel: #f4f1e8;
  --panel-strong: #fffaf0;
  --ink: #171a1f;
  --muted: #68707a;
  --line: rgba(23, 26, 31, 0.14);
  --green: #1f9d61;
  --green-strong: #0d7547;
  --gold: #c8932f;
  --red: #c84c3e;
  --blue: #256c9f;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 0%, rgba(45, 129, 92, 0.22), transparent 28rem),
    linear-gradient(135deg, #101215 0%, #202328 46%, #111316 100%);
}

button {
  font: inherit;
}

.market-tape {
  width: 100%;
  overflow: hidden;
  color: #dcfce7;
  background: #08090b;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.market-tape__track {
  display: flex;
  gap: 28px;
  width: max-content;
  padding: 8px 0;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  animation: ticker 36s linear infinite;
}

.market-tape__track span {
  white-space: nowrap;
}

@keyframes ticker {
  from {
    transform: translateX(0);
  }

  to {
    transform: translateX(-50%);
  }
}

.app-shell {
  width: min(1380px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 44px;
}

.topbar,
.game-grid,
.hero-stats,
.score-grid,
.terminal-panel__header,
.panel__header,
.progress-block__label,
.milestone-meter__label,
.upgrade-card__top,
.stage-row {
  display: grid;
}

.topbar {
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  color: #f8fafc;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand__mark {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

.brand h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.4rem);
  line-height: 0.94;
  letter-spacing: 0;
}

.brand__eyebrow,
.section-label {
  margin: 0 0 5px;
  font-size: 0.75rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.brand__eyebrow {
  color: #a7f3d0;
}

.topbar__actions {
  display: flex;
  gap: 10px;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  cursor: pointer;
  font-weight: 900;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.15);
}

.icon-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.game-grid {
  grid-template-columns: minmax(0, 1.25fr) minmax(310px, 0.75fr);
  grid-template-areas:
    "terminal side"
    "upgrades milestones"
    "upgrades prestige";
  gap: 18px;
  align-items: start;
}

.terminal-panel,
.panel {
  border: 1px solid rgba(255, 255, 255, 0.36);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.terminal-panel {
  grid-area: terminal;
  padding: 18px;
}

.side-stack {
  grid-area: side;
  display: grid;
  gap: 18px;
}

.upgrades-panel {
  grid-area: upgrades;
}

.milestones-panel {
  grid-area: milestones;
}

.prestige-panel {
  grid-area: prestige;
}

.panel {
  padding: 18px;
}

.terminal-panel__header,
.panel__header {
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: start;
  margin-bottom: 16px;
}

h2 {
  margin: 0;
  font-size: 1.3rem;
}

.section-label {
  color: var(--green-strong);
}

.stage-chip {
  align-self: start;
  border: 1px solid rgba(31, 157, 97, 0.22);
  border-radius: 999px;
  padding: 8px 10px;
  color: var(--green-strong);
  background: rgba(31, 157, 97, 0.08);
  font-size: 0.82rem;
  font-weight: 900;
}

.screen {
  position: relative;
  min-height: 310px;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(9, 19, 17, 0.2), rgba(8, 10, 12, 0.84)),
    #101916;
  border: 1px solid rgba(0, 0, 0, 0.5);
}

.screen .hero-stats {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 52px;
}

.screen__grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(108, 255, 183, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(108, 255, 183, 0.08) 1px, transparent 1px);
  background-size: 36px 36px;
}

.market-chart {
  position: absolute;
  inset: 22px 16px 58px;
  width: calc(100% - 32px);
  height: calc(100% - 80px);
  overflow: visible;
}

.chart-area {
  fill: url(#chartFill);
}

.chart-line {
  fill: none;
  stroke: #42d889;
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 10px rgba(66, 216, 137, 0.45));
}

.chart-dot {
  fill: #f7d36a;
  stroke: #101916;
  stroke-width: 3;
}

.screen__readout {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 14px;
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: #d1fae5;
  font-size: 0.88rem;
}

.screen__readout span {
  color: #80caa5;
}

.hero-stats {
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 0;
}

.metric,
.score-grid div,
.legacy-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 14px;
}

.metric span,
.score-grid span,
.legacy-box span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.metric strong,
.score-grid strong,
.legacy-box strong {
  display: block;
  margin-top: 4px;
  font-size: clamp(1.1rem, 2.4vw, 2rem);
  line-height: 1;
  overflow-wrap: anywhere;
}

.metric--primary {
  background: #e7f8ee;
  border-color: rgba(31, 157, 97, 0.25);
}

.research-button,
.button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 900;
}

.research-button {
  width: 100%;
  min-height: 86px;
  display: grid;
  place-items: center;
  gap: 2px;
  color: #fff;
  background: linear-gradient(135deg, #16824f, #1fb36e 54%, #0d6c46);
  box-shadow: 0 14px 0 #084c31;
  transform: translateY(0);
}

.research-button:hover {
  filter: brightness(1.05);
}

.research-button:active {
  transform: translateY(8px);
  box-shadow: 0 6px 0 #084c31;
}

.research-button span {
  font-size: clamp(1.4rem, 4vw, 2.4rem);
}

.research-button small {
  color: rgba(255, 255, 255, 0.78);
  font-weight: 800;
}

.score-grid {
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.progress-block {
  margin-top: 14px;
}

.progress-block__label {
  grid-template-columns: 1fr auto;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 26, 31, 0.1);
}

.progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), #f0be4b);
  transition: width 180ms ease;
}

.muted {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.5;
}

.legacy-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.legacy-box--points {
  background: #fff7dc;
  border-color: rgba(200, 147, 47, 0.35);
}

.prestige-gain {
  margin: -4px 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.prestige-gain strong {
  color: var(--gold);
}

.button {
  min-height: 44px;
  padding: 0 16px;
}

.button--dark {
  width: 100%;
  color: #fff;
  background: var(--ink);
}

.button--light {
  width: 100%;
  color: var(--ink);
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.save-code {
  width: 100%;
  min-height: 116px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  color: var(--ink);
  background: var(--panel-strong);
  font: 0.78rem ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.save-transfer-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: transparent;
}

.upgrade-controls {
  display: flex;
  justify-content: flex-end;
}

.tab,
.buy-mode-toggle {
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-weight: 900;
}

.tab {
  border-bottom: 3px solid transparent;
}

.tab.is-active {
  color: var(--ink);
  border-bottom-color: var(--green-strong);
}

.buy-mode-toggle {
  min-width: 48px;
  color: #fff;
  background: var(--ink);
  border-radius: 8px 8px 0 0;
}

.upgrade-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.upgrade-card {
  min-height: 288px;
  display: grid;
  gap: 12px;
  align-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 14px;
}

.upgrade-card__top {
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.upgrade-card h3 {
  margin: 0;
  font-size: 1rem;
}

.upgrade-card p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.effect-list {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
  padding: 9px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.effect-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  line-height: 1.25;
}

.effect-row__delta {
  color: var(--green-strong);
  white-space: nowrap;
}

.milestone-meter {
  display: grid;
  gap: 7px;
}

.milestone-meter__label {
  grid-template-columns: 1fr auto;
  gap: 10px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 900;
}

.milestone-meter__label strong {
  color: var(--green-strong);
}

.upgrade-card__owned {
  min-width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(37, 108, 159, 0.12);
  color: var(--blue);
  font-weight: 900;
}

.buy-button {
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--green-strong);
  cursor: pointer;
  font-weight: 900;
  white-space: nowrap;
}

.buy-button:disabled {
  cursor: not-allowed;
  background: #9ca3af;
}

.stage-list {
  display: grid;
  gap: 8px;
}

.stage-row {
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.35);
}

.stage-row__number {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(23, 26, 31, 0.1);
  font-weight: 900;
}

.stage-row h3 {
  margin: 0;
  font-size: 0.96rem;
}

.stage-row p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.stage-row.is-unlocked {
  background: #e7f8ee;
  border-color: rgba(31, 157, 97, 0.3);
}

.stage-row.is-current .stage-row__number {
  color: #fff;
  background: var(--green-strong);
}

.prestige-store {
  display: grid;
  gap: 8px;
}

.prestige-balance {
  align-self: start;
  border: 1px solid rgba(200, 147, 47, 0.35);
  border-radius: 999px;
  padding: 7px 9px;
  color: #7a5615;
  background: #fff7dc;
  font-size: 0.78rem;
  font-weight: 900;
  white-space: nowrap;
}

.prestige-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.42);
}

.prestige-card h3 {
  margin: 0;
  font-size: 0.94rem;
}

.prestige-card p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.3;
}

.prestige-card__meta {
  display: grid;
  justify-items: end;
  gap: 3px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-align: right;
}

.prestige-card__meta strong {
  color: var(--ink);
  font-size: 0.76rem;
}

.prestige-card__meta span span,
.prestige-card__meta strong span {
  color: var(--green-strong);
}

.prestige-buy {
  grid-column: 1 / -1;
  min-height: 32px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--gold);
  cursor: pointer;
  font-weight: 900;
}

.prestige-buy:disabled {
  cursor: not-allowed;
  background: #9ca3af;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(360px, calc(100% - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: rgba(17, 24, 39, 0.94);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .game-grid {
    grid-template-columns: 1fr;
    grid-template-areas:
      "terminal"
      "upgrades"
      "side"
      "milestones"
      "prestige";
  }

  .side-stack {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .market-tape__track {
    padding: 5px 0;
    font-size: 0.65rem;
  }

  .app-shell {
    width: min(100% - 12px, 1380px);
    padding-top: 10px;
    padding-bottom: 24px;
  }

  .topbar {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-bottom: 10px;
  }

  .terminal-panel__header,
  .panel__header {
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin-bottom: 10px;
  }

  .upgrade-controls {
    justify-items: start;
  }

  .topbar__actions {
    justify-self: start;
    gap: 8px;
  }

  .brand__mark {
    width: 36px;
    height: 36px;
  }

  .brand {
    gap: 9px;
  }

  .brand h1 {
    font-size: 1.65rem;
  }

  .brand__eyebrow,
  .section-label {
    font-size: 0.63rem;
    margin-bottom: 3px;
  }

  .icon-button {
    width: 34px;
    height: 34px;
  }

  .icon-button svg {
    width: 18px;
    height: 18px;
  }

  .terminal-panel,
  .panel {
    padding: 10px;
  }

  .game-grid {
    gap: 10px;
  }

  h2 {
    font-size: 1rem;
  }

  .stage-chip {
    padding: 5px 8px;
    font-size: 0.7rem;
  }

  .screen {
    min-height: 124px;
  }

  .market-chart {
    inset: 18px 8px 26px;
    width: calc(100% - 20px);
    height: calc(100% - 42px);
    opacity: 0.72;
  }

  .chart-line {
    stroke-width: 4;
  }

  .chart-dot {
    r: 4px;
  }

  .screen__readout {
    left: 10px;
    right: 10px;
    bottom: 8px;
    font-size: 0.68rem;
  }

  .screen__readout strong {
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .screen .hero-stats {
    inset: 8px 10px auto;
    min-height: calc(100% - 38px);
    align-content: space-between;
    pointer-events: none;
  }

  .hero-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  .metric,
  .score-grid div,
  .legacy-box {
    padding: 8px;
  }

  .metric span,
  .score-grid span,
  .legacy-box span {
    font-size: 0.66rem;
  }

  .metric strong,
  .score-grid strong,
  .legacy-box strong {
    font-size: clamp(0.82rem, 4vw, 1.1rem);
    margin-top: 2px;
  }

  .metric {
    color: #d1fae5;
    background: rgba(8, 15, 13, 0.68);
    border-color: rgba(167, 243, 208, 0.24);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.18);
  }

  .metric span {
    color: #9fe7c3;
  }

  .metric strong {
    color: #f8fafc;
  }

  .metric--primary {
    grid-column: 1 / -1;
    max-width: 62%;
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    padding: 0;
  }

  .metric--primary span {
    color: #a7f3d0;
  }

  .metric--primary strong {
    font-size: clamp(1.55rem, 9vw, 2.3rem);
    line-height: 0.95;
    text-shadow: 0 2px 14px rgba(0, 0, 0, 0.45);
  }

  .side-stack,
  .score-grid,
  .save-transfer-actions {
    grid-template-columns: 1fr;
  }

  .research-button {
    min-height: 56px;
    box-shadow: 0 8px 0 #084c31;
  }

  .research-button:active {
    transform: translateY(5px);
    box-shadow: 0 3px 0 #084c31;
  }

  .research-button span {
    font-size: 1.35rem;
  }

  .research-button small {
    font-size: 0.7rem;
  }

  .tabs {
    width: 100%;
  }

  .tab,
  .buy-mode-toggle {
    flex: 1 1 auto;
    min-height: 30px;
    padding: 0 6px;
    font-size: 0.7rem;
  }

  .upgrade-list {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .upgrade-card {
    min-height: 0;
    gap: 8px;
    padding: 10px;
  }

  .upgrade-card h3 {
    font-size: 0.92rem;
  }

  .upgrade-card p {
    font-size: 0.78rem;
    line-height: 1.32;
  }

  .effect-list {
    gap: 3px;
    padding: 7px;
    font-size: 0.72rem;
  }

  .buy-button,
  .button {
    min-height: 32px;
    font-size: 0.78rem;
  }

  .side-stack {
    gap: 10px;
  }

  .save-code {
    min-height: 82px;
    font-size: 0.7rem;
  }

  .prestige-card {
    grid-template-columns: 1fr auto;
    padding: 8px;
  }

  .prestige-card h3 {
    font-size: 0.86rem;
  }

  .prestige-card p,
  .prestige-card__meta,
  .prestige-card__meta strong {
    font-size: 0.7rem;
  }

  .prestige-buy {
    min-height: 30px;
    font-size: 0.76rem;
  }

  .stage-row {
    grid-template-columns: auto 1fr;
  }

  .stage-row > strong {
    grid-column: 2;
    font-size: 0.78rem;
  }

  .stage-row p {
    font-size: 0.74rem;
  }
}
