/* ============================================================
   Panel contract — extracted from style.css
   Generic panel shell, header/body chrome, shared controls,
   semantic shell tiers, and normalized size caps.
   ============================================================ */

/* ============================
   Toast / Snackbar
   ============================ */
.toast {
  position: absolute;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  z-index: 99999;
  padding: 8px 12px;
  border: 2px solid #000;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.2;
  text-shadow: 1px 1px 0 #000;
  image-rendering: pixelated;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  transition: opacity 120ms linear, transform 120ms linear;
}

/* ============================
   Z-Index Hierarchy
   ============================ */
#world-sun {
  z-index: 81 !important;
}

/* Trail HUD + background */


/* Arena + Mini-Game Results (UI layer) */
#chaoregon-results-panel {
  z-index: 2000 !important;
}

/* General UI panels */
#chaoregon-log-panel{
  z-index: 150 !important;
}

/* ✅ Chaoregon Mini-Games — above everything except results/rewards */

/* Debug + Toolbar */

/* Cursor */

/* ============================
   Utilities
   ============================ */


/* Party Move: only one button row visible per tab */
.neutral-buttons,
.hero-buttons,
.dark-buttons {
  display: none;
}

/* ============================
   Trail Shop Panel
   ============================ */

/* Tabs */

/* Inventory List */

/* Exit Button */

/* ============================
   Chaoregon Camp Panel
   ============================ */

/* ============================
   Anchored Sidebar
   ============================ */

/* Hub tiles (Garden / Mini-Games / Online) */

/* Text-style sidebar button (for features without a mini_*.png asset) */

/* Hide legacy sidebar buttons kept for delegation/back-compat */

/* Meta buttons: slightly smaller + less loud */

/* ============================
   Sidebar Hub Panels
   ============================ */

/* Hub panels: standardized top-right controls without affecting sidebar layout */

.hub-panel-controls > .panel-header .panel-pin-btn,
.hub-panel-controls > .panel-header .panel-close-x {
  position: static;
  top: auto;
  right: auto;
}

.hub-panel-controls > .panel-header .panel-close-x {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 24px;
  line-height: 40px;
  text-align: center;
  cursor: pointer;
  user-select: none;
}

.hub-panel-controls > .panel-header .panel-close-x:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 214, 10, 0.55);
}

.hub-section-title {
  font-size: 12px;
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 900;
  margin: 10px 0 6px;
  opacity: 0.75;
}

/* ============================
   Sidebar — Quest New Badge
   ============================ */

/* ============================
   Karate Dual Buttons (Standalone Panel)
   ============================ */
#party-karate-2p,
#party-karate-cpu {
  display: none; /* hidden by default, shown only when mode === karate */
  margin-top: 8px;
  padding: 8px 16px;
  border: 2px solid #ffd60a;
  border-radius: 6px;
  background: #415a77;
  color: #fff;
  font-weight: bold;
  transition: background 0.2s, transform 0.1s;
}

#party-karate-2p:hover,
#party-karate-cpu:hover {
  background: #5b63ff;
  transform: scale(1.05);
}

#party-karate-2p {
  margin-right: 6px;
}

#party-karate-cpu {
  background: #006bff;
}

.racemode-panel,
.racecourse-panel {
  width: 900px;
  height: 520px;
  background: radial-gradient(circle at center, rgba(20,40,60,0.95), rgba(10,15,25,0.95));
  border: 2px solid #415a77;
  border-radius: 12px;
  color: #fff;
  text-align: center;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden;
}

.racemode-title {
  margin: 8px 0 0;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: 0.3px;
  color: #eef6ff;
  text-shadow: 0 1px 0 rgba(0,0,0,0.4);
}

.racemode-mainwrap {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 22px;
  margin-top: 40px;
  padding: 18px;
}

