:root {
  color-scheme: dark;
  --bg-obsidian: #060913;
  --bg-obsidian-deep: #091021;
  --bg-deck: rgba(9, 15, 30, 0.92);
  --bg-deck-solid: #0a1122;
  --bg-inset: rgba(5, 10, 22, 0.72);
  --gold-bright: #ffe49c;
  --gold: #e4b95d;
  --gold-mid: #c5963a;
  --gold-dim: #7f5d20;
  --border-gold-soft: rgba(228, 185, 93, 0.30);
  --border-gold: rgba(228, 185, 93, 0.56);
  --border-gold-strong: rgba(255, 228, 156, 0.85);
  --cyan: #3ee7ff;
  --cyan-soft: rgba(62, 231, 255, 0.16);
  --text-main: #f3f7ff;
  --text-soft: #cfd9ec;
  --text-muted: #93a4c3;
  --danger: #ff808e;
  --ok: #3ce0a4;
  --font-ui: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-crest: Georgia, "Times New Roman", serif;
}

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

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-obsidian);
  color: var(--text-main);
  font-family: var(--font-ui);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

#game-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  display: grid;
  grid-template-rows: 1fr;
  background: radial-gradient(circle at 50% 20%, #121c38 0%, var(--bg-obsidian) 72%);
}

/* Efficient background processing: allow browser to skip rendering when offscreen */
.unity-stage {
  position: relative;
  width: 100%;
  height: 100%;
  content-visibility: auto;
  contain-intrinsic-size: auto none auto 720px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#unity-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #05070e;
  outline: none;
  touch-action: none;
}

/* ============================================================================
   1. Flush Top-Center Soul-Land Notch ("Hồn Đạo Ấn") — Default Collapsed
      Ultra-slim 28px imperial-gold & obsidian tab flush with the top bezel so
      it NEVER blocks in-game top-left Avatar, top-right Event icons, Minimap,
      right Skill rail, or bottom Chat bar. Horizontally draggable!
   ============================================================================ */
.hud-chrome {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  left: 0;
  right: 0;
  z-index: 45;
  pointer-events: none;
}

.hud-notch-wrap {
  position: absolute;
  top: 0;
  left: var(--hud-x, 50%);
  transform: translateX(-50%);
  pointer-events: auto;
  touch-action: none;
}

.soul-notch {
  position: relative;
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 13px 1px 10px;
  border: 1px solid var(--border-gold);
  border-top: 0;
  border-radius: 0 0 14px 14px;
  background:
    linear-gradient(180deg, rgba(20, 30, 56, 0.88) 0%, rgba(8, 13, 27, 0.90) 100%);
  color: var(--text-main);
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  backdrop-filter: blur(14px) saturate(1.18);
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.56),
    0 1px 0 rgba(255, 228, 156, 0.22) inset,
    0 0 16px rgba(228, 185, 93, 0.14);
  opacity: 0.84;
  anchor-name: --soul-notch-anchor;
}

/* Delicate imperial-gold bottom filigree highlight line */
.soul-notch::after {
  content: "";
  position: absolute;
  left: 16%;
  right: 16%;
  bottom: -1px;
  height: 2px;
  border-radius: 99px;
  background: linear-gradient(90deg, transparent, var(--gold-bright), var(--cyan), var(--gold-bright), transparent);
  opacity: 0.85;
  pointer-events: none;
}

.soul-notch:hover,
.soul-notch:focus-visible,
.hud-notch-wrap.is-open .soul-notch,
.hud-notch-wrap.is-dragging .soul-notch {
  opacity: 1;
  border-color: var(--border-gold-strong);
  box-shadow:
    0 8px 26px rgba(0, 0, 0, 0.68),
    0 0 22px rgba(228, 185, 93, 0.28),
    0 0 10px rgba(62, 231, 255, 0.18);
}

.hud-notch-wrap.is-dragging .soul-notch {
  cursor: grabbing;
}

