/*
 * Cowry Guard match presentation.
 *
 * Composition follows the Owner-approved Greenlands battlefield reference:
 * landscape, top HUD, wave and clock beneath it, the field with one shared
 * Cowry Safe on the left and three horizontal lanes running right, side
 * controls in an optional shallow deployment tray over the lower river.
 *
 * CGC-09: gameplay-art values are prefixed `--cg-art-` so they can never
 * collide with the official platform brand tokens.
 */

.cg-stage {
  --cg-art-hud: rgba(9, 14, 12, 0.78);
  --cg-art-hud-edge: rgba(212, 175, 55, 0.28);

  /*
   * The battlefield owns the full game viewport. HUD and controls are overlays
   * on top of it; they must never consume layout rows and shrink the field.
   */
  position: fixed; inset: 0; z-index: 50;
  display: block;
  overflow: hidden;
  background: #0c1410;
  isolation: isolate;
  overscroll-behavior: none;
  touch-action: manipulation;
}

/* ── Top HUD ───────────────────────────────────────────────────────────── */

.cg-topbar {
  position: absolute; z-index: 10; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between; gap: var(--cl-space-3);
  padding: var(--cl-space-2) var(--cl-space-4);
  padding-top: max(var(--cl-space-2), env(safe-area-inset-top));
  background: linear-gradient(180deg, rgba(9,14,12,.92), rgba(9,14,12,.58), transparent);
}
.cg-title { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
/* Owner: Class Core stays in the top-left HUD, never in the deployment launcher. */
.cg-class-core { align-self: flex-start; min-height: 44px; padding: 3px 9px; margin-bottom: 3px;
  border: 1px solid rgba(212,175,55,.28); border-radius: 18px; background: rgba(9,14,12,.75);
  color: #b9bdb6; font: 600 11px system-ui; opacity: .7; cursor: pointer; }
.cg-class-core.is-full { color: #ffe38b; border-color: #d4af37; opacity: 1;
  box-shadow: 0 0 12px rgba(212,175,55,.65), inset 0 0 5px rgba(212,175,55,.2); }
.cg-class-core[aria-pressed="true"] { outline: 2px solid #b98aff; }
.cg-class-core:disabled { cursor: default; }
.cg-class-core[hidden] { display: none; }
.cg-title-main { font-family: var(--cl-font-display); font-size: var(--cl-step-2); color: var(--cl-gold); letter-spacing: .06em; }
.cg-title-sub  { font-size: 10px; color: var(--cl-text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.cg-stats { display: flex; align-items: center; gap: var(--cl-space-2); }
.cg-stat {
  display: flex; flex-direction: column; align-items: center;
  min-width: 62px; padding: 4px var(--cl-space-3);
  background: rgba(0,0,0,.42); border: 1px solid var(--cg-art-hud-edge);
  border-radius: var(--cl-radius-sm);
}
.cg-stat-label { font-size: 9px; letter-spacing: .12em; text-transform: uppercase; color: var(--cl-text-dim); }
.cg-stat-value { font-size: var(--cl-step-2); font-variant-numeric: tabular-nums; color: var(--cl-text); }
.cg-stat-energy .cg-stat-value { color: #6fd0ff; }
.cg-stat-lives  .cg-stat-value { color: #ff7a6b; }
.cg-stat-score  .cg-stat-value { color: var(--cl-gold); }

/* ── Wave and verification band ────────────────────────────────────────── */

.cg-wavebar {
  position: absolute; z-index: 11; top: max(2px, env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%);
  display: flex; align-items: center; justify-content: center; gap: 7px;
  width: max-content; max-width: calc(100% - 32px);
  min-height: 30px; box-sizing: border-box; white-space: nowrap;
  padding: 2px 9px;
  border: 1px solid rgba(212,175,55,.18);
  border-radius: var(--cl-radius-pill);
  background: rgba(9,14,12,.76);
  backdrop-filter: blur(6px);
}
.cg-wave { display: flex; align-items: baseline; gap: var(--cl-space-3); }
.cg-wave-value { font-size: var(--cl-step-1); letter-spacing: .1em; text-transform: uppercase; color: var(--cl-text-muted); }
.cg-wave-clock { font-size: var(--cl-step-3); font-variant-numeric: tabular-nums; color: var(--cl-text); }
.cg-integrity { display: flex; align-items: center; gap: var(--cl-space-2); }
.cg-integrity-label { font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--cl-text-dim); }
.cg-integrity-value { font-size: var(--cl-step-0); color: var(--cl-status-pending); }

/* ── Field ─────────────────────────────────────────────────────────────── */

.cg-field {
  position: absolute; z-index: 0; inset: 0;
  min-height: 0; overflow: hidden; background: #070a08;
}
.cg-canvas { display: block; width: 100%; height: 100%; }

/* ── Deployment overlay: never reserves space in the battlefield ───────── */

.cg-deployment-launcher {
  position: absolute; z-index: 12;
  right: max(8px, env(safe-area-inset-right));
  bottom: max(8px, env(safe-area-inset-bottom));
  width: 48px; height: 48px; display: grid; place-items: center;
  padding: 3px; border: 1px solid rgba(212,175,55,.4); border-radius: 14px;
  background: linear-gradient(145deg, rgba(30,35,56,.9), rgba(11,13,26,.92));
  color: var(--cl-gold); cursor: pointer;
  box-shadow: 0 3px 12px rgba(0,0,0,.35), inset 0 1px rgba(255,240,181,.12);
}
.cg-deployment-launcher svg { width: 36px; height: 40px; }
.cg-deployment-launcher:focus-visible, .cg-deployment-panel button:focus-visible { outline: 2px solid var(--cl-gold); outline-offset: -2px; }
.cg-deployment-panel {
  position: absolute; z-index: 13;
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  bottom: max(4px, env(safe-area-inset-bottom));
  height: clamp(48px, 12vh, 68px); box-sizing: border-box;
  display: flex; align-items: stretch;
  /* Alpha belongs to the surface, not the text/portraits/controls. */
  background: rgba(11,13,26,.78); color: var(--cl-text);
  border: 1px solid rgba(212,175,55,.65); border-radius: 12px;
  box-shadow: 0 3px 16px rgba(0,0,0,.3);
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.cg-deployment-panel[hidden] { display: none; }
.cg-deployment-header { order: 2; flex: 0 0 44px; display: flex; align-items: stretch; border-left: 1px solid var(--cg-art-hud-edge); }
.cg-deployment-header h2, .cg-deployment-hint { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.cg-deployment-close { width: 44px; min-height: 42px; border: 0; border-radius: var(--cl-radius-sm); background: transparent; color: var(--cl-gold); font-size: 28px; cursor: pointer; }
.cg-deployment-body {
  flex: 1; min-width: 0; display: flex; align-items: stretch; gap: 8px;
  overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain;
  /* Overlay/classic scrollbars must not steal the single row's tap height. */
  padding: 3px 6px; scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.cg-deployment-body::-webkit-scrollbar { height: 0; }

.cg-lane-select { flex: 0 0 auto; display: flex; gap: 4px; padding: 0; }
.cg-lane-btn {
  background: rgba(0,0,0,.44); color: var(--cl-text-muted);
  border: 1px solid var(--cg-art-hud-edge); border-radius: var(--cl-radius-pill);
  padding: 4px 8px; min-width: 90px; cursor: pointer; font-family: inherit; font-size: 12px;
}
.cg-lane-btn.is-active { background: var(--cl-gold-gradient); color: var(--cl-text-on-gold); border-color: transparent; }

.cg-tray {
  flex: 0 0 auto; display: flex; gap: 4px; padding: 0; width: max-content;
}
.cg-guard-card {
  flex: 0 0 132px; display: grid; grid-template-columns: 36px 1fr; grid-template-rows: 1fr 1fr;
  align-items: center; gap: 0 5px; min-width: 132px; padding: 2px 5px;
  background: rgba(30,35,56,.45);
  border: 1px solid var(--cg-art-hud-edge); border-radius: var(--cl-radius-sm);
  color: var(--cl-text); cursor: pointer; font-family: inherit;
}
.cg-guard-card.is-selected { border-color: var(--cl-gold); box-shadow: 0 0 0 1px var(--cl-gold), 0 0 18px rgba(212,175,55,.28); }
.cg-guard-portrait { grid-row: 1 / 3; display: block; width: 36px; height: 36px; max-width: 100%; border-radius: var(--cl-radius-sm); background: radial-gradient(circle, rgba(212,175,55,.18), transparent); }
.cg-guard-cost { align-self: start; font-size: 11px; line-height: 1.15; font-weight: 700; color: #6fd0ff; font-variant-numeric: tabular-nums; white-space: nowrap; }
.cg-guard-name { align-self: end; font-size: 11px; line-height: 1.15; color: var(--cl-text); text-align: left; }

.cg-side-controls {
  flex: 0 0 auto; display: flex; gap: 4px; padding: 0;
}
.cg-side-controls .cl-btn {
  min-height: 0; padding: 0 10px; font-size: 11px; white-space: nowrap;
  background: rgba(11,13,26,.3);
}

.cg-action-feedback {
  position: absolute; z-index: 30; left: 50%; bottom: 132px;
  transform: translateX(-50%);
  max-width: min(560px, calc(100% - 32px));
  padding: 9px 14px;
  border: 1px solid rgba(255,122,107,.62);
  border-radius: var(--cl-radius-pill);
  background: rgba(11,13,26,.92);
  color: #fff;
  font-size: var(--cl-step-0);
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  backdrop-filter: blur(8px);
}
.cg-action-feedback[hidden] { display: none; }

.cg-settings { border: 1px solid var(--cl-hairline); border-radius: var(--cl-radius); background: var(--cl-surface-1-solid); color: var(--cl-text); padding: var(--cl-space-5); }
.cg-settings::backdrop { background: rgba(11,13,26,.76); }

/* ── Orientation gate (ADR-008) ────────────────────────────────────────── */

/*
 * ADR-008 landscape enforcement.
 *
 * A blocking gate, not a banner: fixed to the viewport rather than the stage
 * so nothing scrolls out from under it, opaque, and with no dismiss control
 * to find. The play area behind it is also made inert from script, so this
 * is defence in depth rather than a curtain over live controls.
 */
.cg-orientation {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: var(--cl-navy, #0B0D1A); text-align: center; padding: var(--cl-space-5);
  touch-action: none; overscroll-behavior: contain;
}
.cg-orientation[hidden] { display: none; }

/*
 * Advisory: portrait, but the server is NOT holding the run.
 *
 * The match is still advancing and still scoring the player, so the overlay
 * must stop covering the field. It becomes a banner pinned to the top — still
 * asking for landscape, no longer standing between the player and their own
 * controls — and it lets pointer events through to what is underneath.
 */
.cg-orientation[data-advisory] {
  inset: 0 0 auto 0;
  align-items: flex-start;
  padding: var(--cl-space-3) var(--cl-space-4);
  background: rgba(11, 13, 26, .94);
  border-bottom: 1px solid var(--cl-status-held, #D98324);
  text-align: left;
  pointer-events: none;
  touch-action: auto; overscroll-behavior: auto;
}
.cg-orientation[data-advisory] .cg-orientation-card { max-width: none; }
.cg-orientation[data-advisory] .cg-orientation-card strong {
  font-size: var(--cl-step-1); margin-bottom: 0;
}
/* The detail line is the long form; the banner keeps only the instruction. */
.cg-orientation[data-advisory] .cg-orientation-card p { display: none; }

.cg-orientation-card { max-width: 340px; }
.cg-orientation-card strong { display: block; font-size: var(--cl-step-3); color: var(--cl-gold); margin-bottom: var(--cl-space-3); }
.cg-orientation-card p { color: var(--cl-text-muted); }

/* Visibly inert too, for a browser without `inert` support. */
[data-orientation-blocked] { pointer-events: none; user-select: none; filter: grayscale(1) brightness(.55); }

@media (orientation: landscape) and (max-height: 460px) {
  /*
   * Phone landscape: keep the entire battlefield full-viewport and compact
   * only the overlays. Nothing below changes the field's dimensions.
   */
  .cg-topbar {
    gap: 6px;
    padding: 2px 8px;
    padding-top: max(2px, env(safe-area-inset-top));
    background: linear-gradient(180deg, rgba(9,14,12,.88), rgba(9,14,12,.42), transparent);
  }
  .cg-title-sub { display: none; }
  .cg-title-main { font-size: var(--cl-step-0); }
  .cg-stats { gap: 4px; }
  .cg-stat { min-width: 46px; padding: 1px 5px; }
  .cg-stat-label { font-size: 7px; }
  .cg-stat-value { font-size: var(--cl-step-0); }

  .cg-wavebar {
    top: max(2px, env(safe-area-inset-top));
    gap: 5px;
    min-height: 28px;
    padding: 2px 7px;
  }
  .cg-wave-value, .cg-wave-clock { font-size: 11px; }
  .cg-integrity-label { font-size: 7px; }



  .cg-action-feedback {
    bottom: 88px;
    max-width: calc(100% - 20px);
    padding: 6px 10px;
    font-size: 10px;
  }
  .cg-deployment-body { padding: 0 4px; gap: 6px; }
  /* Include the full card width in the tray's intrinsic size on mobile Safari. */
  .cg-guard-card { min-width: 132px; grid-template-columns: 32px 1fr; padding: 1px 4px; }
  .cg-guard-portrait { width: 32px; height: 32px; }
}
.cg-announcer-caption {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: max(64px, calc(env(safe-area-inset-top) + 56px));
  transform: translateX(-50%);
  max-width: min(62vw, 540px);
  padding: 6px 12px;
  border: 1px solid rgba(204, 170, 84, 0.65);
  border-radius: 8px;
  background: rgba(8, 18, 36, 0.82);
  color: #f9edcc;
  font-size: clamp(11px, 1.2vw, 14px);
  text-align: center;
  pointer-events: none;
}
.cg-announcer-caption[hidden] { display: none; }
.cg-announcer-caption.is-urgent { border-color: #e7b955; color: #fff2c7; }
.cg-cycle-value { font-size: 0.75em; color: #e7c777; }
@media (orientation: landscape) and (max-height: 460px) {
  .cg-announcer-caption { top: max(36px, calc(env(safe-area-inset-top) + 32px)); }
}

.cg-leaderboard-launcher { position:absolute;z-index:12;left:8px;bottom:8px;min-height:44px;padding:6px 12px; }
.cg-leaderboard-launcher[hidden] { display:none; }
.cg-live-leaderboard { max-width:min(440px,90vw);max-height:80vh;overflow:auto;background:#101a18;color:#edf0df;border:1px solid #b89945;border-radius:14px; }
/* V1 Classic: keep the Core interactive, but outside the slim cycle/wave bar.
 * Absolute positioning removes its 44px touch target from the bar's height.
 * The indicator remains beside the bar, not in the iPhone's left camera inset.
 */
.cg-wavebar .cg-class-core {
  position: absolute;
  top: 0;
  right: calc(100% + 8px);
  transform: none;
  margin: 0;
  min-height: 44px;
  padding: 2px 8px;
  white-space: nowrap;
  flex: none;
}
.cg-topbar { padding-left: max(8px, env(safe-area-inset-left));
  padding-right: max(8px, env(safe-area-inset-right)); }
@media (max-width: 960px) and (orientation: landscape) {
  .cg-wavebar { gap: 5px; }
  .cg-wavebar .cg-class-core { right: calc(100% + 6px); padding: 2px 7px; font-size: 10px; }
}