.racemode-bigbtn {
  width: 280px;
  height: 146px;
  border-radius: 22px;
  border: 1px solid rgba(138, 182, 228, 0.32);
  background: linear-gradient(180deg, rgba(64, 99, 140, 0.95), rgba(24, 38, 58, 0.98));
  font-size: 32px;
  font-weight: 700;
  color: #f6fbff;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  transition: transform 0.2s, background 0.2s, border-color 0.2s, box-shadow 0.2s;
  box-shadow: 0 12px 26px rgba(0,0,0,0.24), inset 0 1px 0 rgba(255,255,255,0.08);
}
.racemode-bigbtn:hover {
  transform: translateY(-2px) scale(1.02);
  background: linear-gradient(180deg, rgba(79, 119, 164, 0.96), rgba(30, 47, 71, 0.99));
  border-color: rgba(182, 217, 252, 0.62);
}

.racecourse-wrap {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  align-content: start;
  flex-wrap: wrap;
  gap: 22px;
  margin-top: 16px;
  padding: 16px;
}

.racemode-btn {
  width: 264px;
  height: 232px;
  border-radius: 20px;
  border: 1px solid rgba(120, 163, 207, 0.24);
  background: linear-gradient(180deg, rgba(18, 29, 43, 0.95), rgba(10, 16, 25, 0.98));
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
  overflow: hidden;
  box-shadow: 0 12px 24px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.05);
}
.racemode-btn img {
  width: 100%;
  height: 170px;
  object-fit: cover;
}
.racemode-btn span {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.25px;
  color: #eef6ff;
  background: linear-gradient(180deg, rgba(58, 88, 124, 0.88), rgba(28, 45, 68, 0.92));
  border-top: 1px solid rgba(255,255,255,0.08);
}
.racemode-btn:hover {
  transform: translateY(-2px) scale(1.02);
  border-color: rgba(176, 214, 250, 0.56);
  box-shadow: 0 16px 28px rgba(0,0,0,0.24), inset 0 1px 0 rgba(255,255,255,0.07);
}

.racemode-back {
  position: absolute;
  top: 14px;
  left: 16px;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid rgba(122, 165, 210, 0.3);
  background: linear-gradient(180deg, rgba(42, 62, 88, 0.95), rgba(18, 29, 44, 0.96));
  color: #edf5ff;
  cursor: pointer;
  font-size: 14px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}
.racemode-back:hover {
  background: linear-gradient(180deg, rgba(58, 82, 112, 0.96), rgba(24, 39, 59, 0.98));
}

/* ============================
   Custom Garden Editor Styles (Grid Checkerboard Fix)
   ============================ */

#grid-edit-panel {
  width: 420px;
  min-height: 320px;
  z-index: 9999;
}

#grid-edit-panel .panel-body {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(255,255,255,0.92);
}

#grid-edit-panel .grid-edit-muted {
  color: rgba(255,255,255,0.72);
  margin-bottom: 10px;
}

#grid-edit-panel .grid-edit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  flex-wrap: wrap;
}

#grid-edit-panel .grid-edit-group-title {
  font-weight: 700;
  color: #cfe7ff;
  margin-bottom: 6px;
}

#grid-edit-panel .grid-edit-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

#grid-edit-panel .grid-edit-checks {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#grid-edit-panel .grid-edit-checks label {
  cursor: pointer;
}

#grid-edit-panel .grid-edit-btn {
  font: inherit;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.95);
  cursor: pointer;
}

#grid-edit-panel .grid-edit-btn.active {
  border-color: rgba(255,0,0,0.7);
  box-shadow: 0 0 0 2px rgba(255,0,0,0.25);
}


#editor-toolbar {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  background: rgba(20,30,40,0.9);
  padding: 5px;
  border-radius: 6px;
}

#editor-toolbar button {
  background: #1b263b;
  color: #fff;
  border: 1px solid #415a77;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  user-select: none;
}
#editor-toolbar button.active {
  background: #778da9;
  color: #000;
}

