/* In-game screen: map canvas, top bar, side/bottom panel, toasts and end screens. */

#game-screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  --panel-w: clamp(212px, 28vw, 300px);
}
#game-screen.landscape {
  grid-template-columns: minmax(0, 1fr) var(--panel-w);
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top panel" "stage panel";
}
#game-screen.portrait {
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "top" "stage" "panel";
}

/* ---------- Top bar ---------- */
.gs-top {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 4px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-left: max(10px, env(safe-area-inset-left));
  min-width: 0;
}
.portrait .gs-top { padding-right: max(10px, env(safe-area-inset-right)); }
.gs-menu-btn { flex: none; }
.gs-burger { display: flex; flex-direction: column; gap: 3px; }
.gs-burger i { display: block; width: 16px; height: 2.5px; border-radius: 2px; background: #fff; }
.gs-title { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; }
.gs-title-main { display: flex; align-items: center; gap: 6px; min-width: 0; }
.gs-title-text {
  font-size: 17px;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.gs-diff-dot { flex: none; width: 9px; height: 9px; border-radius: 50%; box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.3); }
.gs-weather {
  align-self: flex-start;
  max-width: 100%;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}
.gs-weather:hover { color: #fff; }
.gs-pills { display: flex; gap: 6px; flex: none; }
.gs-pill { font-size: 15px; padding: 5px 10px; }
.gs-heart { color: #FF5A6A; }
.gs-flag { color: #BFD8FF; }
.gs-pill.low { background: rgba(229, 72, 77, 0.55); animation: lowpulse 1s ease-in-out infinite; }
@keyframes lowpulse { 50% { background: rgba(229, 72, 77, 0.25); } }

/* ---------- Map ---------- */
.gs-stage {
  grid-area: stage;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.gs-world {
  display: block;
  border-radius: 12px;
  box-shadow: 0 6px 26px rgba(0, 0, 0, 0.5);
  touch-action: none;
}

.gs-toast {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translate(-50%, -10px);
  opacity: 0;
  width: max-content;
  max-width: min(92%, 480px);
  padding: 9px 15px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.78);
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  white-space: pre-line;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.gs-toast.show { opacity: 1; transform: translate(-50%, 0); }

.gs-paused {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
}

/* ---------- Panel ---------- */
.gs-panel {
  grid-area: panel;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  min-width: 0;
  padding: 10px;
  background: rgba(8, 12, 26, 0.74);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.landscape .gs-panel {
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: max(10px, env(safe-area-inset-top));
  padding-right: max(10px, env(safe-area-inset-right));
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}
.portrait .gs-panel {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px 20px 0 0;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  padding-left: max(10px, env(safe-area-inset-left));
  padding-right: max(10px, env(safe-area-inset-right));
}
.gs-sel { flex: 1 1 auto; min-height: 0; }
.portrait .gs-sel { flex: none; height: 158px; }

.gs-controls { flex: none; display: flex; flex-direction: column; gap: 8px; }
.portrait .gs-controls { flex-direction: row; align-items: stretch; }
.gs-chips { display: flex; gap: 6px; }
.landscape .gs-chips > * { flex: 1 1 0; min-width: 0; padding: 0 4px; }
.gs-speed, .gs-pause { font-variant-numeric: tabular-nums; }
.gs-wave { height: 48px; padding: 0 12px; font-size: 17px; gap: 8px; white-space: nowrap; }
.portrait .gs-wave { flex: 1 1 auto; width: auto; min-width: 0; height: 44px; font-size: 15px; }
.gs-wave:disabled { opacity: 0.5; filter: saturate(0.4); box-shadow: none; }
.gs-wave:disabled:active { transform: none; }
.gs-wave-bonus {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--gold);
  font-size: 13px;
}

.gs-blast { position: relative; }
.gs-blast-ic { font-size: 18px; }
.gs-blast-bar {
  position: absolute;
  left: 7px;
  right: 7px;
  bottom: 5px;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
}
.gs-blast-bar i { display: block; height: 100%; background: var(--gold); }
.gs-blast.charging .gs-blast-ic { opacity: 0.5; }
.gs-blast.ready { background: #E8792F; animation: blastpulse 0.9s ease-in-out infinite; }
@keyframes blastpulse { 50% { background: #B4541A; } }
.gs-blast-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--red);
  font-size: 11px;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Idle hint ---------- */
.gs-idle { display: flex; flex-direction: column; justify-content: center; gap: 8px; min-height: 100%; }
.gs-idle p { margin: 0; font-size: 14px; font-weight: 600; line-height: 1.35; color: var(--text-dim); text-align: center; }
.gs-idle .gs-keys { font-size: 11.5px; color: var(--text-faint); }

/* ---------- Build menu ---------- */
.gs-sel-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; }
.gs-sel-title { font-size: 14px; font-weight: 800; color: var(--text-dim); }
.gs-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(76px, 1fr));
  gap: 6px;
}
.portrait .gs-cards {
  display: flex;
  overflow-x: auto;
  padding-bottom: 4px;
  touch-action: pan-x;
  -webkit-overflow-scrolling: touch;
}
.portrait .gs-card { flex: 0 0 80px; }
.gs-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: 7px 4px 6px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--card-stroke);
  transition: transform 0.1s, background 0.1s, opacity 0.15s;
}
button.gs-card:hover { background: rgba(255, 255, 255, 0.14); }
button.gs-card:active { transform: scale(0.95); }
.gs-card.poor { opacity: 0.42; }
.gs-card-icon { width: 40px; height: 40px; }
.gs-card-name {
  max-width: 100%;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.gs-card-cost { display: flex; align-items: center; gap: 3px; font-size: 13px; font-weight: 900; color: var(--gold); }
.gs-card.locked { opacity: 0.55; }
.gs-card.locked .gs-card-icon { filter: grayscale(1) brightness(0.6); }
.gs-card-lock { font-size: 10px; font-weight: 700; color: var(--text-dim); white-space: nowrap; }
.gs-rope {
  position: absolute;
  top: 3px;
  right: 3px;
  padding: 1px 4px;
  border-radius: 6px;
  background: var(--rope);
  color: #3A2A10;
  font-size: 9.5px;
  font-weight: 900;
}
.gs-key { position: absolute; top: 3px; left: 6px; font-size: 10px; font-weight: 800; color: var(--text-faint); }

/* ---------- Tower and obstacle panels ---------- */
.gs-tower, .gs-obstacle { display: flex; flex-direction: column; gap: 8px; }
.portrait .gs-tower, .portrait .gs-obstacle { display: grid; grid-template-columns: minmax(0, 1fr) 138px; gap: 10px; }
.gs-tw-head { display: flex; align-items: center; gap: 10px; }
.gs-tw-icon { display: flex; flex-direction: column; align-items: center; gap: 4px; flex: none; }
.gs-tw-icon img { width: 44px; height: 44px; }
.gs-tw-icon .pips { display: flex; gap: 2px; }
.gs-tw-icon .pips i { display: block; width: 6px; height: 6px; border-radius: 50%; background: rgba(255, 255, 255, 0.2); }
.gs-tw-icon .pips i.on { background: var(--star); }
.gs-tw-title { min-width: 0; }
.gs-tw-name { font-size: 16px; font-weight: 900; line-height: 1.15; }
.gs-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.gs-badge {
  padding: 2px 6px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-dim);
  font-size: 10.5px;
  font-weight: 800;
  white-space: nowrap;
}
.gs-badge.mountain { background: rgba(150, 190, 110, 0.28); color: #DDF3BE; }
.gs-stats { display: flex; flex-direction: column; gap: 2px; margin-top: 8px; font-size: 13px; }
.gs-stat { display: flex; justify-content: space-between; gap: 8px; }
.gs-stat-l { color: var(--text-dim); white-space: nowrap; }
.gs-stat-v { font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.gs-stat-n { color: #7FE08A; }
.gs-tw-meta { display: flex; justify-content: space-between; gap: 6px; margin-top: 6px; font-size: 12px; color: var(--text-faint); }
.gs-rope-text { color: var(--rope); font-weight: 800; }
.gs-tw-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; align-content: start; }
.gs-tw-buttons .gs-up, .gs-tw-buttons .gs-mark { grid-column: 1 / -1; height: 38px; font-size: 14px; }
.portrait .gs-tw-buttons { grid-template-columns: 1fr; }
.gs-tgt { --btn: rgba(255, 255, 255, 0.14); }
.gs-sell { --btn: #A8463A; }
.gs-ob-reward { display: flex; align-items: center; gap: 3px; margin-top: 3px; font-size: 13px; font-weight: 900; color: var(--gold); }
.gs-hp { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.gs-hpbar { flex: 1; height: 8px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.gs-hpbar i { display: block; height: 100%; background: var(--star); }
.gs-hptext { font-size: 12px; font-weight: 800; color: var(--text-dim); font-variant-numeric: tabular-nums; white-space: nowrap; }
.gs-explain { margin: 8px 0 0; font-size: 12px; line-height: 1.35; color: var(--text-faint); }

/* ---------- Overlays ---------- */
.gs-overlays { position: absolute; inset: 0; z-index: 40; pointer-events: none; }
.gs-overlays > * { pointer-events: auto; }
.gs-dim { color: var(--text-dim); font-weight: 600; }
.gs-toggle-row { display: flex; gap: 8px; }
.gs-toggle { height: 38px; font-size: 14px; }
.gs-end .overlay-card { max-width: 400px; }
.gs-end-stars { display: flex; gap: 6px; font-size: 46px; line-height: 1; }
.gs-end-stars span { display: inline-block; animation: starpop 0.45s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes starpop { from { transform: scale(0) rotate(-40deg); opacity: 0; } to { transform: none; opacity: 1; } }
.gs-crystals { display: flex; align-items: center; gap: 6px; font-size: 24px; font-weight: 900; color: var(--crystal); }
.gs-newtowers { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.gs-newtowers-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; }
.gs-newtower { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; font-weight: 800; }
.gs-record { font-size: 17px; font-weight: 800; color: var(--star); }
.gs-tip {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.35;
  text-align: left;
}
.gs-btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; }
.gs-btn-row.single { grid-template-columns: 1fr; }
.gs-btn-row .btn-menu { min-width: 0; padding-left: 10px; padding-right: 10px; }
.gs-reward { --btn: var(--purple); gap: 6px; }
.gs-reward:disabled { opacity: 0.6; }
.gs-reward-ic { font-size: 18px; }
.gs-reward-note {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.07);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  text-align: center;
}
.gs-reward-note.ok { color: var(--crystal); }

/* ---------- Small screens (Poki 640×360, phones in landscape) ---------- */
.compact .gs-top { padding-top: max(5px, env(safe-area-inset-top)); padding-bottom: 2px; gap: 6px; }
.compact .gs-menu-btn { width: 32px; height: 32px; }
.compact .gs-title-text { font-size: 14px; }
.compact .gs-weather { font-size: 11px; }
.compact .gs-pill { font-size: 13px; padding: 4px 8px; }
.compact .gs-pills { gap: 4px; }
.compact.landscape .gs-panel { padding: 7px; gap: 6px; }
.compact .btn-chip { height: 34px; min-width: 34px; font-size: 13px; border-radius: 10px; }
.compact .gs-wave { height: 38px; font-size: 14px; }
.compact.landscape .gs-cards { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 5px; }
.compact .gs-card { padding: 5px 3px 4px; border-radius: 10px; }
.compact .gs-card-icon { width: 32px; height: 32px; }
.compact .gs-card-name { font-size: 9.5px; }
.compact .gs-card-cost { font-size: 12px; }
.compact .gs-tw-name { font-size: 14px; }
.compact .gs-stats { font-size: 12px; margin-top: 5px; }
.compact .gs-tw-buttons .gs-up, .compact .gs-tw-buttons .gs-mark { height: 32px; font-size: 13px; }
.compact .btn-panel { height: 28px; font-size: 12px; }
.compact .gs-explain { font-size: 11px; }
.compact .gs-idle p { font-size: 12.5px; }
.compact .gs-toast { font-size: 12.5px; padding: 7px 12px; }
.compact .overlay { padding: 8px; }
.compact .overlay-card { padding: 16px; gap: 10px; border-radius: 20px; }
.compact .overlay-card h1 { font-size: 24px; }
.compact .gs-end-stars { font-size: 34px; }
.compact .btn-menu { padding: 10px 14px; font-size: 16px; border-radius: 14px; }
.compact .btn-menu.small { padding: 8px 12px; font-size: 14px; }
.compact .gs-tip { font-size: 12.5px; padding: 8px 10px; }
.compact.portrait .gs-sel { height: 150px; }
@media (max-width: 360px) {
  .portrait .gs-pill { font-size: 12px; padding: 4px 7px; }
  .portrait .gs-title-text { font-size: 13px; }
}
