:root {
  --bg: #2b1d14;
  --card: #3d2a1d;
  --line: #5a3f2b;
  --ink: #fff4e0;
  --muted: #c9a989;
  --accent: #ffb703;
  --accent-ink: #2b1d14;
  --good: #8bc34a;
  --bad: #e76f51;
  --edge: #1a110b;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: "Rubik", system-ui, sans-serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#stage { position: fixed; inset: 0; }
#stage canvas { display: block; }

.hidden { display: none !important; }

/* ---------- кнопки ---------- */
.btn {
  font: inherit;
  font-weight: 600;
  border: 3px solid var(--edge);
  border-radius: 12px;
  padding: 12px 20px;
  cursor: pointer;
  background: var(--line);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--edge);
  transition: transform .05s;
  text-decoration: none;
  display: inline-block;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--edge); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.wide { width: 100%; }

/* ---------- HUD ---------- */
.hud-top {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  right: 64px;
  display: flex;
  gap: 8px;
  justify-content: space-between;
  align-items: flex-start;
  pointer-events: none;
}
.pill {
  background: rgba(43, 29, 20, .88);
  border: 3px solid var(--edge);
  border-radius: 999px;
  padding: 6px 14px;
  box-shadow: 0 3px 0 var(--edge);
  pointer-events: auto;
}
.seeds-pill {
  font-family: "Press Start 2P", monospace;
  font-size: 15px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.seeds-pill.bump { animation: bump .35s; }
@keyframes bump { 50% { transform: scale(1.15); } }
.wallet-pill { font-size: 12px; color: var(--muted); }
.hud-left { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.danger-pill {
  font: 600 13px "Rubik", system-ui, sans-serif;
  color: #ffd6cc;
  border-color: #7a2b1d;
  background: rgba(90, 30, 20, .9);
  cursor: pointer;
  animation: pulse 1.6s infinite;
}
@keyframes pulse { 50% { box-shadow: 0 3px 0 var(--edge), 0 0 0 4px rgba(231, 111, 81, .35); } }
.seed-ico { font-family: system-ui, sans-serif; }

.collect {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  font-size: 17px;
  padding: 14px 26px;
  white-space: nowrap;
}
.collect:active { transform: translateX(-50%) translateY(3px); }

.map-ctrl {
  position: fixed;
  right: 12px;
  top: calc(12px + env(safe-area-inset-top));
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 12; /* поверх экрана входа, чтобы язык можно было сменить до входа */
}
.ctrl {
  width: 42px;
  height: 42px;
  font: 700 20px/1 "Rubik", system-ui, sans-serif;
  color: var(--ink);
  background: rgba(43, 29, 20, .88);
  border: 3px solid var(--edge);
  border-radius: 10px;
  box-shadow: 0 3px 0 var(--edge);
  cursor: pointer;
}
.ctrl:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--edge); }
.ctrl.off { color: var(--muted); opacity: .75; }
.ctrl.lang { font: 700 13px/1 "Rubik", system-ui, sans-serif; letter-spacing: .04em; }

/* ---------- вход ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(20, 13, 8, .45);
  z-index: 10;
}
.card {
  background: var(--card);
  border: 3px solid var(--line);
  border-radius: 14px;
  padding: 22px;
  box-shadow: 0 5px 0 var(--edge);
}
.login { max-width: 400px; width: 100%; text-align: center; }
.login .logo {
  font-family: "Press Start 2P", monospace;
  font-size: 14px;
  line-height: 1.6;
  color: var(--accent);
}
.login-hamster { width: 110px; margin: 12px auto 4px; display: block; image-rendering: pixelated; }
.login h1 { font-size: 20px; margin: 8px 0; }
.login p { color: var(--muted); font-size: 14px; }
.login .btn { margin-top: 6px; }
.hint { font-size: 13px; color: var(--muted); }

/* ---------- панель хомяка ---------- */
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(440px, 100%);
  transform: translate(-50%, 110%);
  transition: transform .25s ease;
  background: var(--card);
  border: 3px solid var(--edge);
  border-bottom: 0;
  border-radius: 16px 16px 0 0;
  padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
  z-index: 8;
  box-shadow: 0 -4px 0 rgba(0, 0, 0, .25);
}
.sheet.open { transform: translate(-50%, 0); }
.sheet-close {
  position: absolute;
  right: 10px;
  top: 8px;
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
}
.sheet-head { display: flex; gap: 14px; align-items: center; }
.sheet-ava { width: 64px; image-rendering: pixelated; }
.sheet-name { font-size: 20px; font-weight: 700; }
.sheet-meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.sheet-row { display: flex; justify-content: space-between; font-size: 14px; margin: 6px 0; color: var(--muted); }
.sheet-row b { color: var(--ink); }
.sheet .btn { margin-top: 10px; }