#editor-grid {
  width: 1500px;
  height: 862px;
  display: grid;
  grid-template-columns: repeat(100, 10px);
  grid-template-rows: repeat(100, 10px);
  margin: 0 auto;
  cursor: crosshair;
  border: 2px solid #415a77;
  background-color: #00C000;
  background-image:
    linear-gradient(45deg, #00C000 25%, transparent 25%),
    linear-gradient(-45deg, #00C000 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #00C000 75%),
    linear-gradient(-45deg, transparent 75%, #00C000 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.tile {
  width: 10px;
  height: 10px;
  box-sizing: border-box;
}

.tile:hover {
  outline: 1px solid yellow !important;
} 

/* Override default tile colors */
.tile.grass { background: transparent; }
.tile.water { background: #2196f3; }
.tile.climb { background: #8d6e63; }
.tile.wall { background: #555555; }
.tile.border { background: #212121; }
.tile.sky { background: #81d4fa; }

.garden-decor {
  image-rendering: pixelated;
}

.garden-decor.shake {
  animation: treeShake 0.4s ease-in-out infinite alternate;
}
@keyframes treeShake {
  from { transform: rotate(-3deg); }
  to { transform: rotate(3deg); }
}

.tree-fruit {
  image-rendering: pixelated;
  z-index: 1;
}

.garden-decor {
  z-index: 1;
}

#grid-overlay {
  z-index: 20;
  pointer-events: none;
}

.mm-label {
  color: #fff;
  font-size: 16px;
  margin: 4px 8px;
  font-family: sans-serif;
}

#mm-countdown {
  position: absolute;
  top: 260px;
  left: 270px;
  font-size: 64px;
  color: #fff;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 80px;
  height: 80px;
  text-shadow: 2px 2px 4px #000;
}

.mm-results {
  position: absolute;
  top: 200px;
  left: 150px;
  width: 300px;
  background: #222;
  border: 2px solid #fff;
  padding: 20px;
  text-align: center;
}

.mm-results-btn {
  padding: 8px 16px;
  margin-top: 12px;
}

.mm-scoreboard {
  position: absolute;
  top: 120px;
  left: 120px;
  width: 360px;
  padding: 20px;
  background: #222;
  border: 2px solid #fff;
  color: #fff;
  text-align: center;
}

.mm-scoreboard-list {
  margin-top: 10px;
  text-align: left;
}

.mm-scoreboard-close {
  margin-top: 16px;
}

/* Outcome states (lightweight) */

@keyframes result-bounce {
  from { transform: translateX(-50%) scale(1.6) translateY(0); }
  to   { transform: translateX(-50%) scale(1.6) translateY(-6px); }
}

/* =========================================

/* =========================================
   Universal panel close "X" (top-right)
   Appended by js/panel-close-x.js.
   IMPORTANT: Do NOT change .panel positioning globally.
   ========================================= */
.panel-close-x {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid rgba(181, 212, 242, 0.28);
  background: linear-gradient(180deg, rgba(52, 70, 96, 0.98) 0%, rgba(30, 43, 61, 0.98) 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 2px 6px rgba(0,0,0,0.22);
  color: #f7fbff;
  font-size: 18px;
  font-weight: 800;
  line-height: 36px;
  text-align: center;
  cursor: pointer;
  z-index: 9000;
  user-select: none;
  pointer-events: auto;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

.panel-close-x:hover {
  background: linear-gradient(180deg, rgba(88, 52, 68, 0.98) 0%, rgba(60, 34, 46, 0.98) 100%);
  border-color: rgba(255, 170, 190, 0.52);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 4px 12px rgba(0,0,0,0.28);
  transform: translateY(-1px);
}

   ============================ */
   DEV / MP Danger Buttons
   ============================ */
.dev-danger {
  border-color: #7a2a2a !important;
}
.lp-danger-btn {
  border-color: #7a2a2a !important;
}

/* ============================
   Panel Pin Button
   ============================ */
.panel-pin-btn {
  position: absolute;
  top: 6px;
  right: 50px;
  height: 38px;
  min-width: 66px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid rgba(181, 212, 242, 0.28);
  background: linear-gradient(180deg, rgba(50, 74, 102, 0.98) 0%, rgba(28, 44, 63, 0.98) 100%);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.08), 0 2px 6px rgba(0,0,0,0.22);
  color: #f6fbff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.5px;
  line-height: 36px;
  cursor: pointer;
  user-select: none;
  z-index: 5;
  transition: background 120ms ease, border-color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

/* =========================================
   Standardized Header Controls
   - Applies only to panels marked by js/panel-close-x.js (std-panel-controls)
   - Excludes gardens + sidebar/toolbar HUD by design
   ========================================= */
.std-panel-controls > .panel-header {
  position: relative;
  padding-top: 10px;
  padding-bottom: 11px;
  margin-bottom: 0;
}

/* If header spacing reduces usable space, scroll instead of letting content spill outside */
.std-panel-controls {
  overflow: auto;
}

.std-panel-controls > .panel-header > .panel-header-controls {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

/* When placed in header controls, buttons should flow normally */
.std-panel-controls > .panel-header .panel-pin-btn,
.std-panel-controls > .panel-header .panel-close-x {
  position: static;
  top: auto;
  right: auto;
}

/* Floating garden pin overlay disabled for neutral-only stage layout */
.garden-pin-floating {
  display: none !important;
}

.panel-pin-btn:hover {
  background: linear-gradient(180deg, rgba(70, 103, 140, 0.98) 0%, rgba(35, 57, 82, 0.98) 100%);
  border-color: rgba(161, 208, 255, 0.48);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.10), 0 4px 12px rgba(0,0,0,0.28);
  transform: translateY(-1px);
}

.panel-pin-btn.is-pinned {
  background: linear-gradient(180deg, rgba(84, 117, 152, 0.98) 0%, rgba(46, 72, 97, 0.98) 100%);
  border-color: rgba(191, 225, 255, 0.56);
}

.panel.pinned {
  box-shadow: 0 0 0 1px rgba(196,225,250,0.20), 0 0 0 4px rgba(120,165,214,0.10), var(--panel-shell-shadow);
}

/* Cursor5 Decorate hover */

/* ============================================
   DRAG/DROP REORDER (SIDEBAR + HUBS)
   ============================================ */

/* ============================================================
   PARTY MODE PANEL (MP meta loop)
   ============================================================ */
   PANEL CONTRACT (Phase 1)
   - header + body structure for standardized panels
   - does NOT delete/override legacy per-panel rules
   ======================================================================== */

.panel-header-controls { pointer-events: auto; }
.panel-header-controls, .panel-header-controls * { user-select: none; }

/* ============================
   Phase 5: Panel Contract migrations
   ============================ */


/* ===== Patch 5: focus dot + stats layout cleanup ===== */

/* ===== Patch 6: focus/stats/debug cleanup ===== */

/* ===== Patch 7: stats button alignment cleanup ===== */

/* ===== merged patch overrides on patched7 base ===== */

#ui-options-panel:not(.hidden),
#ui-options-panel.panel-shell-list:not(.hidden) {
  display: flex !important;
  flex-direction: column !important;
}
#ui-options-panel .ui-options-tabs {
  display: flex;
  flex: 0 0 auto;
  gap: 10px;
  flex-wrap: wrap;
  min-height: auto !important;
  margin: 0 0 10px 0 !important;
  padding: 0 0 6px 0 !important;
  position: relative !important;
  z-index: 5 !important;
  background: linear-gradient(180deg, rgba(11,18,29,0.96), rgba(11,18,29,0.88)) !important;
}
#ui-options-panel .ui-options-tabpage.active::after {
  content: "";
  display: block;
  width: 100%;
  height: 160px;
  flex: 0 0 auto;
}
#ui-options-panel .ui-audio-grid {
  display:flex;
  flex-direction:column;
  gap:12px;
}
#ui-options-panel .ui-audio-row input[type="number"] {
  width:100%;
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(0,0,0,0.45);
  color:#fff;
  border-radius:8px;
  padding:8px 10px;
}
#ui-options-panel .ui-audio-check {
  display:flex;
  align-items:center;
  gap:8px;
  font-weight:700;
}
#ui-options-panel .ui-options-copy { padding: 6px 2px; }
#ui-options-panel .ui-about-value { opacity: 0.9; }

/* ============================
   Controls Reference Panel
   ============================ */
#controls-panel.panel {
  z-index: 2600 !important;
  overflow: hidden;
}
#controls-panel .panel-body.controls-panel-body {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  height: 100%;
  padding: 0;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(7,16,34,0.96), rgba(11,25,49,0.94));
}
.controls-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}
.controls-sidebar {
  min-height: 0;
  min-width: 0;
  border-right: 1px solid rgba(255,255,255,0.12);
  padding: 14px 10px 14px 14px;
  overflow-y: auto;
  overflow-x: hidden;
  background: rgba(3, 10, 22, 0.65);
}
.controls-nav-btn {
  display: block;
  width: 100%;
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.14);
  border-radius: 10px;
  background: rgba(255,255,255,0.05);
  color: #fff;
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.controls-nav-btn:hover { background: rgba(255,255,255,0.1); }
.controls-nav-btn.active {
  background: rgba(118, 191, 255, 0.22);
  border-color: rgba(118, 191, 255, 0.4);
}
.controls-content {
  display: block;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 16px 18px 24px;
}
.controls-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  margin-bottom: 16px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  background: rgba(255,255,255,0.05);
}
.controls-kicker {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.75;
}
.controls-hero h2 { margin: 4px 0 8px; font-size: 28px; }
.controls-hero p { margin: 0; line-height: 1.4; opacity: 0.92; }
.controls-legend {
  min-width: 340px;
  display: grid;
  gap: 10px;
}
.controls-legend > div {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  background: rgba(0,0,0,0.18);
}
.controls-sections { display: grid; gap: 16px; }
.controls-section {
  scroll-margin-top: 14px;
  padding: 14px 16px 16px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  background: rgba(255,255,255,0.04);
}
.controls-section h3 { margin: 0 0 6px; font-size: 24px; }
.controls-section > p { margin: 0 0 14px; line-height: 1.45; opacity: 0.9; }
.controls-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.controls-card {
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 12px 13px;
  background: rgba(0,0,0,0.15);
}
.controls-card h4 { margin: 0 0 8px; font-size: 18px; }
.controls-card ul { margin: 0; padding-left: 18px; }
.controls-card li { margin: 0 0 6px; line-height: 1.35; }
.controls-card li:last-child { margin-bottom: 0; }
.controls-card p { margin: 0; line-height: 1.4; }
.controls-wide { grid-column: 1 / -1; }
@media (max-width: 1400px) {
  .controls-shell { grid-template-columns: 220px minmax(0, 1fr); }
}

