:root {
  --bg: #0f172a;
  --panel: rgba(15, 23, 42, 0.92);
  --line: rgba(148, 163, 184, 0.25);
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #22d3ee;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

canvas#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
  display: block;
}

.hidden { display: none !important; }

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
}

.btn {
  background: #1e293b;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 42px;
  font-weight: 600;
}
.btn:hover { background: #273449; }
.btn.primary { background: #0891b2; border-color: #22d3ee; color: #fff; }
.btn.primary:hover { background: #0e7490; }
.btn.go { background: #15803d; border-color: #22c55e; color: #fff; }
.btn.danger { background: #7f1d1d; border-color: #ef4444; }
.btn:disabled { opacity: 0.45; cursor: default; }

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #1e293b;
  border: 1px solid var(--line);
  font-weight: 700;
  flex: none;
}

/* ---------------------------------------------------------------- HUD */
#hud {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(6px + var(--safe-t)) calc(8px + var(--safe-r)) 6px calc(8px + var(--safe-l));
  background: linear-gradient(var(--panel), rgba(15, 23, 42, 0.8));
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.hud-top {
  display: flex;
  align-items: center;
  gap: 10px;
}
.hud-name {
  font-weight: 700;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hud-stat { display: flex; flex-direction: column; line-height: 1.1; font-weight: 700; }
.hud-stat .lbl { font-size: 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.hud-stat .bar { width: 80px; height: 8px; border-radius: 4px; background: #334155; margin-top: 3px; overflow: hidden; }
#hud-rating { height: 100%; width: 100%; background: var(--good); transition: width 0.3s, background 0.3s; }

#strip {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  margin-top: 6px;
  min-height: 40px;
  scrollbar-width: none;
}
#strip::-webkit-scrollbar { display: none; }
#strip .empty { color: var(--muted); font-size: 12px; align-self: center; }
.chip {
  flex: none;
  background: #1e293b;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 8px;
  text-align: left;
  min-width: 92px;
}
.chip.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.chip.cleared { border-color: var(--good); }
.chip .cs { font-weight: 700; font-size: 12px; display: flex; justify-content: space-between; gap: 6px; }
.chip .sz { color: var(--muted); font-weight: 600; }
.chip .fuel { height: 4px; background: #334155; border-radius: 2px; margin-top: 4px; overflow: hidden; }
.chip .fuel > div { height: 100%; background: var(--good); }
.chip.low { animation: blink 0.8s infinite alternate; }
@keyframes blink { to { border-color: var(--bad); } }

/* -------------------------------------------------------------- Panel */
#panel {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--panel);
  border-top: 1px solid var(--line);
  padding: 8px calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l));
  z-index: 5;
  min-height: 64px;
}
.panel-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
#panel-title { font-weight: 800; font-size: 15px; }
#panel-status { color: var(--muted); font-size: 13px; }
#panel-info { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
#panel-info .dots { display: inline-flex; gap: 2px; flex-wrap: wrap; max-width: 220px; }
#panel-info .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
#panel-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
#panel-actions::-webkit-scrollbar { display: none; }
#panel-actions .btn { flex: none; padding: 8px 12px; min-height: 40px; }
#panel-actions .btn small { display: block; font-size: 10px; font-weight: 600; opacity: 0.8; }

/* ------------------------------------------------------------- Toasts */
#toasts {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: calc(100px + var(--safe-t));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
  z-index: 6;
  width: min(92vw, 460px);
}
.toast {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  transition: opacity 0.4s;
  max-width: 100%;
}
.toast.good { border-left-color: var(--good); }
.toast.warn { border-left-color: var(--warn); }
.toast.bad { border-left-color: var(--bad); }
.toast.arrive { border-left-color: #a78bfa; }

/* ------------------------------------------------------------ Screens */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: radial-gradient(circle at 30% 20%, rgba(14, 116, 144, 0.35), transparent 60%), rgba(2, 6, 23, 0.86);
  overflow-y: auto;
}
#menu { background: radial-gradient(circle at 30% 10%, #164e63, #0f172a 60%); align-items: flex-start; }
.menu-inner { width: min(760px, 100%); margin: auto; }
.logo { display: flex; align-items: center; gap: 12px; }
.logo h1 { margin: 0; font-size: 34px; letter-spacing: -0.02em; }
.logo .tag { margin: 0; color: var(--accent); font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; font-size: 12px; }
.intro { color: #cbd5e1; max-width: 60ch; }
#levels {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.level {
  text-align: left;
  background: rgba(30, 41, 59, 0.85);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.level:hover:not(:disabled) { border-color: var(--accent); }
.level .top { display: flex; justify-content: space-between; align-items: center; }
.level .nm { font-weight: 800; font-size: 16px; }
.level .diff { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: #334155; }
.level .diff.Easy { background: #14532d; }
.level .diff.Medium { background: #713f12; }
.level .diff.Hard { background: #7c2d12; }
.level .diff.Expert { background: #7f1d1d; }
.level .bl { color: #cbd5e1; font-size: 13px; }
.level .facts { color: var(--muted); font-size: 12px; }
.level .stars { color: #facc15; letter-spacing: 2px; }
.level:disabled .nm::after { content: " 🔒"; }

.menu-row { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: #0f172a;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  width: min(520px, 100%);
  max-height: 100%;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
.card h2 { margin: 0 0 8px; }
.card ol { padding-left: 20px; margin: 0 0 10px; }
.card li { margin-bottom: 6px; }
.card .hint { color: var(--muted); font-size: 12px; }
#ov-stars { font-size: 34px; color: #facc15; letter-spacing: 6px; margin: 4px 0; }
#ov-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; margin: 8px 0 14px; color: #cbd5e1; font-size: 13px; }
#ov-stats b { color: #fff; }

@media (max-width: 560px) {
  .hud-stat.time { display: none; }
  .hud-stat .bar { width: 56px; }
  .hud-top { gap: 8px; }
  .logo h1 { font-size: 28px; }
}

/* ------------------------------------------------- campaign, shop, extras */
.wallet { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 6px 0 4px; }
.coins, .starcount { font-weight: 800; font-size: 16px; background: rgba(30, 41, 59, 0.85); border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px; }
.starcount { color: #facc15; }
/* cloud saves line on the menu */
.cloud { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; margin: 8px 0 4px; padding: 8px 12px; background: rgba(30, 41, 59, 0.85); border: 1px solid var(--line); border-radius: 12px; font-size: 13px; line-height: 1.35; }
.cloud .ctag { font-weight: 800; color: var(--accent); white-space: nowrap; }
.cloud .cmsg { flex: 1; min-width: 160px; color: var(--muted); }
.cloud .cacts { display: flex; gap: 6px; }
.cloud .cacts .btn { padding: 6px 12px; font-size: 13px; }
#levels { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }
.level .num { font-weight: 800; color: var(--accent); margin-right: 6px; }
.level .top .nm { flex: 1; min-width: 0; }
.level .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.level .tags span { font-size: 11px; background: #334155; border-radius: 6px; padding: 1px 6px; color: #e2e8f0; }
.level:disabled { opacity: 0.55; cursor: default; }
.level:disabled .stars { color: var(--muted); letter-spacing: 0; font-size: 12px; }
.level .diff.Insane { background: #581c87; }
.card.wide { width: min(720px, 100%); }
.shop-head { display: flex; align-items: center; justify-content: space-between; }
#shop-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 14px; }
.upgrade { display: flex; align-items: center; gap: 12px; background: #1e293b; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.upgrade .info { flex: 1; min-width: 0; }
.upgrade .nm { font-weight: 800; }
.upgrade .desc { color: var(--muted); font-size: 12px; }
.upgrade .pips { display: flex; gap: 4px; margin-top: 5px; }
.upgrade .pips span { width: 18px; height: 6px; border-radius: 3px; background: #334155; }
.upgrade .pips span.on { background: var(--good); }
.upgrade .btn { flex: none; min-width: 84px; }
.chip.mayday { border-color: var(--bad); background: #450a0a; animation: blink 0.6s infinite alternate; }
#panel-info .dot.sq { border-radius: 2px; }
.red { color: #f87171; }

/* ---------------------------------------- compact bars on phones (portrait)
   and short landscape screens: give the map as much room as possible. */
@media (max-width: 600px), (max-height: 520px) {
  #hud { padding: calc(3px + var(--safe-t)) calc(6px + var(--safe-r)) 3px calc(6px + var(--safe-l)); }
  .hud-top { gap: 7px; }
  .icon-btn { width: 30px; height: 30px; border-radius: 8px; font-size: 12px; }
  .hud-name { font-size: 13px; }
  .hud-stat { font-size: 13px; flex-direction: row; align-items: center; }
  .hud-stat .lbl { display: none; }
  .hud-stat .bar { width: 46px; height: 6px; margin-top: 0; }
  #hud-pax::before { content: "👤"; margin-right: 2px; font-size: 11px; }
  #hud-bags::before { content: "🧳"; margin-right: 2px; font-size: 11px; }
  #strip { margin-top: 3px; min-height: 0; gap: 4px; }
  #strip.none { display: none; }
  .chip { padding: 2px 6px; min-width: 70px; border-radius: 6px; }
  .chip .cs { font-size: 11px; gap: 4px; }
  .chip .fuel { height: 3px; margin-top: 2px; }

  #panel { padding: 4px calc(8px + var(--safe-r)) calc(4px + var(--safe-b)) calc(8px + var(--safe-l)); min-height: 0; }
  .panel-head { display: block; line-height: 1.25; }
  #panel-title { font-size: 13px; display: inline; margin-right: 6px; }
  #panel-status {
    font-size: 12px; display: inline;
  }
  .panel-head { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  #panel-info { font-size: 11px; margin-top: 1px; flex-wrap: nowrap; white-space: nowrap; overflow: hidden; gap: 6px; }
  #panel-info .dot { width: 6px; height: 6px; }
  #panel-actions { margin-top: 4px; gap: 4px; }
  #panel-actions .btn { padding: 4px 9px; min-height: 32px; font-size: 13px; border-radius: 8px; }
  #panel-actions .btn small { font-size: 9px; }

  #toasts { width: min(94vw, 420px); }
  .toast { font-size: 11px; padding: 3px 8px; }
}

/* Short landscape screens (phones on their side): one row for the top bar
   with the arrivals strip inline, and panel buttons beside the text. */
@media (max-height: 520px) and (orientation: landscape) {
  #hud { display: flex; align-items: center; gap: 8px; }
  .hud-top { flex: 1 1 auto; min-width: 0; }
  #hud > #strip { flex: 0 1 auto; max-width: 46%; min-width: 0; margin-top: 0; }
  .hud-name { max-width: 150px; }
  #panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 10px;
    align-items: center;
  }
  #panel .panel-head, #panel #panel-info { grid-column: 1; }
  #panel-actions { grid-column: 2; grid-row: 1 / span 2; margin-top: 0; max-width: 58vw; }
}

/* Studio credit and link back to the games page, the same on every Game Golem Studios title screen */
.logo .studio { margin: 4px 0 0; color: var(--muted); font-weight: 700; letter-spacing: .3em; text-transform: uppercase; font-size: 11px; }
.ggs-foot { text-align: center; font-size: 11px; margin-top: 12px; }
.ggs-foot a { color: var(--muted); text-underline-offset: 2px; }
