/* ═══════════════════════════════════════════════════════════════════════════
   THRONEBOUND REALMS — integration.css  (shell skeleton + start menu + boot card)

   Scope: ONLY the page shell (html/body, #realm-app and its four containers),
   the start menu (#tbr-start), the boot-error card (#tbr-boot) and the
   #debug overlay. The in-game look of #hud / #gamepad / #modal-host belongs
   to css/realms.css (the presentation module), loaded later by the manifest;
   nothing here styles their children.

   Tokens are the same names as ../css/game.css, redeclared locally because
   this page deliberately does NOT load game.css (its #panel/#bottom-nav
   layout rules would fight a full-viewport canvas).
   ═══════════════════════════════════════════════════════════════════════════ */
:root {
  --night-900: #0b111c;
  --night-800: #101826;
  --night-700: #182338;
  --parch-50:  #f6ecd2;
  --parch-100: #efe2c0;
  --parch-200: #e5d3a8;
  --parch-300: #d6bf8a;
  --parch-400: #b99f66;
  --ink-900: #2c2013;
  --ink-700: #4a3823;
  --ink-500: #6b5535;
  --wood-700: #33220f;
  --wood-600: #4a3118;
  --wood-500: #63421f;
  --gold-600: #a8752a;
  --gold-500: #d9a53f;
  --gold-400: #e8bb55;
  --gold-300: #f3cf6d;
  --gem: #4fd1c5;
  --good: #5fae52;
  --bad: #c0554a;
  --discord: #5865f2;
  --font-display: Georgia, 'Iowan Old Style', 'Palatino Linotype', 'Book Antiqua', 'Times New Roman', serif;
  --font-body: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, .55);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .35);
  --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);
}

/* ── shell ─────────────────────────────────────────────────────────────── */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--night-900);
  color: var(--parch-100);
  font-family: var(--font-body);
  overscroll-behavior: none;       /* no pull-to-refresh while holding the pad */
  -webkit-text-size-adjust: 100%;
}
body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  touch-action: none;              /* the gamepad + canvas own every touch */
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}
[hidden] { display: none !important; }

#realm-app {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--night-900);
}
#realm-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}
#hud { position: absolute; inset: 0; pointer-events: none; z-index: 10; }
#hud > * { pointer-events: auto; }
#gamepad {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding-bottom: var(--safe-b);
  z-index: 20;
  touch-action: none;
}
#modal-host { position: absolute; inset: 0; z-index: 30; }

/* ── shared primitives (start menu + boot card + debug) ────────────────── */
.tbr-card {
  background:
    linear-gradient(180deg, rgba(255,255,255,.08), rgba(0,0,0,0) 30%),
    var(--parch-100);
  color: var(--ink-900);
  border: 2px solid var(--gold-600);
  outline: 1px solid var(--wood-700);
  outline-offset: 3px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 22px 22px 18px;
  width: min(440px, calc(100vw - 32px - var(--safe-l) - var(--safe-r)));
  max-height: calc(100vh - 32px - var(--safe-t) - var(--safe-b));
  max-height: calc(100dvh - 32px - var(--safe-t) - var(--safe-b));
  overflow: auto;
  box-sizing: border-box;
}
/* `tbri-btn`, not `tbr-btn`: engine/engine.css styles its touch A/B pad with
   `.tbr-btn` (fixed size, border-radius 50%) and is injected after this sheet. */
.tbri-btn {
  display: inline-flex;
  box-sizing: border-box; /* <a> and <button> share the class; anchors default to content-box and overflow at width:100% */
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: 8px;
  border: 1px solid var(--wood-700);
  background: linear-gradient(180deg, var(--gold-300), var(--gold-500) 55%, var(--gold-600));
  color: var(--ink-900);
  font: 700 16px/1.15 var(--font-display);
  letter-spacing: .02em;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,.45);
  transition: transform .08s ease, filter .12s ease;
}
.tbri-btn:hover { filter: brightness(1.06); }
.tbri-btn:active { transform: translateY(1px); }
.tbri-btn:focus-visible { outline: 3px solid var(--gem); outline-offset: 2px; }
.tbri-btn[disabled], .tbri-btn[aria-disabled="true"] {
  filter: grayscale(.6) brightness(.85);
  cursor: not-allowed;
  transform: none;
}
.tbri-btn-big { width: 100%; min-height: 54px; font-size: 20px; }
.tbri-btn-ghost {
  background: linear-gradient(180deg, var(--parch-50), var(--parch-200));
  color: var(--ink-700);
}
.tbri-btn-discord {
  background: linear-gradient(180deg, #7b86f5, var(--discord) 60%, #4752c4);
  color: #fff;
  border-color: #2f3690;
}
.tbr-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.tbr-row > * { flex: 1 1 auto; }
.tbr-muted { color: var(--ink-500); font-size: 14px; margin: 8px 0 0; }
.tbr-details {
  width: 100%;
  box-sizing: border-box;
  margin-top: 12px;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--ink-900);
  background: var(--parch-50);
  border: 1px solid var(--parch-400);
  border-radius: 6px;
  padding: 8px;
  resize: vertical;
  -webkit-user-select: text;
  user-select: text;
}