.racemode-body,
.racecourse-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px;
  border-radius: 22px;
  border: 1px solid rgba(116, 156, 198, 0.18);
  background: linear-gradient(180deg, rgba(18, 29, 45, 0.74), rgba(9, 15, 24, 0.84));
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
}

/* ============================================================
   Display pass: semantic shell tiers
   - separates panel intent from raw size buckets
   - keeps future normalization work centralized
   ============================================================ */

.panel.panel-shell-gameplay-xl,
.panel.panel-shell-gameplay-wide,
.panel.panel-shell-setup-lg,
.panel.panel-shell-editor,
.panel.panel-shell-canvas,
.panel.panel-shell-sidecard,
.panel.panel-shell-list,
.panel.panel-shell-modal,
.panel.panel-shell-rpg {
  max-width: calc(var(--app-authored-width) - 24px);
  max-height: calc(var(--app-authored-height) - 24px);
}

.panel.panel-shell-gameplay-xl,
.panel.panel-shell-gameplay-wide,
.panel.panel-shell-setup-lg,
.panel.panel-shell-editor,
.panel.panel-shell-canvas,
.panel.panel-shell-sidecard,
.panel.panel-shell-list,
.panel.panel-shell-modal,
.panel.panel-shell-rpg {
  display: flex;
  flex-direction: column;
}

