/* ============================================================================
   TS ALL-FOR-ONE — IN-GAME GM PANEL OVERLAY & FLOATING LAUNCHER
   Ornate Three Kingdoms RPG UI (Ebony Lacquer & Gilded Bronze)
   Strictly scoped under #tsgm-root (zero conflict with game canvas / world map)
   ============================================================================ */

#tsgm-root {
  --gm-font-disp: "Playfair Display", "Noto Serif", Georgia, serif;
  --gm-font: "Be Vietnam Pro", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
  --gm-ebony-0: #140e0a;
  --gm-ebony-1: #1a120d;
  --gm-ebony-2: #261a13;
  --gm-gold: #c99746;
  --gm-gold-hi: #f0cf85;
  --gm-crimson: #b8332a;
  --gm-jade: #2e9e63;
  --gm-scroll-blue: #215387;
  --gm-cream: #f5ead6;
  --gm-sand: #bfa886;

  position: fixed;
  inset: 0;
  z-index: 9600;
  pointer-events: none;
  font-family: var(--gm-font);
  user-select: none;
}

#tsgm-root *, #tsgm-root *::before, #tsgm-root *::after {
  box-sizing: border-box;
}

/* ==================== COMPACT FLOATING GM LAUNCHER BUTTON ==================== */
.tsgm-fab {
  position: fixed;
  top: 62px;
  right: 14px;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 13px 6px 7px;
  border-radius: 999px;
  background: linear-gradient(180deg, #322116 0%, #1c120c 100%);
  border: 1.5px solid var(--gm-gold);
  box-shadow:
    0 0 0 1px rgba(240, 207, 133, 0.32),
    0 10px 26px rgba(8, 4, 2, 0.68),
    inset 0 1px 0 rgba(240, 207, 133, 0.35);
  cursor: pointer;
  touch-action: none;
  transition: transform .14s ease, box-shadow .16s ease, border-color .16s ease;
}
.tsgm-fab:hover {
  border-color: var(--gm-gold-hi);
  box-shadow:
    0 0 0 1.5px rgba(240, 207, 133, 0.55),
    0 12px 28px rgba(8, 4, 2, 0.78),
    0 0 16px rgba(201, 151, 70, 0.35);
}
.tsgm-fab:active { transform: scale(0.96); }
.tsgm-fab.active {
  background: linear-gradient(180deg, #992922 0%, #611914 100%);
  border-color: var(--gm-gold-hi);
  box-shadow:
    0 0 0 1.5px rgba(240, 207, 133, 0.7),
    0 10px 26px rgba(100, 22, 16, 0.65),
    0 0 18px rgba(184, 51, 42, 0.45);
}

.tsgm-fab-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #f7dfa3 0%, #c99746 58%, #6d4717 100%);
  border: 1.5px solid #fff0c7;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.55), inset 0 1px 2px rgba(255, 255, 255, 0.6);
  flex-shrink: 0;
}
.tsgm-fab-text {
  display: flex;
  flex-direction: column;
  line-height: 1.18;
  text-align: left;
  max-width: 165px;
}
.tsgm-fab-title {
  font-family: var(--gm-font-disp);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.25px;
  color: var(--gm-gold-hi);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  white-space: nowrap;
}
.tsgm-fab-sub {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--gm-sand);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.85);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tsgm-fab-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f0cf85;
  border: 1.5px solid #1a120d;
  box-shadow: 0 0 7px rgba(240, 207, 133, 0.8);
  flex-shrink: 0;
}
.tsgm-fab-dot.online {
  background: #38d983;
  box-shadow: 0 0 8px rgba(56, 217, 131, 0.9);
}
.tsgm-fab-dot.offline {
  background: #ef5350;
  box-shadow: 0 0 7px rgba(239, 83, 80, 0.8);
}

