:root {
  --bg: #0b0d1a;
  --panel: rgba(17, 20, 42, 0.84);
  --line: rgba(255, 255, 255, 0.13);
  --text: #eef2ff;
  --muted: #a5b4fc;
  --accent: #38bdf8;
  --good: #4ade80;
  --bad: #f87171;
  --warn: #fbbf24;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Fredoka', system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button { pointer-events: auto; }

#res {
  position: absolute;
  top: calc(10px + var(--st));
  left: calc(10px + var(--sl));
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: calc(100% - 200px);
}
.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px 5px 8px;
  font-weight: 600;
  font-size: 17px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.pill .ic { font-size: 18px; }
.pill small { font-size: 12px; font-weight: 500; color: var(--muted); }
.pill small.pos { color: var(--good); }
.pill small.neg { color: var(--bad); }
.pill.bump { animation: bump .35s ease-out; }
@keyframes bump { 40% { transform: scale(1.12); } }
.o2 .bar { width: 90px; height: 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.o2 .bar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #38bdf8, #67e8f9); border-radius: 6px; transition: width .2s; }
.o2 b { font-size: 14px; min-width: 58px; }
.o2.low .bar i { background: linear-gradient(90deg, #ef4444, #f97316); }
.o2.low { animation: blink 1s infinite; }
@keyframes blink { 50% { border-color: var(--bad); box-shadow: 0 0 14px rgba(248, 113, 113, 0.65); } }

#topbtns {
  position: absolute;
  top: calc(10px + var(--st));
  right: calc(10px + var(--sr));
  display: flex;
  gap: 6px;
}
.round {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.round:hover { border-color: var(--accent); }

#goals {
  position: absolute;
  top: calc(60px + var(--st));
  right: calc(10px + var(--sr));
  width: 236px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
}
body.goals-open #goals { display: block; }
#goals h3 { font-size: 15px; margin-bottom: 6px; color: var(--accent); }
#goals li { list-style: none; font-size: 14px; padding: 2px 0; display: flex; gap: 6px; align-items: baseline; }
#goals li::before { content: '○'; color: var(--muted); width: 12px; flex: none; }
#goals li.done { color: var(--good); opacity: .8; }
#goals li.done::before { content: '✔'; color: var(--good); }
#goals li.opt { color: var(--muted); font-size: 13px; }
#goals li.sep { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }

#hint {
  position: absolute;
  left: 50%;
  bottom: calc(18px + var(--sb));
  transform: translateX(-50%);
  width: max-content;
  max-width: min(560px, calc(100% - 380px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 9px 16px;
  font-size: 16px;
  text-align: center;
  line-height: 1.3;
}
#hint:empty { display: none; }
#hint.warn { border-color: var(--bad); color: #fecaca; }
#hint.good { border-color: var(--good); color: #bbf7d0; }

#toasts {
  position: absolute;
  left: 50%;
  bottom: calc(80px + var(--sb));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(520px, 92%);
}
.toast {
  background: rgba(15, 18, 36, 0.94);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 7px 14px;
  font-size: 15px;
  text-align: center;
  animation: tin .25s ease-out;
  transition: opacity .4s;
}
.toast.err { border-color: var(--bad); color: #fecaca; }
.toast.ok { border-color: var(--good); color: #bbf7d0; }
.toast.out { opacity: 0; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

#actions {
  position: absolute;
  right: calc(12px + var(--sr));
  bottom: calc(14px + var(--sb));
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.act {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 78px;
  padding: 8px 10px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 22px;
  font-weight: 600;
  cursor: pointer;
  position: relative;
}
.act span { font-size: 13px; }
.act kbd { position: absolute; top: 3px; right: 6px; font: 500 10px 'Fredoka', sans-serif; color: var(--muted); }
.act:hover { border-color: var(--accent); }
.act.glow { border-color: var(--good); box-shadow: 0 0 16px rgba(74, 222, 128, 0.55); }
.act.crew { opacity: .55; }
.act.crew.ready {
  opacity: 1;
  background: linear-gradient(135deg, #f97316, #ef4444);
  border-color: #fed7aa;
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 50% { transform: scale(1.07); box-shadow: 0 0 26px rgba(249, 115, 22, 0.85); } }

#buildbar {
  position: absolute;
  left: 50%;
  top: calc(64px + var(--st));
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 8px 10px 8px 14px;
  width: max-content;
  max-width: calc(100% - 20px);
}
.bb-text { display: flex; flex-direction: column; font-size: 14px; line-height: 1.25; }
.bb-text b { font-size: 15px; }
#bb-reason { color: var(--good); }
#bb-reason.bad { color: var(--bad); }
#buildbar button { pointer-events: auto; border: none; border-radius: 10px; padding: 9px 14px; font-weight: 600; font-size: 15px; cursor: pointer; }
#bb-ok { background: var(--good); color: #052e16; }
#bb-ok:disabled { opacity: .4; }
#bb-cancel { background: rgba(255, 255, 255, 0.12); color: var(--text); }

/* ---------- Dotyk ---------- */
.touch-only { display: none !important; }
body.touch .touch-only { display: flex !important; }
body.touch .act kbd { display: none; }
#b-drill {
  position: absolute;
  right: calc(16px + var(--sr));
  bottom: calc(18px + var(--sb));
  width: 96px; height: 96px;
  border-radius: 50%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  background: radial-gradient(circle at 35% 30%, #60a5fa, #1d4ed8);
  border: 3px solid rgba(255, 255, 255, 0.5);
  color: #fff;
  touch-action: none;
}
#b-drill span { font-size: 14px; font-weight: 600; }
#b-drill.on { transform: scale(.93); filter: brightness(1.25); }
#stick {
  position: absolute;
  left: calc(28px + var(--sl));
  bottom: calc(28px + var(--sb));
  width: 124px; height: 124px;
  margin: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.06);
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
#stick i { width: 52px; height: 52px; border-radius: 50%; background: rgba(255, 255, 255, 0.35); display: block; }
#stick.active { border-color: rgba(255, 255, 255, 0.45); }
body.touch #actions { bottom: calc(130px + var(--sb)); flex-direction: column; align-items: flex-end; }
body.touch .act { min-width: 70px; padding: 7px 8px; font-size: 20px; }
body.touch #hint { bottom: auto; top: calc(62px + var(--st)); max-width: calc(100% - 20px); font-size: 15px; }
body.touch #toasts { bottom: calc(165px + var(--sb)); }
body.touch #buildbar { top: auto; bottom: calc(20px + var(--sb)); }
body.building #b-drill, body.building #stick, body.building #actions { display: none !important; }

/* ---------- Nakładki ---------- */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 6, 15, 0.62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: calc(16px + var(--st)) 16px calc(16px + var(--sb));
  z-index: 10;
}
.overlay.menu { background: rgba(5, 6, 15, 0.35); }
.card {
  background: linear-gradient(160deg, rgba(28, 33, 70, 0.96), rgba(15, 17, 38, 0.96));
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 24px;
  max-width: 460px;
  width: 100%;
  text-align: center;
  max-height: 100%;
  overflow: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.card.small { max-width: 360px; }
.card, .sheet { touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.card h1 {
  font-size: 34px;
  line-height: 1.1;
  margin: 4px 0 8px;
  background: linear-gradient(90deg, #e0e7ff, #7dd3fc, #fbbf24);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.card h2 { font-size: 26px; margin-bottom: 10px; }
.logo { font-size: 52px; line-height: 1; }
.sub { color: #c7d2fe; font-size: 16px; line-height: 1.35; margin-bottom: 12px; }
.label { color: var(--muted); font-size: 14px; margin: 6px 0; }
.colors { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.25); }
.swatch.sel { border-color: #fff; transform: scale(1.12); }
.btns { display: flex; flex-direction: column; gap: 8px; margin-top: 6px; }
.btns.row { flex-direction: row; }
.btns.row > * { flex: 1; }
.big {
  font-size: 20px;
  font-weight: 600;
  padding: 12px 22px;
  border-radius: 14px;
  border: none;
  background: linear-gradient(135deg, #38bdf8, #6366f1);
  color: #fff;
  cursor: pointer;
}
.big:hover { filter: brightness(1.1); }
.big.danger { background: linear-gradient(135deg, #f97316, #ef4444); }
.ghost, .as-btn {
  font-size: 16px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: block;
}
.ghost:hover { border-color: var(--accent); }
.help { text-align: left; font-size: 15px; line-height: 1.45; margin: 12px 0 4px; color: #dbe3ff; }
.help li { list-style: none; margin-bottom: 5px; }
.best { color: var(--warn); font-size: 15px; margin-top: 12px; min-height: 1em; }
.back { display: inline-block; margin-top: 10px; color: var(--muted); text-decoration: none; font-size: 14px; }
.stars { font-size: 40px; letter-spacing: 4px; margin: 6px 0; }
.wtime { font-size: 20px; font-weight: 600; }

.sheet {
  background: linear-gradient(160deg, rgba(28, 33, 70, 0.97), rgba(15, 17, 38, 0.97));
  border: 1px solid var(--line);
  border-radius: 22px;
  max-width: 780px;
  width: 100%;
  max-height: 100%;
  overflow: auto;
  padding: 16px;
}
.sheet header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.sheet h2 { font-size: 22px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.bcard {
  position: relative;
  text-align: left;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.bcard:hover { border-color: var(--accent); background: rgba(56, 189, 248, 0.08); }
.bcard .bi { font-size: 32px; line-height: 1.1; }
.bcard h4 { font-size: 16px; }
.bcard .cost { font-weight: 600; color: var(--warn); font-size: 14px; }
.bcard p { font-size: 13px; color: #c7d2fe; line-height: 1.3; margin-top: 2px; }
.bcard .st { font-size: 12.5px; margin-top: 4px; color: var(--good); }
.bcard .st.bad { color: var(--bad); }
.bcard.no { opacity: .6; }
.bcard .tag { font-size: 11px; background: var(--accent); color: #082f49; border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: 2px; }
.bcard kbd { position: absolute; top: 6px; right: 9px; font: 500 11px 'Fredoka', sans-serif; color: var(--muted); }
body.touch .bcard kbd { display: none; }

/* ---------- Telefon ---------- */
@media (max-width: 760px) {
  #res { max-width: calc(100% - 20px); gap: 5px; }
  .pill { font-size: 15px; padding: 4px 10px 4px 7px; }
  .pill .ic { font-size: 15px; }
  .pill small { display: none; }
  .o2 .bar { width: 64px; }
  #hint, body.touch #hint { top: calc(92px + var(--st)); bottom: auto; max-width: calc(100% - 20px); font-size: 15px; }
  #topbtns, body.touch #topbtns { top: calc(172px + var(--st)); bottom: auto; right: calc(10px + var(--sr)); left: auto; flex-direction: column; }
  #goals, body.touch #goals { top: calc(172px + var(--st)); bottom: auto; right: calc(58px + var(--sr)); left: auto; width: min(260px, calc(100% - 80px)); }
  #toasts, body.touch #toasts { left: calc(10px + var(--sl)); transform: none; align-items: flex-start; width: calc(100% - 120px); bottom: calc(160px + var(--sb)); }
  .toast { text-align: left; font-size: 14px; }
  .card h1 { font-size: 28px; }
  .card { padding: 18px; }
}