.panel.panel-shell-gameplay-xl > .panel-header,
.panel.panel-shell-gameplay-wide > .panel-header,
.panel.panel-shell-setup-lg > .panel-header,
.panel.panel-shell-editor > .panel-header,
.panel.panel-shell-canvas > .panel-header,
.panel.panel-shell-sidecard > .panel-header,
.panel.panel-shell-list > .panel-header,
.panel.panel-shell-modal > .panel-header,
.panel.panel-shell-rpg > .panel-header {
  flex: 0 0 auto;
}

.panel.panel-shell-gameplay-xl > .panel-body,
.panel.panel-shell-gameplay-wide > .panel-body,
.panel.panel-shell-setup-lg > .panel-body,
.panel.panel-shell-editor > .panel-body,
.panel.panel-shell-canvas > .panel-body,
.panel.panel-shell-sidecard > .panel-body,
.panel.panel-shell-list > .panel-body,
.panel.panel-shell-modal > .panel-body,
.panel.panel-shell-rpg > .panel-body {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}

.panel.panel-shell-gameplay-xl > .panel-body,
.panel.panel-shell-gameplay-wide > .panel-body,
.panel.panel-shell-canvas > .panel-body,
.panel.panel-shell-editor > .panel-body,
.panel.panel-shell-rpg > .panel-body {
  overflow: hidden;
}