.notch-crest {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(255, 228, 156, 0.65);
  background: radial-gradient(circle at 35% 30%, #ffe69e 0%, #c6912e 60%, #4e350d 100%);
  color: #160e03;
  font-family: var(--font-crest);
  font-size: 11px;
  font-weight: 800;
  box-shadow: 0 0 8px rgba(228, 185, 93, 0.45);
}

.notch-fps {
  font-variant-numeric: tabular-nums;
  color: var(--gold-bright);
}

.notch-bg {
  font-variant-numeric: tabular-nums;
  color: var(--text-soft);
  font-weight: 600;
}

.notch-chevron {
  color: var(--gold);
  margin-left: 1px;
}

.hud-notch-wrap.is-open .notch-chevron {
  transform: rotate(180deg);
}

.pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 8px var(--cyan);
  flex-shrink: 0;
}

.pill-dot.is-done {
  background: var(--ok);
  box-shadow: 0 0 8px var(--ok);
}

.pill-dot.is-paused {
  background: var(--gold);
  box-shadow: none;
}

.pill-sep {
  opacity: 0.42;
  color: var(--gold);
}

/* ============================================================================
   2. Ornate Soul-Land Command Deck (Native Popover + Top-Layer Transitions)
   ============================================================================ */
@supports not selector(:popover-open) {
  [popover]:not(.\:popover-open) {
    display: none;
  }
}

.soul-deck {
  position: fixed;
  pointer-events: auto;
  width: min(392px, calc(100vw - 20px));
  padding: 15px 15px 14px;
  border-radius: 16px;
  border: 1px solid var(--border-gold);
  background:
    radial-gradient(280px 140px at 14% 0%, rgba(228, 185, 93, 0.14), transparent 68%),
    radial-gradient(260px 140px at 88% 100%, rgba(62, 231, 255, 0.12), transparent 70%),
    var(--bg-deck);
  color: var(--text-main);
  backdrop-filter: blur(20px) saturate(1.25);
  box-shadow:
    0 24px 64px rgba(0, 0, 0, 0.78),
    0 0 0 1px rgba(255, 228, 156, 0.14) inset,
    0 0 34px rgba(228, 185, 93, 0.14);
  overflow: hidden;
  opacity: 0;
  transition-property: opacity, transform, display, overlay;
  transition-duration: 0.22s;
  transition-timing-function: cubic-bezier(0.22, 1, 0.36, 1);
  transition-behavior: allow-discrete;
}

@media (prefers-reduced-motion: no-preference) {
  .soul-deck {
    transform: translateY(-8px) scale(0.97);
  }
}

.soul-deck:is(:popover-open, .\:popover-open):where(:not([data-closing])) {
  display: block;
  opacity: 1;

  @starting-style {
    opacity: 0;
  }

  @media (prefers-reduced-motion: no-preference) {
    transform: translateY(0) scale(1);

    @starting-style {
      transform: translateY(-8px) scale(0.97);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .soul-deck {
    transition-duration: 0.1s;
  }
}

@supports (position-area: block-end) {
  .soul-deck {
    position-anchor: --soul-notch-anchor;
    inset: auto;
    margin: 8px 0 0 0;
    position-area: block-end;
    position-try-fallbacks: flip-inline, flip-block;
  }
}

@supports not (position-area: block-end) {
  .soul-deck {
    inset: auto;
    margin: 0;
  }
}

/* Golden Soul-Tech filigree top energy bar inside panel */
.deck-ornament {
  position: absolute;
  top: 0;
  left: 12%;
  right: 12%;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), var(--gold-bright), var(--cyan), var(--gold), transparent);
  pointer-events: none;
}

.deck-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 11px;
  margin-bottom: 11px;
  border-bottom: 1px solid rgba(228, 185, 93, 0.2);
}

.deck-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.deck-seal {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  border: 1px solid rgba(255, 228, 156, 0.7);
  background: linear-gradient(145deg, #fbe29b 0%, #c89432 62%, #5e4010 100%);
  color: #140d02;
  font-family: var(--font-crest);
  font-size: 16px;
  font-weight: 800;
  box-shadow: 0 0 14px rgba(228, 185, 93, 0.32);
  flex-shrink: 0;
}

.deck-titles {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.deck-titles strong {
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--gold-bright);
  white-space: nowrap;
}

.deck-titles small {
  font-size: 10.5px;
  color: var(--text-muted);
  white-space: nowrap;
}

.deck-quick-actions {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.deck-icon-btn,
.deck-collapse-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 30px;
  border-radius: 9px;
  border: 1px solid rgba(228, 185, 93, 0.28);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-soft);
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
}

