/* Palette, typography and the small reusable components.
   Act transitions drive --sky-*, --ground and --ember from js/ui/render.js. */

:root {
  color-scheme: dark;

  /* Surfaces */
  --bg: #0b0c10;
  --panel: #16181f;
  --panel-2: #1e212a;
  --panel-3: #262a35;
  --line: #2f3441;
  --line-soft: #23262f;

  /* Text */
  --text: #e8e4dc;
  --text-dim: #a6adb9;
  --text-faint: #6f7783;

  /* Semantics */
  --ember: #ff7a2f;
  --ember-soft: #ffa168;
  --gold: #f0b429;
  --power: #6c9fd1;
  --valor: #b57ae0;
  --danger: #e34b39;
  --good: #7fb069;
  --warn: #e0a030;

  /* Act-driven, overwritten at runtime */
  --sky-1: #3d5a80;
  --sky-2: #98a8b8;
  --sky-3: #e8b48a;
  --ground: #4a5340;
  --fog: 0;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 4px 16px rgb(0 0 0 / 0.45);
  --shadow-lg: 0 12px 48px rgb(0 0 0 / 0.6);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

/* Every number in the game is tabular. Without this, counters visibly jitter
   as digits change width and the whole UI feels cheap. */
.num,
.stat-value,
.cost,
.rate {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ---------- Type ---------- */

.title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.hint {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

.flavour {
  font-size: 12px;
  font-style: italic;
  color: var(--text-faint);
  line-height: 1.4;
}

/* ---------- Top bar stats ---------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(6px + env(safe-area-inset-top)) 10px 6px;
  background: linear-gradient(180deg, #14161d, #101218);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 30;
}

.stat {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 9px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

/* Four stat tiles will not fit a phone width in one row — they forced ~100px of
   horizontal overflow on the whole document, which then dragged every
   full-width child out with them. Wrap into a 2x2 block instead of shrinking
   the numbers into ellipses. */
@media (max-width: 700px) {
  #topbar {
    flex-wrap: wrap;
  }

  .stat {
    flex: 1 1 calc(50% - 6px);
  }
}

.stat-icon {
  font-size: 17px;
  line-height: 1;
  flex: none;
}

.stat-text {
  min-width: 0;
}

.stat-label {
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-faint);
  line-height: 1.2;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.15;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-sub {
  font-size: 10px;
  color: var(--text-dim);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Push the sub-label to the far edge of its stat tile. It must be allowed to
   shrink, or `white-space: nowrap` makes it an unshrinkable strut that pushes
   the whole bar wider than the screen. */
.stat > .stat-sub {
  margin-left: auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Toggled from JS instead of an inline style, so the CSP needs no
   'unsafe-inline' for style attributes. */
.is-hidden {
  display: none !important;
}

.noscript-notice {
  padding: 24px;
  text-align: center;
}

.noscript-notice h1 {
  font-size: 20px;
  margin-bottom: 8px;
}

.noscript-notice p {
  color: var(--text-dim);
}

#stat-ingots .stat-value { color: var(--ember-soft); }
#stat-gold .stat-value { color: var(--gold); }
#stat-power .stat-value { color: var(--power); }
#stat-valor .stat-value { color: var(--valor); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  transition: background 120ms, border-color 120ms, transform 60ms;
}

.btn:hover:not(:disabled) {
  background: var(--panel-3);
  border-color: #3c4351;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.4;
}

.btn-primary {
  background: linear-gradient(180deg, #c8541b, #a03f12);
  border-color: #e07a3a;
  color: #fff5ec;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #dd6021, #b34815);
  border-color: #ff9a5a;
}

.btn-gold {
  background: linear-gradient(180deg, #8a6412, #6a4a0c);
  border-color: #c99a2a;
  color: #fff4d8;
}

.btn-danger {
  border-color: #6b2b24;
  color: #f0a89f;
}

.btn-valor {
  background: linear-gradient(180deg, #6b3f8f, #4e2c6b);
  border-color: #9b6bc4;
  color: #f3e8ff;
}

.btn-sm {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 12px;
}

/* ---------- Shop rows (buildings, gear, upgrades) ---------- */

.row {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  padding: 9px 11px;
  text-align: left;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  transition: background 100ms, border-color 100ms, transform 60ms;
}

.row + .row {
  margin-top: 6px;
}

.row:hover:not(.locked):not(:disabled) {
  background: var(--panel-2);
  border-color: #363c4a;
}

.row:active:not(.locked):not(:disabled) {
  transform: translateY(1px);
}

/* Affordable rows get a warm edge — the single strongest "buy me" signal. */
.row.affordable {
  border-color: #5a4020;
  background: linear-gradient(90deg, #1d1a16, var(--panel) 40%);
}

.row.affordable:hover {
  border-color: var(--ember);
}

.row.unaffordable {
  opacity: 0.55;
}

.row.owned-none .row-count {
  color: var(--text-faint);
}

.row-icon {
  font-size: 24px;
  line-height: 1;
  text-align: center;
  filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.5));
}

.row-main {
  min-width: 0;
}

.row-name {
  font-size: 14px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-meta {
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* The "N more -> x2" line. Deliberately in the ember colour: it is the thing
   the player should always be able to see a reason to keep buying toward. */
.row-milestone {
  font-size: 10px;
  font-weight: 700;
  color: var(--ember-soft);
  opacity: 0.85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.row-right {
  text-align: right;
  flex: none;
}

.cost {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.cost.can { color: var(--ember-soft); }
.cost.cant { color: var(--text-faint); }
.cost.gold-can { color: var(--gold); }
.cost.gold-cant { color: var(--text-faint); }

.row-count {
  font-size: 19px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.row.locked {
  opacity: 0.35;
  filter: grayscale(1);
  cursor: default;
}

/* ---------- Panels ---------- */

.section {
  padding: 12px;
  border-bottom: 1px solid var(--line-soft);
}

.section:last-child {
  border-bottom: 0;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
}

.card {
  padding: 11px;
  background: var(--panel);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
}

.card + .card {
  margin-top: 8px;
}

/* ---------- Meters ---------- */

.meter {
  position: relative;
  height: 8px;
  background: #0d0e12;
  border: 1px solid var(--line-soft);
  border-radius: 99px;
  overflow: hidden;
}

.meter-fill {
  width: 100%;
  height: 100%;
  border-radius: 99px;
  transition: width 200ms linear, background 300ms;
}

.meter-fill.hp { background: linear-gradient(90deg, #5f8f4a, var(--good)); }
.meter-fill.hp.hurt { background: linear-gradient(90deg, #b08020, var(--warn)); }
.meter-fill.hp.critical { background: linear-gradient(90deg, #a02a1e, var(--danger)); }

/* ---------- Chips / tags ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 650;
  border-radius: 99px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text-dim);
  white-space: nowrap;
}

.chip.melee { color: #f0a97a; border-color: #5a3a24; }
.chip.ranged { color: #a8cf92; border-color: #3a4d2e; }
.chip.armor { color: #9cc4e8; border-color: #2c4256; }
.chip.danger { color: #f2a79c; border-color: #6b2b24; background: #23120f; }
.chip.boss {
  color: #ffd98a;
  border-color: #7a5410;
  background: #241a06;
}

/* ---------- Scrollbars (desktop nicety, harmless elsewhere) ---------- */

.scroll {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
  -webkit-overflow-scrolling: touch;
}

.scroll::-webkit-scrollbar {
  width: 9px;
}

.scroll::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 99px;
  border: 2px solid var(--panel);
}

.scroll::-webkit-scrollbar-track {
  background: transparent;
}