.panel.panel-shell-setup-lg > .panel-body,
.panel.panel-shell-list > .panel-body,
.panel.panel-shell-sidecard > .panel-body,
.panel.panel-shell-modal > .panel-body {
  overflow: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.panel.panel-shell-rpg > .panel-body {
  overflow-x: hidden;
}

.panel.panel-shell-sidecard {
  max-width: min(420px, calc(var(--app-authored-width) - 24px));
}

.panel.panel-shell-modal {
  max-width: min(1100px, calc(var(--app-authored-width) - 24px));
  max-height: min(760px, calc(var(--app-authored-height) - 24px));
}

.panel.panel-shell-gameplay-xl {
  max-width: min(1520px, calc(var(--app-authored-width) - 24px));
  max-height: min(900px, calc(var(--app-authored-height) - 24px));
}

.panel.panel-shell-gameplay-wide {
  max-width: min(1440px, calc(var(--app-authored-width) - 24px));
  max-height: min(880px, calc(var(--app-authored-height) - 24px));
}

.panel.panel-shell-setup-lg {
  max-width: min(1120px, calc(var(--app-authored-width) - 24px));
  max-height: min(840px, calc(var(--app-authored-height) - 24px));
}

.panel.panel-shell-editor {
  max-width: min(1540px, calc(var(--app-authored-width) - 24px));
  max-height: min(940px, calc(var(--app-authored-height) - 24px));
}

.panel.panel-shell-canvas {
  max-width: min(1220px, calc(var(--app-authored-width) - 24px));
  max-height: min(840px, calc(var(--app-authored-height) - 24px));
}

.panel.panel-shell-list {
  max-width: min(960px, calc(var(--app-authored-width) - 24px));
  max-height: min(760px, calc(var(--app-authored-height) - 24px));
}

.panel.panel-shell-rpg {
  max-width: min(1180px, calc(var(--app-authored-width) - 24px));
  max-height: min(840px, calc(var(--app-authored-height) - 24px));
}

/* Display pass: second reduction round for newly-tokenized families */
.panel-size-setup-md,
.panel-size-editor-xxl,
.panel-size-list-lg,
.panel-size-list-md,
.panel-size-card-lg,
.panel-size-card-md,
.panel-size-card-wide,
.panel-size-setup-xl {
  max-width: calc(var(--app-authored-width) - 24px);
  max-height: calc(var(--app-authored-height) - 24px);
}

.panel-size-setup-md,
.panel-size-setup-xl,
.panel-size-list-lg {
  max-width: min(1040px, calc(var(--app-authored-width) - 24px));
}

.panel-size-list-md,
.panel-size-card-lg,
.panel-size-card-md,
.panel-size-card-wide {
  max-width: min(720px, calc(var(--app-authored-width) - 24px));
}

/* ============================================================
   Display pass phase: internal panel fit cleanup
   - targeted polish for newly-normalized shells
   - keep shell sizing, fix panel body reflow/overflow
   ============================================================ */

.party-hub-buttons {
  position: relative;
  inset: auto;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  grid-auto-rows: minmax(150px, 1fr);
  gap: clamp(16px, 2vw, 32px);
  min-height: 0;
}

.party-hub-buttons .hub-btn {
  min-height: 150px;
}

.party-hub-buttons .hub-btn img {
  width: min(100%, 260px);
  height: min(100%, 150px);
}


/* Janken */
/* Chao Kart pregame */

/* Responsive internal reflow for clamped shells */
@media (max-width: 1500px) {
  .party-hub-buttons {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    grid-auto-rows: minmax(120px, 1fr);
    gap: 16px;
  }

  #party-minigame-select {
    grid-column: 1 / -1;
  }
}