.deck-icon-btn {
  width: 30px;
  padding: 0;
}

.deck-collapse-btn {
  padding: 0 10px;
  color: var(--gold-bright);
  border-color: rgba(228, 185, 93, 0.44);
  background: rgba(228, 185, 93, 0.12);
}

.deck-icon-btn[aria-pressed="true"] {
  border-color: rgba(255, 128, 142, 0.65);
  background: rgba(255, 128, 142, 0.16);
  color: var(--danger);
}

#btn-mute[aria-pressed="true"] .vol-wave {
  opacity: 0.18;
}

/* Segmented Controls (FPS + Quality) */
.deck-controls {
  display: grid;
  gap: 9px;
  margin-bottom: 12px;
}

.deck-row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.deck-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

.seg-group {
  display: grid;
  gap: 4px;
  padding: 3px;
  border-radius: 11px;
  border: 1px solid rgba(228, 185, 93, 0.2);
  background: var(--bg-inset);
}

.seg-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.seg-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.tb-btn {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 6px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

/* Style toggled state strictly from ARIA attribute so visual & accessible states never diverge */
.tb-btn[aria-pressed="true"] {
  background: linear-gradient(145deg, #f6d57f 0%, #d49f3a 100%);
  color: #150e02;
  border-color: rgba(255, 244, 205, 0.9);
  box-shadow:
    0 2px 10px rgba(228, 185, 93, 0.36),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

/* Telemetry & Background Download Section */
.deck-telemetry {
  padding: 11px 12px;
  border-radius: 12px;
  border: 1px solid rgba(62, 231, 255, 0.18);
  background: rgba(5, 11, 24, 0.64);
}

.pop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}

.pop-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--gold-bright);
}

.pop-badge {
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--cyan);
}

.pop-bar-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
  margin-bottom: 7px;
}

.pop-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--cyan), var(--gold-bright));
  box-shadow: 0 0 10px rgba(62, 231, 255, 0.45);
}

.pop-meta {
  margin: 0 0 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.4;
}

.pop-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 7px 6px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.07);
  margin-bottom: 10px;
  text-align: center;
}

.pop-metrics .m-label {
  display: block;
  font-size: 10px;
  color: var(--text-muted);
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pop-metrics strong {
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-main);
}

.pop-actions {
  display: flex;
  gap: 6px;
}

.pop-btn {
  flex: 1;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--border-gold-soft);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
  font-family: var(--font-ui);
  font-size: 11.5px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.pop-btn.is-paused {
  background: rgba(228, 185, 93, 0.2);
  border-color: var(--gold);
  color: var(--gold-bright);
}

.pop-btn-subtle {
  flex: 0 0 auto;
  border-color: rgba(62, 231, 255, 0.34);
  color: var(--cyan);
}

.pop-btn-danger {
  flex: 0 0 auto;
  border-color: rgba(255, 128, 142, 0.38);
  color: var(--danger);
}

/* Focus indicators & Hover feedback */
.soul-notch:focus-visible,
.deck-icon-btn:focus-visible,
.deck-collapse-btn:focus-visible,
.tb-btn:focus-visible,
.pop-btn:focus-visible,
.ime-input:focus-visible,
.ime-submit:focus-visible,
.ime-cancel:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

@media (hover: hover) {
  .tb-btn:hover:not([aria-pressed="true"]),
  .deck-icon-btn:hover,
  .pop-btn:hover {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.11);
    border-color: rgba(228, 185, 93, 0.45);
  }

  .deck-collapse-btn:hover {
    background: rgba(228, 185, 93, 0.24);
    border-color: var(--gold-bright);
  }
}

@media (prefers-reduced-motion: no-preference) {
  .soul-notch,
  .notch-chevron,
  .tb-btn,
  .deck-icon-btn,
  .deck-collapse-btn,
  .pop-btn,
  .boot-progress-fill,
  .pop-bar-fill {
    transition:
      background-color 150ms ease,
      color 150ms ease,
      border-color 150ms ease,
      opacity 160ms ease,
      transform 180ms cubic-bezier(0.22, 1, 0.36, 1),
      box-shadow 160ms ease,
      width 200ms ease;
  }
}