.energy {
  height: 12px;
  background: var(--edge);
  border-radius: 6px;
  overflow: hidden;
  margin: 14px 0 8px;
}
.energy > div { height: 100%; background: var(--good); transition: width .3s; }
.energy > div.low { background: var(--bad); }

/* ---------- уведомление ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--accent-ink);
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 600;
  transition: transform .25s, opacity .25s;
  max-width: calc(100% - 32px);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

.burrow-ava { width: 80px; }

/* ---------- набег Кита ---------- */
.whale {
  position: fixed;
  top: 18%;
  left: 100%;
  width: min(260px, 60vw);
  image-rendering: pixelated;
  z-index: 15;
  pointer-events: none;
  display: none;
}
.whale.fly { display: block; animation: whale-fly 2.6s ease-in-out forwards; }
@keyframes whale-fly {
  0%   { transform: translate(0, 0) rotate(-4deg); }
  25%  { transform: translate(calc(-35vw - 130px), 30px) rotate(3deg); }
  50%  { transform: translate(calc(-60vw - 130px), -10px) rotate(-3deg); }
  75%  { transform: translate(calc(-85vw - 130px), 25px) rotate(3deg); }
  100% { transform: translate(calc(-100vw - 300px), 0) rotate(-4deg); }
}
.raid-card { max-width: 360px; width: 100%; text-align: center; }
.raid-whale { width: 150px; image-rendering: pixelated; }
.raid-card h2 { margin: 6px 0; font-size: 20px; }
.raid-card p { color: var(--muted); font-size: 15px; }

/* широкий экран: кнопка сбора в правом нижнем углу, чтобы не закрывать нору */
@media (min-width: 700px) and (min-aspect-ratio: 11/10) {
  .collect { left: auto; right: 16px; transform: none; }
  .collect:active { transform: translateY(3px); }
  .toast { bottom: 24px; }
}

/* ---------- прокачка и профессии ---------- */
.sheet { max-height: min(86vh, 760px); overflow-y: auto; overscroll-behavior: contain; z-index: 14; } /* выше кнопок карты */
#raid { z-index: 16; }
.sheet-sub {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 2px solid var(--line);
  font-weight: 600;
  font-size: 15px;
}
.sheet-sub b { color: var(--accent); }
.jobs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.job {
  font: inherit;
  text-align: left;
  color: var(--ink);
  background: var(--bg);
  border: 3px solid var(--edge);
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 8px;
  align-items: center;
}
.job .ico { font-size: 22px; grid-row: span 2; }
.job .name { font-weight: 600; font-size: 14px; }
.job .mult { font-family: "Press Start 2P", monospace; font-size: 11px; color: var(--muted); }
.job .mult.up { color: var(--good); }
.job .mult.down { color: var(--bad); }
.job.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.job:disabled { cursor: default; }
.job:not(.on):disabled { opacity: .55; }

.market-pill {
  font: 600 12px "Rubik", system-ui, sans-serif;
  color: var(--ink);
  display: flex;
  gap: 10px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.mk.up { color: #b5e48c; }
.mk.down { color: #ffb4a2; }
.market-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.market-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--bg);
  border: 2px solid var(--edge);
  border-radius: 10px;
  padding: 8px 10px;
  font-variant-numeric: tabular-nums;
}
.market-row .ico { font-size: 22px; }
.market-row .what { font-size: 13px; color: var(--muted); }
.market-row .what b { color: var(--ink); font-size: 14px; display: block; }
.market-row .val { text-align: right; font-size: 13px; }
.market-row .val b { display: block; font-family: "Press Start 2P", monospace; font-size: 12px; }
.up { color: var(--good); }
.down { color: var(--bad); }

/* верхние плашки не переносятся на узком экране */
.mk, .wallet-pill, .seeds-pill, .danger-pill { white-space: nowrap; }
.wallet-pill { flex-shrink: 0; }
.hud-left { min-width: 0; }
@media (max-width: 420px) {
  .market-pill { gap: 8px; padding: 6px 10px; }
  .wallet-pill { font-size: 11px; padding: 6px 10px; }
}