/* ==================== COMPACT LIVE IN-GAME FONT TUNER PILL ==================== */
.tsgm-font-bar {
  position: fixed;
  top: 112px;
  right: 14px;
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px 4px 10px;
  border-radius: 999px;
  background: rgba(24, 16, 11, 0.88);
  border: 1px solid rgba(201, 151, 70, 0.62);
  box-shadow: 0 6px 18px rgba(8, 4, 2, 0.58);
  color: var(--gm-cream);
  font: 700 11px var(--gm-font);
  backdrop-filter: blur(5px);
}
.tsgm-font-lbl {
  color: var(--gm-sand);
  white-space: nowrap;
  margin-right: 1px;
}
.tsgm-font-btn {
  width: 21px;
  height: 21px;
  border-radius: 50%;
  border: 1px solid rgba(240, 207, 133, 0.55);
  background: linear-gradient(180deg, #352317 0%, #22160f 100%);
  color: var(--gm-gold-hi);
  font: 800 13px/1 var(--gm-font);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: background .12s ease, border-color .12s ease;
}
.tsgm-font-btn:hover {
  background: linear-gradient(180deg, #523620 0%, #311f13 100%);
  border-color: var(--gm-gold-hi);
}
.tsgm-font-btn:active { transform: scale(0.92); }
.tsgm-font-val {
  min-width: 38px;
  text-align: center;
  padding: 2px 5px;
  border-radius: 6px;
  border: 1px solid rgba(201, 151, 70, 0.25);
  background: rgba(255, 240, 200, 0.08);
  color: var(--gm-gold-hi);
  font: 700 11px "Cascadia Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.tsgm-font-val:hover { background: rgba(240, 207, 133, 0.18); }

/* ==================== GM PANEL OVERLAY BACKDROP & SHELL ==================== */
.tsgm-backdrop {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 42%, rgba(28, 18, 12, 0.58) 0%, rgba(9, 6, 4, 0.80) 100%);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  pointer-events: auto;
  opacity: 0;
  transition: opacity .2s ease;
}
.tsgm-backdrop.show {
  display: flex;
  opacity: 1;
}

/* Side-by-Side Play Mode: play game on left, use GM Panel on right */
.tsgm-backdrop.dock-side {
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  pointer-events: none;
  justify-content: flex-end;
  padding: 10px;
}

.tsgm-shell {
  position: relative;
  width: min(1480px, 88vw);
  height: min(920px, 88vh);
  border-radius: 14px;
  overflow: hidden;
  background: #1a120d;
  border: 2px solid var(--gm-gold);
  box-shadow:
    0 0 0 1px rgba(240, 207, 133, 0.45),
    0 0 0 5px rgba(26, 18, 13, 0.9),
    0 0 0 6px rgba(201, 151, 70, 0.48),
    0 28px 72px rgba(0, 0, 0, 0.88),
    0 0 42px rgba(201, 151, 70, 0.14);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  transition: width .22s ease, height .22s ease, transform .22s ease;
  animation: tsgm-pop .2s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes tsgm-pop {
  from { opacity: 0; transform: scale(0.975) translateY(6px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.tsgm-backdrop.dock-side .tsgm-shell {
  width: min(820px, 56vw);
  height: calc(100vh - 20px);
  box-shadow:
    -10px 0 44px rgba(0, 0, 0, 0.78),
    0 0 0 1.5px rgba(240, 207, 133, 0.65);
}

.tsgm-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
  background: #1a120d;
}

/* Loading & Offline Fallback Card */
.tsgm-overlay-state {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at 50% 35%, #2b1d14 0%, #170f0a 72%, #100a07 100%);
  color: var(--gm-cream);
}
.tsgm-overlay-state.hidden { display: none; }

.tsgm-state-card {
  max-width: 500px;
  padding: 26px 28px;
  border-radius: 12px;
  background: linear-gradient(180deg, #271b14 0%, #1c130e 100%);
  border: 1.5px solid var(--gm-gold);
  box-shadow:
    0 0 0 4px rgba(26, 18, 13, 0.8),
    0 0 0 5px rgba(201, 151, 70, 0.35),
    0 22px 52px rgba(0, 0, 0, 0.72);
  color: var(--gm-cream);
}
.tsgm-state-card h3 {
  margin: 0 0 10px;
  font-family: var(--gm-font-disp);
  font-size: 20px;
  font-weight: 700;
  color: var(--gm-gold-hi);
}
.tsgm-state-card p {
  margin: 0 0 16px;
  font-size: 13.5px;
  line-height: 1.55;
  font-weight: 500;
  color: var(--gm-sand);
}
.tsgm-state-card code {
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(201, 151, 70, 0.14);
  border: 1px solid rgba(201, 151, 70, 0.35);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  color: var(--gm-gold-hi);
}
.tsgm-state-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}
.tsgm-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--gm-gold);
  background: linear-gradient(180deg, #c73c32 0%, #992720 100%);
  color: #fff8eb;
  font: 700 13px var(--gm-font);
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 224, 178, 0.3);
  transition: filter .14s ease, transform .1s ease;
}
.tsgm-btn:hover { filter: brightness(1.1); }
.tsgm-btn:active { transform: translateY(1px); }
.tsgm-btn.warn {
  background: linear-gradient(180deg, #d8a248 0%, #a57022 100%);
  border-color: var(--gm-gold-hi);
  color: #1f1208;
}
.tsgm-btn.ghost {
  background: rgba(255, 240, 210, 0.06);
  border-color: rgba(201, 151, 70, 0.45);
  color: var(--gm-cream);
}

.tsgm-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(201, 151, 70, 0.2);
  border-top-color: var(--gm-gold-hi);
  margin: 0 auto 12px;
  animation: tsgm-spin .75s linear infinite;
}
@keyframes tsgm-spin { to { transform: rotate(360deg); } }

@media (max-width: 1440px) {
  .tsgm-shell {
    width: min(1360px, 92vw);
    height: min(860px, 90vh);
  }
}

@media (max-width: 760px) {
  .tsgm-fab { top: 54px; right: 8px; padding: 5px 10px 5px 6px; }
  .tsgm-fab-text { max-width: 112px; }
  .tsgm-font-bar { top: 96px; right: 8px; }
  .tsgm-shell,
  .tsgm-backdrop.dock-side .tsgm-shell {
    width: 98vw;
    height: 95vh;
    border-radius: 10px;
  }
}