@media (pointer: coarse) {
  .soul-notch {
    height: 34px;
    padding: 0 14px 1px 11px;
    font-size: 12px;
  }
  .tb-btn,
  .deck-icon-btn,
  .deck-collapse-btn,
  .pop-btn {
    min-height: 40px;
    font-size: 13px;
  }
  .deck-icon-btn {
    width: 40px;
  }
}

/* Hint tooltips (progressive enhancement when interestfor + position-area supported) */
[popover="hint"] {
  padding: 5px 9px;
  border-radius: 8px;
  border: 1px solid var(--border-gold-soft);
  background: #0a1020;
  color: var(--text-main);
  font-size: 11.5px;
}

@supports (position-area: block-end) {
  [popover="hint"] {
    inset: auto;
    margin-block-start: 6px;
    position-area: block-end;
    position-try-fallbacks: flip-block;
  }
}

[interestfor] {
  interest-delay: 0.25s 0.1s;
}

/* ============================================================================
   3. Boot Splash Overlay & Native HTML5 Vietnamese IME Bar
   ============================================================================ */
.boot-overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 35%, rgba(22, 36, 74, 0.92), rgba(6, 9, 19, 0.98) 70%);
}

.boot-overlay[hidden] {
  display: none;
}

.boot-card {
  width: min(460px, 100%);
  padding: 28px 24px;
  border-radius: 18px;
  border: 1px solid var(--border-gold);
  background: rgba(10, 15, 29, 0.93);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.76), 0 0 42px rgba(228, 185, 93, 0.14);
  text-align: center;
}

.boot-emblem {
  display: inline-grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 10px;
  border-radius: 14px;
  border: 1px solid var(--border-gold-strong);
  background: linear-gradient(145deg, #fbe29b 0%, #c89432 62%, #5e4010 100%);
  color: #140d02;
  font-family: var(--font-crest);
  font-size: 28px;
  font-weight: 800;
  box-shadow: 0 0 26px rgba(228, 185, 93, 0.38);
}

.boot-title {
  margin: 0 0 4px;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--gold-bright);
}

.boot-subtitle {
  margin: 0 0 20px;
  font-size: 13px;
  color: var(--text-muted);
}

.boot-progress-track {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.09);
  overflow: hidden;
  border: 1px solid rgba(228, 185, 93, 0.22);
}

.boot-progress-fill {
  height: 100%;
  width: 4%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--gold-mid), var(--gold-bright), var(--cyan));
}

.boot-meta-row {
  display: flex;
  justify-content: space-between;
  margin-top: 9px;
  font-size: 12px;
  color: var(--text-main);
}

.boot-tip {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.boot-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 128, 142, 0.14);
  border: 1px solid rgba(255, 128, 142, 0.45);
  color: #ffd0d6;
  font-size: 12px;
}

.ime-overlay {
  position: fixed;
  inset: auto 0 max(18px, env(safe-area-inset-bottom)) 0;
  z-index: 60;
  display: flex;
  justify-content: center;
  padding: 0 14px;
  pointer-events: none;
}

.ime-overlay[hidden] {
  display: none;
}

.ime-bar {
  pointer-events: auto;
  width: min(560px, 100%);
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 14px;
  background: rgba(10, 16, 30, 0.96);
  border: 1px solid var(--border-gold);
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.7);
}

.ime-input {
  flex: 1;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid rgba(228, 185, 93, 0.28);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  font-size: 15px;
}

.ime-submit, .ime-cancel {
  min-width: 56px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid var(--border-gold-soft);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.ime-submit {
  background: linear-gradient(145deg, #f6d57f 0%, #d49f3a 100%);
  color: #150e02;
  border-color: var(--gold-bright);
}

.ime-cancel {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

@media (forced-colors: active) {
  .soul-notch,
  .soul-deck,
  .tb-btn,
  .deck-icon-btn,
  .deck-collapse-btn,
  .pop-btn {
    border-color: ButtonText;
    box-shadow: none;
  }
  .tb-btn[aria-pressed="true"] {
    background: Highlight;
    color: HighlightText;
    border-color: Highlight;
  }
}