@media (max-width: 980px) {
  .party-hub-buttons {
    grid-template-columns: 1fr;
  }
}

/* ============================================================
   Display pass patch29 — targeted setup/results/gameplay fit cleanup
   Focus: lobby/matchmake/party-mode/results/gameplay bodies under shell sizes
   ============================================================ */

/* Normalize remaining large ID overrides back onto token/shell sizing. */


#race-multiplayer-panel {
  background: rgba(12, 22, 32, 0.96) !important;
  border: 3px solid #3a4f69;
  border-radius: 12px;
}

#race-multiplayer-panel > .panel-body, #global-results-panel > .panel-body, #matchmake-panel > .panel-body{
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

/* Results panels — older intermediary authority block trimmed.
   Later Global Results Refactor + final results-shell ownership now define
   the active body/banner/footer/list contract. */

/* Gameplay bodies */
#karate-mp-panel > .panel-body.karate-mp-body {
  padding: 10px;
  gap: 10px;
  overflow: hidden;
}

#karate-mp-panel .karate-mp-info {
  flex: 0 0 auto;
  margin-top: 0;
}

/* Arena family: old info strips were reading like duplicate headers under the new chrome. */
.tmp-panel-body > .tmp-info,
.mp2x-body > .tmp-info,
#karate-mp-panel .karate-mp-info {
  margin: 10px 10px 8px !important;
  padding: 10px 12px !important;
  border-radius: 16px !important;
  border: 1px solid rgba(112, 151, 193, 0.18) !important;
  background: linear-gradient(180deg, rgba(16, 25, 38, 0.88), rgba(10, 16, 26, 0.94)) !important;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04) !important;
}

.tmp-panel-body > .tmp-info:first-child,
.mp2x-body > .tmp-info:first-child,
#karate-mp-panel .karate-mp-info:first-child {
  margin-top: 12px !important;
}

.tmp-info-help,
#karate-mp-panel .karate-mp-info .tmp-info-help {
  opacity: 0.78 !important;
}

#karate-mp-panel .karate-mp-arena {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 0;
}

/* ============================================================
   Display pass: shared arena panel contract
   - keeps canvas/stage panels on a single internal layout model
   - prevents header/body regressions as more panels get normalized
   ============================================================ */

.arena-panel-body {
  position: relative;
  padding: 0 !important;
  overflow: hidden;
  background: transparent;
}

#treasure-hunt-panel, #race-multiplayer-panel{
  overflow: hidden;
}

#treasure-hunt-panel > .panel-body, #shared-garden-world-panel > .panel-body, #race-multiplayer-panel > .panel-body{
  min-width: 0;
  min-height: 0;
}

#treasure-hunt-panel > .panel-body, #shared-garden-world-panel > .panel-body, #race-multiplayer-panel > .panel-body{
  display: flex;
  flex-direction: column;
}

#karate-mp-panel .karate-mp-arena {
  flex: 1 1 auto;
  min-height: 0;
}

/* ============================================================
   Display pass phase: representative internal fit cleanup
   - setup/list/canvas/editor representative polish
   - keeps shell contracts intact, fixes common content pressure points
   ============================================================ */

.panel.panel-shell-setup-lg > .panel-header,
.panel.panel-shell-list > .panel-header,
.panel.panel-shell-modal > .panel-header,
.panel.panel-shell-editor > .panel-header,
.panel.panel-shell-canvas > .panel-header {
  position: relative;
  min-width: 0;
}

.panel.panel-shell-setup-lg > .panel-header > .panel-title,
.panel.panel-shell-list > .panel-header > .panel-title,
.panel.panel-shell-modal > .panel-header > .panel-title,
.panel.panel-shell-editor > .panel-header > .panel-title,
.panel.panel-shell-canvas > .panel-header > .panel-title {
  min-width: 0;
  padding-right: 8px;
}

#party-status-panel > .panel-body.party-status-panel-body, #quest-board-panel > .panel-body.quest-panel-body, #trackmaker2-panel > .panel-body.tm2-body, #chaoracemaker-panel > .panel-body.crm-body, #garden-editor-panel > .panel-body, #shared-garden-world-panel > .panel-body.shared-garden-world-body, #karate-mp-panel > .panel-body.karate-mp-body{
  min-width: 0;
  min-height: 0;
}