/* ── start menu ────────────────────────────────────────────────────────── */
#tbr-start {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
  box-sizing: border-box;
  background:
    radial-gradient(ellipse at 50% 120%, rgba(217,165,63,.28), transparent 55%),
    radial-gradient(ellipse at 50% -20%, rgba(79,209,197,.18), transparent 50%),
    linear-gradient(180deg, var(--night-800), var(--night-900) 70%);
  overflow: auto;
}
#tbr-start::before {
  /* faint tile grid: the page IS the overworld */
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 32px 32px;
  pointer-events: none;
}
.tbr-start-card { position: relative; text-align: center; }
.tbr-crest {
  width: 64px; height: 64px;
  margin: -8px auto 8px; /* stays inside the card's padding box: overflow:auto would clip a hanging crest */
  display: block;
  filter: drop-shadow(0 4px 10px rgba(0,0,0,.5));
}
.tbr-kicker {
  margin: 0;
  font: 700 12px/1 var(--font-body);
  letter-spacing: .28em;
  text-transform: uppercase;
  color: var(--gold-600);
}
#tbr-start-title {
  margin: 6px 0 2px;
  font: 700 clamp(30px, 8vw, 40px)/1.05 var(--font-display);
  color: var(--ink-900);
  text-shadow: 0 1px 0 rgba(255,255,255,.5);
}
.tbr-tagline { margin: 0 0 16px; color: var(--ink-500); font-style: italic; font-family: var(--font-display); }
.tbr-load { margin: 14px 0 6px; }
.tbr-load-track {
  height: 8px;
  border-radius: 4px;
  background: var(--parch-300);
  border: 1px solid var(--parch-400);
  overflow: hidden;
}
#tbr-load-bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--gem), var(--good));
  transition: width .25s ease;
}
#tbr-load-text { margin: 6px 0 0; font-size: 13px; color: var(--ink-500); }
#tbr-load-why { margin: 4px 0 0; font-size: 13px; color: var(--bad); font-weight: 600; }
.tbr-how-toggle {
  background: none; border: 0; padding: 6px 0; margin-top: 10px;
  color: var(--ink-700); text-decoration: underline; cursor: pointer;
  font: 600 14px/1.2 var(--font-body);
}
#tbr-how { text-align: left; font-size: 14px; line-height: 1.45; color: var(--ink-700); }
#tbr-how p { margin: 8px 0; }
#tbr-how a { color: var(--ink-900); }
.tbr-foot {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  color: var(--ink-500);
}
.tbr-foot button { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; cursor: pointer; font: inherit; }

/* ── boot-error card ───────────────────────────────────────────────────── */
#tbr-boot {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  box-sizing: border-box;
  background: rgba(11, 17, 28, .82);
  overflow: auto;
}
.tbr-boot-card h2 { margin: 0 0 6px; font: 700 22px/1.2 var(--font-display); color: var(--bad); }
.tbr-boot-msg { margin: 0; font-weight: 600; word-break: break-word; }

/* ── #debug overlay ────────────────────────────────────────────────────── */
.tbr-debug {
  position: fixed;
  left: 8px; right: 8px; bottom: calc(8px + var(--safe-b));
  max-height: 45vh;
  z-index: 200;
  background: rgba(11, 17, 28, .94);
  color: var(--parch-100);
  border: 1px solid var(--gold-600);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.tbr-debug-bar { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-bottom: 1px solid rgba(255,255,255,.12); }
.tbr-debug-bar .tbri-btn { min-height: 28px; padding: 2px 10px; font-size: 12px; }
.tbr-debug pre { margin: 0; padding: 8px; overflow: auto; white-space: pre-wrap; -webkit-user-select: text; user-select: text; }

@media (prefers-reduced-motion: reduce) {
  .tbri-btn, #tbr-load-bar { transition: none; }
}
@media (max-height: 560px) {
  .tbr-crest { display: none; }
  .tbr-card { padding: 14px 16px 12px; }
  #tbr-start-title { font-size: 26px; }
}