#quest-board-panel > .panel-body.quest-panel-body,
#global-results-body {
  align-items: stretch;
}

#trackmaker2-panel > .panel-body.tm2-body,
#chaoracemaker-panel > .panel-body.crm-body,
#garden-editor-panel > .panel-body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#shared-garden-world-panel > .panel-body.shared-garden-world-body, #karate-mp-panel > .panel-body.karate-mp-body{
  display: flex;
  flex-direction: column;
}

@media (max-width: 1220px), (max-height: 760px) {
  .controls-shell {
    grid-template-columns: 1fr;
  }

  .controls-sidebar {
    max-height: 220px;
  }

  .controls-hero {
    flex-direction: column;
  }

  .controls-legend {
    min-width: 0;
    width: 100%;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  }

  .controls-grid {
    grid-template-columns: 1fr;
  }

}

/* ============================================================
   Authoritative generic panel shell contract
   ============================================================ */
.panel {
  position: fixed;
  z-index: 9000;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,calc(var(--panel-shell-alpha) * 0.045)) 0%, rgba(255,255,255,calc(var(--panel-shell-alpha) * 0.018)) 9%, rgba(255,255,255,0.00) 16%),
    linear-gradient(180deg, rgba(16,26,40,calc(var(--panel-shell-alpha) * 0.98)) 0%, rgba(11,19,31,calc(var(--panel-shell-alpha) * 0.98)) 100%);
  border: 2px solid var(--panel-shell-border);
  border-radius: var(--panel-shell-radius);
  box-shadow: var(--panel-shell-shadow);
  color: #fff;
  overflow: hidden;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 1px 0 var(--panel-shell-border-soft), inset 0 0 0 1px rgba(10, 14, 22, 0.24);
  opacity: 1;
}

.panel > .panel-header,
.tmp-wrap > .panel-header {
  position: relative;
  flex: 0 0 auto;
  min-height: var(--panel-header-h);
  margin: 0;
  padding: 10px var(--panel-header-pad-x) 11px;
  display: flex;
  align-items: center;
  gap: var(--panel-header-gap);
  background:
    linear-gradient(180deg, rgba(255,255,255,calc(var(--panel-header-alpha) * 0.12)) 0%, rgba(255,255,255,calc(var(--panel-header-alpha) * 0.03)) 12%, rgba(255,255,255,0.00) 100%),
    linear-gradient(0deg, rgba(255,255,255,calc(var(--panel-header-pattern-alpha) * 0.14)), rgba(255,255,255,calc(var(--panel-header-pattern-alpha) * 0.14))),
    var(--panel-header-pattern-layer),
    linear-gradient(180deg, rgba(var(--panel-header-rgb, 70,103,137),var(--panel-header-alpha)) 0%, rgba(var(--panel-header-rgb-deep, 34,56,79),var(--panel-header-alpha)) 100%);
  border-bottom: 1px solid var(--panel-header-divider);
  box-shadow: inset 0 -1px 0 rgba(0,0,0,0.28), inset 0 1px 0 rgba(255,255,255,0.08);
  background-repeat: no-repeat, no-repeat, repeat, no-repeat;
  background-position: 0 0, 0 0, left top, 0 0;
  background-size: auto, auto, 256px 256px, auto;
}

.panel > .panel-header::after,
.tmp-wrap > .panel-header::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, rgba(255,255,255,0.02), rgba(170,208,246,0.28), rgba(255,255,255,0.02));
  pointer-events: none;
}

.panel-title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  color: #f4f8fc;
  font-size: 24px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0.4px;
  text-shadow: 0 1px 0 rgba(0,0,0,0.24);
}

.panel > .panel-body,
.tmp-wrap > .panel-body {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  width: 100%;
  box-sizing: border-box;
  padding: 14px 16px 16px;
  background: linear-gradient(180deg, rgba(255,255,255,calc(var(--panel-body-alpha) * 0.04)) 0%, rgba(255,255,255,0.00) 18%);
}

.panel.hidden {
  display: none !important;
}
