:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #f4f7fb;
  background: #080b11;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 84% 8%, rgba(37, 217, 155, 0.13), transparent 28rem),
    radial-gradient(circle at 12% 30%, rgba(87, 125, 255, 0.1), transparent 30rem),
    #080b11;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 56px 0 80px;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 34px;
}

.eyebrow,
.step {
  margin: 0 0 9px;
  color: #25d99b;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 760px;
  margin-bottom: 14px;
  font-size: clamp(2.35rem, 6vw, 4.8rem);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

h2 {
  margin-bottom: 0;
  font-size: 1.16rem;
  letter-spacing: -0.02em;
}

.subtitle {
  max-width: 660px;
  margin-bottom: 0;
  color: #9ca8b9;
  line-height: 1.65;
}

.policy-card {
  display: flex;
  min-width: 230px;
  align-items: center;
  gap: 13px;
  padding: 17px 19px;
  border: 1px solid rgba(37, 217, 155, 0.28);
  border-radius: 14px;
  background: rgba(16, 27, 27, 0.72);
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.2);
}

.policy-card strong,
.policy-card small {
  display: block;
}

.policy-card small {
  margin-top: 2px;
  color: #83a99d;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #25d99b;
  box-shadow: 0 0 0 6px rgba(37, 217, 155, 0.09), 0 0 20px #25d99b;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(420px, 1.45fr);
  gap: 18px;
}

.card {
  border: 1px solid #1d2531;
  border-radius: 18px;
  background: rgba(13, 18, 27, 0.88);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(18px);
}

.connection-card,
.stream-card,
.diagnostics-card {
  padding: 24px;
}

.card-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 24px;
}

.badge {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 750;
}

.badge.neutral {
  color: #96a3b5;
  background: #171e28;
}

.badge.online {
  color: #63e9b8;
  background: rgba(37, 217, 155, 0.12);
}

.badge.error {
  color: #ff9898;
  background: rgba(255, 87, 87, 0.12);
}

form,
label {
  display: grid;
}

form {
  gap: 15px;
}

label {
  gap: 7px;
  color: #b8c2d0;
  font-size: 0.82rem;
  font-weight: 650;
}

input,
select {
  width: 100%;
  border: 1px solid #263140;
  border-radius: 10px;
  outline: 0;
  padding: 12px 13px;
  color: #f7f9fc;
  background: #0a0f17;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

select {
  appearance: none;
  padding-right: 38px;
  background-image:
    linear-gradient(45deg, transparent 50%, #7f8da1 50%),
    linear-gradient(135deg, #7f8da1 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 2px),
    calc(100% - 12px) calc(50% - 2px);
  background-repeat: no-repeat;
  background-size: 6px 6px, 6px 6px;
}

input:focus,
select:focus {
  border-color: #25d99b;
  box-shadow: 0 0 0 3px rgba(37, 217, 155, 0.1);
}

.button-row {
  display: flex;
  gap: 10px;
  margin-top: 5px;
}

button.primary,
button.secondary {
  border-radius: 10px;
  padding: 11px 15px;
  font-weight: 750;
}

button.primary {
  border: 1px solid #25d99b;
  color: #04110d;
  background: #25d99b;
}

button.secondary {
  border: 1px solid #2a3544;
  color: #d8dfe8;
  background: #111822;
}

.profile-panel,
.game-panel,
.steam-panel,
.quality-panel,
.capture-panel {
  margin-top: 20px;
  padding: 16px;
  border: 1px solid #202a36;
  border-radius: 13px;
  background: rgba(8, 13, 20, 0.68);
}

.game-panel,
.steam-panel,
.quality-panel,
.capture-panel {
  margin: 0 0 16px;
}

.capture-panel {
  border-color: rgba(37, 217, 155, 0.3);
}

.game-panel {
  border-color: rgba(87, 154, 255, 0.38);
  background:
    linear-gradient(135deg, rgba(87, 154, 255, 0.075), transparent 55%),
    rgba(8, 13, 20, 0.72);
}

.steam-panel {
  border-color: rgba(128, 112, 255, 0.42);
  background:
    linear-gradient(135deg, rgba(104, 88, 255, 0.11), transparent 58%),
    rgba(8, 13, 20, 0.72);
}

.steam-actions {
  flex-wrap: wrap;
  margin-top: 0;
}

.steam-actions button {
  min-width: 132px;
  font-size: 0.76rem;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 13px;
}

.section-heading strong,
.section-heading small {
  display: block;
}

.section-heading strong {
  color: #ecf2f8;
  font-size: 0.88rem;
}

.section-heading small,
.privacy-note,
.quality-message {
  color: #748297;
  font-size: 0.72rem;
  line-height: 1.45;
}

.section-heading small {
  margin-top: 4px;
}

.profile-grid,
.game-profile-grid,
.custom-quality-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.game-profile-grid {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
}

.custom-quality-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 12px;
}

.custom-quality-grid[hidden] {
  display: none;
}

.compact-buttons {
  align-items: center;
  margin-top: 12px;
}

.compact-buttons button {
  font-size: 0.76rem;
}

.text-button.danger {
  color: #d98d8d;
}

.privacy-note {
  display: block;
  margin-top: 9px;
}

.quality-heading {
  align-items: center;
}

.quality-apply {
  flex: 0 0 auto;
  padding: 8px 11px !important;
  font-size: 0.74rem;
}

.quality-message {
  min-height: 1.1em;
  margin: 10px 1px 0;
}

.quality-message.error {
  color: #ff9898;
}

.quality-message.switching {
  color: #63e9b8;
}

.control-settings {
  margin: 0 0 16px;
  border: 1px solid #202a36;
  border-radius: 13px;
  background: rgba(8, 13, 20, 0.68);
}

.control-settings summary {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.control-settings summary::-webkit-details-marker {
  display: none;
}

.control-settings summary strong,
.control-settings summary small {
  display: block;
}

.control-settings summary strong {
  color: #ecf2f8;
  font-size: 0.86rem;
}

.control-settings summary small {
  margin-top: 3px;
  color: #748297;
  font-size: 0.7rem;
}

.control-settings[open] summary {
  border-bottom: 1px solid #202a36;
}

.control-settings-body {
  padding: 15px 16px 16px;
}

.game-control-presets {
  margin-bottom: 15px;
  border: 1px solid rgba(37, 217, 155, 0.2);
  border-radius: 11px;
  padding: 13px;
  background: rgba(37, 217, 155, 0.035);
}

.game-control-preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
  margin-top: 11px;
}

.control-settings-grid,
.binding-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.range-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px;
  align-items: center;
  gap: 10px;
}

.range-control input[type="range"] {
  min-height: 34px;
  border: 0;
  padding: 0;
  accent-color: #25d99b;
  background: transparent;
}

.range-control output {
  color: #63e9b8;
  font-size: 0.74rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.binding-fieldset {
  min-width: 0;
  margin: 15px 0 0;
  border: 1px solid #202a36;
  border-radius: 11px;
  padding: 12px;
}

.binding-fieldset legend {
  padding: 0 6px;
  color: #8997aa;
  font-size: 0.72rem;
  font-weight: 750;
}

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

.binding-grid label {
  font-size: 0.72rem;
}

.binding-grid select {
  min-width: 0;
  padding: 9px 28px 9px 9px;
  font-size: 0.74rem;
  background-position:
    calc(100% - 15px) calc(50% - 2px),
    calc(100% - 9px) calc(50% - 2px);
}

.facts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  margin: 24px 0 0;
  border: 1px solid #202a36;
  border-radius: 12px;
  background: #202a36;
}

.facts div {
  min-width: 0;
  padding: 12px;
  background: #0c121a;
}

.facts dt {
  margin-bottom: 5px;
  color: #718096;
  font-size: 0.67rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.facts dd {
  overflow: hidden;
  margin: 0;
  color: #cbd3de;
  font-size: 0.82rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.facts dd.safe {
  color: #4cdda9;
}

.video-frame {
  position: relative;
  overflow: hidden;
  aspect-ratio: 16 / 9;
  border: 1px solid #25303d;
  border-radius: 13px;
  background: #030507;
}

.video-frame video {
  display: block;
  width: 100%;
  height: 100%;
  outline: 0;
  object-fit: contain;
  object-position: 50% 50%;
}

.video-frame.mobile-input-active {
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.mobile-mode-toggle,
.mobile-focus-button,
.mobile-release-button {
  position: absolute;
  z-index: 8;
  min-width: 44px;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  color: #f7fafc;
  background: rgba(3, 5, 7, 0.8);
  backdrop-filter: blur(8px);
}

.mobile-focus-button {
  top: 50%;
  left: max(8px, env(safe-area-inset-left));
  display: grid;
  width: 44px;
  height: 44px;
  transform: translateY(-50%);
  padding: 0;
  place-items: center;
  border-color: rgba(105, 167, 255, 0.5);
  color: #dbeaff;
  font-size: 1.15rem;
  line-height: 1;
  pointer-events: auto;
  touch-action: manipulation;
}

.mobile-focus-button[hidden] {
  display: none;
}

.mobile-mode-toggle {
  top: 12px;
  left: 12px;
  padding: 8px 12px;
}

.mobile-mode-toggle[aria-pressed="true"] {
  border-color: rgba(37, 217, 155, 0.8);
  color: #74efc0;
  background: rgba(5, 32, 25, 0.9);
}

.mobile-mode-toggle:disabled {
  opacity: 0.72;
  cursor: not-allowed;
}

.mobile-controls {
  --mobile-action-size: clamp(40px, 5.7vw, 54px);
  --mobile-cluster-gap: clamp(8px, 1.4vw, 18px);
  --mobile-stick-size: clamp(112px, 20vw, 172px);
  position: absolute;
  z-index: 6;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  touch-action: none;
}

.mobile-controls[hidden] {
  display: none;
}

/* Hiding the gamepad must not disable the underlying touch layer. Keep the
   transparent trackpad fallback mounted while removing every obstructing
   visual control. */
.mobile-controls.mobile-controls-collapsed .move-stick,
.mobile-controls.mobile-controls-collapsed .camera-stick,
.mobile-controls.mobile-controls-collapsed .mobile-hotbar,
.mobile-controls.mobile-controls-collapsed .mobile-side-actions,
.mobile-controls.mobile-controls-collapsed .mobile-metin2-controller,
.mobile-controls.mobile-controls-collapsed .mobile-xbox-controller,
.mobile-controls.mobile-controls-collapsed .mobile-focus-button,
.mobile-controls.mobile-controls-collapsed .mobile-release-button {
  display: none;
}

.mobile-controls.mobile-controls-collapsed .mobile-touchpad {
  width: 100%;
}

.mobile-controls.mobile-controls-collapsed .mobile-touchpad::after {
  display: none;
}

.mobile-touchpad {
  position: absolute;
  z-index: 1;
  top: 0;
  right: 0;
  width: 62%;
  height: 100%;
  pointer-events: auto;
  touch-action: none;
}

.mobile-touchpad[hidden] {
  display: none;
}

.video-frame.mobile-direct-touch video {
  touch-action: none;
}

.video-frame.mobile-game-zoom video {
  transform: scale(var(--game-scale, 1));
  transform-origin: 50% 50%;
  touch-action: none;
  will-change: transform;
}

.video-frame.mobile-desktop-touch video {
  transform:
    translate3d(
      var(--desktop-translate-x, 0px),
      var(--desktop-translate-y, 0px),
      0
    )
    scale(var(--desktop-scale, 1));
  transform-origin: 50% 50%;
  touch-action: none;
  will-change: transform;
}

.video-frame.mobile-desktop-mode .move-stick,
.video-frame.mobile-desktop-mode .camera-stick,
.video-frame.mobile-desktop-mode .mobile-hotbar,
.video-frame.mobile-desktop-mode .mobile-side-actions,
.video-frame.mobile-desktop-mode .mobile-metin2-controller,
.video-frame.mobile-desktop-mode .mobile-xbox-controller,
.video-frame.mobile-desktop-mode .mobile-focus-button {
  display: none;
}

.video-frame.mobile-desktop-mode .mobile-touchpad {
  width: 100%;
}

.mobile-game-zoom-button {
  position: absolute;
  z-index: 8;
  top: max(64px, calc(env(safe-area-inset-top) + 52px));
  right: max(12px, env(safe-area-inset-right));
  min-width: 72px;
  min-height: 44px;
  border: 1px solid rgba(105, 167, 255, 0.58);
  border-radius: 10px;
  padding: 7px 10px;
  color: #dbeaff;
  background: rgba(7, 20, 39, 0.9);
  font-size: 0.76rem;
  font-weight: 780;
  pointer-events: auto;
  touch-action: manipulation;
}

.mobile-game-zoom-button[hidden] {
  display: none;
}

.control-capability-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  color: #9da9b8;
}

.mobile-touchpad::after {
  position: absolute;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  color: rgba(255, 255, 255, 0.28);
  content: "Wischen: Maus · Tippen: Klick";
  font-size: clamp(0.58rem, 1.5vw, 0.72rem);
  pointer-events: none;
}

.move-stick,
.camera-stick {
  --stick-x: 0px;
  --stick-y: 0px;
  position: absolute;
  z-index: 3;
  bottom: max(22px, env(safe-area-inset-bottom));
  left: max(22px, env(safe-area-inset-left));
  width: var(--mobile-stick-size);
  aspect-ratio: 1;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
}

.move-stick-ring,
.move-stick-knob,
.camera-stick-ring,
.camera-stick-knob {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

.move-stick-ring,
.camera-stick-ring {
  inset: 0;
  border: 2px solid rgba(255, 255, 255, 0.23);
  background:
    radial-gradient(circle, rgba(37, 217, 155, 0.06) 0 26%, transparent 27%),
    rgba(3, 6, 9, 0.46);
  box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.36);
}

.move-stick-knob,
.camera-stick-knob {
  top: 50%;
  left: 50%;
  width: 42%;
  aspect-ratio: 1;
  transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
  border: 2px solid rgba(99, 233, 184, 0.78);
  background: rgba(10, 38, 31, 0.82);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.36);
}

.camera-stick {
  right: max(22px, env(safe-area-inset-right));
  left: auto;
}

.camera-stick-ring {
  border-color: rgba(105, 167, 255, 0.36);
  background:
    radial-gradient(circle, rgba(93, 151, 255, 0.08) 0 26%, transparent 27%),
    rgba(3, 6, 12, 0.5);
}

.camera-stick-knob {
  border-color: rgba(122, 180, 255, 0.82);
  background: rgba(13, 31, 57, 0.86);
}

.camera-stick-direction {
  position: absolute;
  z-index: 1;
  color: rgba(220, 234, 255, 0.68);
  font-size: clamp(0.62rem, 1.45vw, 0.82rem);
  font-weight: 800;
  line-height: 1;
  pointer-events: none;
}

.camera-stick-left {
  top: 50%;
  left: 10%;
  transform: translateY(-50%);
}

.camera-stick-right {
  top: 50%;
  right: 10%;
  transform: translateY(-50%);
}

.camera-stick-up {
  top: 9%;
  left: 50%;
  transform: translateX(-50%);
}

.camera-stick-down {
  bottom: 9%;
  left: 50%;
  transform: translateX(-50%);
}

.camera-stick-center-label {
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(226, 239, 255, 0.82);
  font-size: clamp(0.52rem, 1.2vw, 0.68rem);
  font-weight: 850;
  letter-spacing: 0.04em;
  line-height: 1;
  pointer-events: none;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
}

.camera-stick.neutral-action-active .camera-stick-center-label {
  color: #04110d;
  text-shadow: none;
}

.camera-stick.neutral-action-active .camera-stick-knob {
  border-color: rgba(99, 233, 184, 0.94);
  background: rgba(99, 233, 184, 0.94);
}

.mobile-hotbar {
  position: absolute;
  z-index: 4;
  inset: 0;
  pointer-events: none;
}

.mobile-hotbar-cluster {
  position: absolute;
  bottom: max(22px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: repeat(2, var(--mobile-action-size));
  gap: clamp(5px, 0.8vw, 9px);
  pointer-events: none;
}

.mobile-hotbar-primary {
  left: calc(
    max(22px, env(safe-area-inset-left)) + var(--mobile-stick-size) + var(--mobile-cluster-gap)
  );
}

.mobile-hotbar-function {
  right: calc(
    max(22px, env(safe-area-inset-right)) + var(--mobile-stick-size) + var(--mobile-cluster-gap)
  );
}

.mobile-side-actions {
  position: absolute;
  z-index: 4;
  top: 44%;
  right: max(10px, env(safe-area-inset-right));
  display: grid;
  gap: 8px;
  transform: translateY(-50%);
  pointer-events: none;
}

.mobile-metin2-controller,
.mobile-xbox-controller {
  position: absolute;
  z-index: 3;
  inset: 0;
  pointer-events: none;
}

.mobile-metin2-controller[hidden],
.mobile-xbox-controller[hidden] {
  display: none;
}

/* Xbox/Steam has its own controller surface. None of these controls are
   re-used by the Metin2 hotbar, so changing one layout cannot alter the
   bindings or geometry of the other. The corner arrangement follows the
   familiar Moonlight-style OSC: left stick over D-pad, ABXY over right stick. */
.mobile-xbox-controller {
  --xbox-stick-size: clamp(94px, 16vw, 142px);
  --xbox-dpad-size: clamp(100px, 17vw, 148px);
  --xbox-face-size: clamp(108px, 18vw, 154px);
  --xbox-button-size: clamp(42px, 5.8vw, 54px);
  opacity: 0.7;
}

.xbox-button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid rgba(223, 233, 247, 0.46);
  border-radius: 12px;
  padding: 6px 9px;
  color: #f4f8ff;
  background: rgba(7, 14, 25, 0.84);
  box-shadow: 0 7px 20px rgba(0, 0, 0, 0.34);
  font-size: clamp(0.66rem, 1.5vw, 0.82rem);
  font-weight: 850;
  line-height: 1;
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.xbox-button:disabled {
  opacity: 0.45;
}

.xbox-button.active,
.xbox-button:active {
  transform: scale(0.92);
  border-color: rgba(255, 255, 255, 0.92);
  background: rgba(91, 132, 191, 0.96);
}

.xbox-shoulders {
  position: absolute;
  z-index: 6;
  top: max(12px, env(safe-area-inset-top));
  display: flex;
  gap: clamp(5px, 1vw, 10px);
  pointer-events: none;
}

.xbox-shoulders-left {
  left: max(18px, env(safe-area-inset-left));
}

.xbox-shoulders-right {
  right: max(18px, env(safe-area-inset-right));
}

.xbox-shoulder-button {
  min-width: clamp(52px, 7vw, 76px);
  min-height: 42px;
  border-radius: 13px;
}

.xbox-stick {
  --stick-x: 0px;
  --stick-y: 0px;
  position: absolute;
  z-index: 4;
  width: var(--xbox-stick-size);
  aspect-ratio: 1;
  border-radius: 50%;
  pointer-events: auto;
  touch-action: none;
}

.xbox-left-stick {
  top: max(64px, calc(env(safe-area-inset-top) + 52px));
  left: max(20px, env(safe-area-inset-left));
}

.xbox-right-stick {
  right: max(20px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
}

.xbox-stick-ring,
.xbox-stick-knob {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
}

.xbox-stick-ring {
  inset: 0;
  border: 2px solid rgba(201, 219, 247, 0.42);
  background:
    radial-gradient(circle, rgba(119, 166, 232, 0.1) 0 29%, transparent 30%),
    rgba(3, 8, 16, 0.62);
  box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.48);
}

.xbox-stick-knob {
  top: 50%;
  left: 50%;
  width: 42%;
  aspect-ratio: 1;
  transform: translate(calc(-50% + var(--stick-x)), calc(-50% + var(--stick-y)));
  border: 2px solid rgba(164, 199, 247, 0.84);
  background: rgba(19, 39, 68, 0.92);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.42);
}

.xbox-stick-label {
  position: absolute;
  z-index: 1;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: rgba(229, 239, 255, 0.72);
  font-size: clamp(0.62rem, 1.3vw, 0.76rem);
  font-weight: 900;
  pointer-events: none;
}

.xbox-stick-click {
  position: absolute;
  z-index: 6;
  min-width: 44px;
  min-height: 38px;
  border-radius: 19px;
}

.xbox-left-stick-click {
  top: max(72px, calc(env(safe-area-inset-top) + 60px));
  left: calc(max(20px, env(safe-area-inset-left)) + var(--xbox-stick-size) + 8px);
}

.xbox-right-stick-click {
  right: calc(max(20px, env(safe-area-inset-right)) + var(--xbox-stick-size) + 8px);
  bottom: max(22px, calc(env(safe-area-inset-bottom) + 6px));
}

.xbox-dpad {
  position: absolute;
  z-index: 4;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: max(20px, env(safe-area-inset-left));
  width: var(--xbox-dpad-size);
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(3, 8, 16, 0.34);
  box-shadow: inset 0 0 24px rgba(0, 0, 0, 0.34);
  pointer-events: auto;
  touch-action: none;
}

.xbox-dpad-direction,
.xbox-dpad-center {
  position: absolute;
  display: grid;
  place-items: center;
  width: 34%;
  height: 34%;
  border: 1px solid rgba(210, 226, 248, 0.38);
  color: rgba(235, 243, 255, 0.86);
  background: rgba(12, 24, 42, 0.9);
  font-size: clamp(0.72rem, 1.8vw, 1rem);
  line-height: 1;
  pointer-events: none;
}

.xbox-dpad-up {
  top: 0;
  left: 33%;
  border-radius: 11px 11px 3px 3px;
}

.xbox-dpad-right {
  top: 33%;
  right: 0;
  border-radius: 3px 11px 11px 3px;
}

.xbox-dpad-down {
  bottom: 0;
  left: 33%;
  border-radius: 3px 3px 11px 11px;
}

.xbox-dpad-left {
  top: 33%;
  left: 0;
  border-radius: 11px 3px 3px 11px;
}

.xbox-dpad-center {
  top: 33%;
  left: 33%;
  border-radius: 4px;
}

.xbox-dpad-direction.active {
  border-color: rgba(255, 255, 255, 0.94);
  color: #07111f;
  background: rgba(165, 201, 250, 0.96);
}

.xbox-face-buttons {
  position: absolute;
  z-index: 5;
  top: max(60px, calc(env(safe-area-inset-top) + 48px));
  right: max(18px, env(safe-area-inset-right));
  width: var(--xbox-face-size);
  aspect-ratio: 1;
  pointer-events: none;
}

.xbox-face-button {
  position: absolute;
  width: var(--xbox-button-size);
  min-width: var(--xbox-button-size);
  height: var(--xbox-button-size);
  min-height: var(--xbox-button-size);
  border-radius: 50%;
  padding: 0;
  font-size: clamp(0.8rem, 2vw, 1.08rem);
}

.xbox-face-y,
.xbox-face-a {
  left: 50%;
  transform: translateX(-50%);
}

.xbox-face-y { top: 0; border-color: rgba(255, 213, 74, 0.9); color: #ffe27c; }
.xbox-face-a { bottom: 0; border-color: rgba(80, 220, 129, 0.9); color: #72ee9c; }
.xbox-face-x { top: 50%; left: 0; transform: translateY(-50%); border-color: rgba(75, 161, 255, 0.9); color: #83bdff; }
.xbox-face-b { top: 50%; right: 0; transform: translateY(-50%); border-color: rgba(255, 92, 92, 0.9); color: #ff9292; }
.xbox-face-y.active, .xbox-face-y:active { transform: translateX(-50%) scale(0.92); background: rgba(177, 137, 12, 0.95); }
.xbox-face-a.active, .xbox-face-a:active { transform: translateX(-50%) scale(0.92); background: rgba(22, 139, 68, 0.95); }
.xbox-face-x.active, .xbox-face-x:active { transform: translateY(-50%) scale(0.92); background: rgba(18, 92, 171, 0.95); }
.xbox-face-b.active, .xbox-face-b:active { transform: translateY(-50%) scale(0.92); background: rgba(164, 35, 35, 0.95); }

.xbox-center-buttons {
  position: absolute;
  z-index: 6;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.5vw, 14px);
  transform: translateX(-50%);
  pointer-events: none;
}

.xbox-system-button {
  min-width: 46px;
  min-height: 40px;
  border-radius: 20px;
  font-size: 0.9rem;
}

.xbox-guide-button {
  width: 48px;
  min-width: 48px;
  height: 48px;
  min-height: 48px;
  border-radius: 50%;
  border-color: rgba(143, 186, 247, 0.72);
  color: #cfe4ff;
  font-size: 1.15rem;
}

.video-frame.mobile-xbox-layout .mobile-release-button {
  right: auto;
  left: 50%;
  transform: translateX(-50%);
}

/* While the dedicated Xbox surface is visible, its own release button is the
   mobile toggle. Keep the remaining fullscreen utility in the otherwise free
   top-center strip instead of covering shoulders, triggers or ABXY. */
.video-frame.mobile-xbox-controller-visible .mobile-mode-toggle {
  display: none;
}

.video-frame.mobile-xbox-controller-visible .mobile-release-button {
  left: calc(50% - 30px);
}

.video-frame.mobile-xbox-controller-visible .fullscreen-toggle {
  top: max(12px, env(safe-area-inset-top));
  right: auto;
  bottom: auto;
  left: calc(50% + 30px);
  width: 40px;
  min-width: 40px;
  height: 38px;
  min-height: 38px;
}

.mobile-action-button {
  min-width: 44px;
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 12px;
  padding: 6px;
  color: #f7fafc;
  background: rgba(8, 13, 20, 0.72);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.28);
  pointer-events: auto;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.mobile-hotbar-button {
  aspect-ratio: 1;
  font-size: clamp(0.68rem, 1.5vw, 0.86rem);
  font-weight: 780;
}

.mobile-pointer-click-button {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  min-height: 38px;
  border-radius: 10px;
  padding: 5px 8px;
  color: rgba(239, 246, 255, 0.92);
  background: rgba(8, 13, 20, 0.78);
  font-size: clamp(0.64rem, 1.45vw, 0.8rem);
  font-weight: 820;
  letter-spacing: 0.03em;
}

.mobile-pointer-click-button[hidden] {
  display: none;
}

#mobileLeftClickButton:active {
  transform: scale(0.96);
  border-color: rgba(99, 233, 184, 0.96);
  color: #04110d;
  background: rgba(99, 233, 184, 0.94);
}

#mobileRightClickButton:active {
  transform: scale(0.96);
  border-color: rgba(122, 180, 255, 0.98);
  color: #06101f;
  background: rgba(122, 180, 255, 0.94);
}

.mobile-side-button {
  min-width: clamp(44px, 5.7vw, 54px);
  min-height: clamp(44px, 5.7vw, 54px);
  border-radius: 50%;
  color: #dbeaff;
  background: rgba(13, 31, 57, 0.78);
  font-weight: 820;
}

.mobile-action-button.active {
  transform: scale(0.93);
  border-color: #63e9b8;
  color: #04110d;
  background: rgba(99, 233, 184, 0.92);
}

.mobile-release-button {
  top: max(12px, env(safe-area-inset-top));
  left: 50%;
  min-height: 38px;
  transform: translateX(-50%);
  padding: 6px 11px;
  border-color: rgba(255, 136, 136, 0.42);
  color: #ffc0c0;
  font-size: 0.7rem;
  pointer-events: auto;
  touch-action: manipulation;
}

/* The virtual gamepad is 30% more transparent so the game UI remains
   readable underneath it without weakening its touch targets. */
.video-frame:not(.mobile-desktop-mode) .move-stick,
.video-frame:not(.mobile-desktop-mode) .camera-stick,
.video-frame:not(.mobile-desktop-mode) .mobile-hotbar-cluster,
.video-frame:not(.mobile-desktop-mode) .mobile-side-actions {
  opacity: 0.7;
}

/* Utility controls are intentionally much quieter than the gamepad. They
   become clear while hovered, pressed or keyboard-focused. */
.video-frame .mobile-mode-toggle,
.video-frame .mobile-focus-button,
.video-frame .mobile-release-button,
.video-frame .mobile-game-zoom-button,
.video-frame .fullscreen-toggle {
  opacity: 0.32;
  transition: opacity 120ms ease;
}

.video-frame .mobile-mode-toggle:focus-visible,
.video-frame .mobile-mode-toggle:active,
.video-frame .mobile-focus-button:focus-visible,
.video-frame .mobile-focus-button:active,
.video-frame .mobile-release-button:focus-visible,
.video-frame .mobile-release-button:active,
.video-frame .mobile-game-zoom-button:focus-visible,
.video-frame .mobile-game-zoom-button:active,
.video-frame .fullscreen-toggle:focus-visible,
.video-frame .fullscreen-toggle:active {
  opacity: 0.88;
}

@media (hover: hover) {
  .video-frame .mobile-mode-toggle:hover,
  .video-frame .mobile-focus-button:hover,
  .video-frame .mobile-release-button:hover,
  .video-frame .mobile-game-zoom-button:hover,
  .video-frame .fullscreen-toggle:hover {
    opacity: 0.88;
  }
}

.video-frame video:focus {
  box-shadow: inset 0 0 0 2px rgba(37, 217, 155, 0.7);
}

.playback-resume {
  position: absolute;
  z-index: 9;
  top: 50%;
  left: 50%;
  min-width: 0;
  padding: 9px 13px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(37, 217, 155, 0.72);
  border-radius: 9px;
  color: #f7fafc;
  background: rgba(3, 10, 10, 0.9);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.42);
  cursor: pointer;
}

.playback-resume:hover,
.playback-resume:focus-visible {
  border-color: #63e9b8;
  background: rgba(10, 32, 27, 0.96);
}

.playback-resume[hidden] {
  display: none;
}

.video-frame:fullscreen,
.video-frame.viewport-fullscreen {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  border: 0;
  border-radius: 0;
  aspect-ratio: auto;
  background: #000;
}

.video-frame.viewport-fullscreen {
  position: fixed;
  z-index: 1000;
  inset: 0;
}

body.stream-fullscreen {
  overflow: hidden;
  overscroll-behavior: none;
}

/* `backdrop-filter` makes a fixed descendant use the card as its containing
   block in Chromium/WebKit. Remove it only for the CSS fullscreen fallback so
   inset:0 is measured against the viewport on browsers without Fullscreen API. */
body.stream-fullscreen .stream-card {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.fullscreen-toggle {
  position: absolute;
  z-index: 9;
  right: 12px;
  bottom: 12px;
  display: grid;
  width: 44px;
  height: 44px;
  padding: 0;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 8px;
  color: #f7fafc;
  background: rgba(3, 5, 7, 0.78);
  backdrop-filter: blur(8px);
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
}

.fullscreen-toggle:hover {
  border-color: rgba(37, 217, 155, 0.7);
  background: rgba(10, 24, 22, 0.9);
}

.fullscreen-toggle:disabled {
  display: none;
}

.system-volume-control {
  display: flex;
  width: 100%;
  min-height: 42px;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  padding: 8px 10px;
  border: 1px solid #202a36;
  border-radius: 12px;
  color: #f7fafc;
  background: rgba(8, 13, 20, 0.78);
  opacity: 1;
  pointer-events: auto;
  touch-action: manipulation;
}

.system-volume-control[hidden] {
  display: none;
}

.system-volume-label {
  flex: 0 0 auto;
  margin-right: 4px;
  color: #aeb9c7;
  font-size: 0.76rem;
  letter-spacing: 0.02em;
}

.system-volume-control button {
  display: grid;
  width: 34px;
  min-width: 34px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  place-items: center;
  border-radius: 7px;
  font-size: 1rem;
  line-height: 1;
}

.system-volume-control input[type="range"] {
  width: auto;
  min-width: 82px;
  flex: 1 1 180px;
  min-height: 32px;
  margin: 0;
  accent-color: #63e9b8;
}

.system-volume-control output {
  min-width: 3.2em;
  color: #d9e6ee;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.system-volume-control.is-muted {
  border-color: rgba(245, 186, 73, 0.52);
}

.system-volume-control.is-unavailable {
  opacity: 0.26;
}

.video-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  padding: 20px;
  background:
    linear-gradient(135deg, rgba(37, 217, 155, 0.04), transparent 45%),
    repeating-linear-gradient(0deg, transparent, transparent 25px, rgba(255, 255, 255, 0.012) 26px);
  text-align: center;
}

.video-placeholder.hidden {
  display: none;
}

.video-placeholder strong {
  margin: 13px 0 5px;
}

.video-placeholder small {
  color: #6f7d90;
}

.play-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgba(37, 217, 155, 0.32);
  border-radius: 50%;
  color: #25d99b;
  background: rgba(37, 217, 155, 0.08);
}

.stream-actions {
  margin-top: 16px;
}

.input-hint {
  margin: 11px 2px 0;
  color: #738197;
  font-size: 0.76rem;
  line-height: 1.5;
}

.input-hint.active {
  color: #63e9b8;
}

.facts.compact {
  grid-template-columns: repeat(4, 1fr);
  margin-top: 16px;
}

.live-diagnostics {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid #202a36;
  border-radius: 13px;
  background: rgba(8, 13, 20, 0.68);
}

.diagnostics-heading {
  align-items: center;
}

.diagnostics-copy {
  flex: 0 0 auto;
  padding: 8px 11px !important;
  font-size: 0.74rem;
}

.facts.connection-facts {
  margin-top: 0;
}

.telemetry-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin: 10px 0 0;
  padding: 0;
  border: 1px solid #202a36;
  border-radius: 12px;
  background: #202a36;
}

.telemetry-grid div {
  min-width: 0;
  padding: 11px 12px;
  background: #0c121a;
}

.telemetry-grid dt {
  margin-bottom: 5px;
  color: #718096;
  font-size: 0.64rem;
  font-weight: 750;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.telemetry-grid dd {
  overflow: hidden;
  margin: 0;
  color: #d8e0e9;
  font-size: 0.8rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.telemetry-grid dd.safe {
  color: #63e9b8;
}

.telemetry-grid dd.warning {
  color: #f5ba49;
}

.diagnostics-message {
  min-height: 1em;
  margin: 10px 1px 0;
  color: #748297;
  font-size: 0.7rem;
  line-height: 1.45;
}

.diagnostics-message.success {
  color: #63e9b8;
}

.diagnostics-message.error {
  color: #ff9898;
}

.diagnostics-card {
  margin-top: 18px;
}

.diagnostics-card .card-heading {
  margin-bottom: 14px;
}

.text-button {
  border: 0;
  padding: 6px;
  color: #8290a4;
  background: transparent;
}

.event-log {
  display: grid;
  max-height: 250px;
  gap: 8px;
  overflow: auto;
  margin: 0;
  padding: 0;
  list-style: none;
}

.event-log:empty::before {
  content: "Noch keine Ereignisse.";
  padding: 16px 0;
  color: #69778b;
}

.event-log li {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 12px;
  padding: 9px 11px;
  border-radius: 8px;
  color: #b7c1cf;
  background: #0a1018;
  font-family: "Cascadia Code", "SFMono-Regular", Consolas, monospace;
  font-size: 0.76rem;
  line-height: 1.45;
}

.event-log time {
  color: #5d6b7e;
}

@media (max-width: 860px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .policy-card {
    min-width: 0;
  }

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

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

@media (max-width: 520px) {
  .shell {
    width: min(100% - 20px, 1180px);
    padding-top: 30px;
  }

  .connection-card,
  .stream-card,
  .diagnostics-card {
    padding: 18px;
  }

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

  .facts.compact {
    grid-template-columns: repeat(2, 1fr);
  }

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

  .button-row {
    flex-direction: column;
  }

  .profile-grid,
  .game-profile-grid,
  .game-control-preset-grid,
  .custom-quality-grid,
  .control-settings-grid,
  .binding-grid {
    grid-template-columns: 1fr;
  }

  .quality-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .diagnostics-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .quality-apply,
  .diagnostics-copy {
    width: 100%;
  }
}

@media (pointer: coarse) {
  button,
  select,
  input {
    min-height: 44px;
  }

  .fullscreen-toggle {
    top: 12px;
    right: 12px;
    bottom: auto;
  }

  .system-volume-control {
    min-height: 44px;
    gap: 4px;
    padding: 7px 8px;
    flex-wrap: wrap;
  }

  .system-volume-control button {
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
  }

  .system-volume-control input[type="range"] {
    min-width: 110px;
  }

  .system-volume-label {
    width: 100%;
    margin: 0 0 2px;
  }

}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 560px) {
  .mobile-controls {
    --mobile-action-size: clamp(40px, 11vh, 48px);
    --mobile-cluster-gap: 8px;
    --mobile-stick-size: clamp(104px, 28vh, 150px);
  }

  .move-stick,
  .camera-stick {
    bottom: max(14px, env(safe-area-inset-bottom));
  }

  .move-stick {
    left: max(16px, env(safe-area-inset-left));
  }

  .camera-stick {
    right: max(16px, env(safe-area-inset-right));
    left: auto;
  }

  .mobile-action-button {
    min-width: 44px;
    min-height: 44px;
  }

  .mobile-hotbar-cluster {
    bottom: max(14px, env(safe-area-inset-bottom));
  }

  .mobile-hotbar-primary {
    left: calc(
      max(16px, env(safe-area-inset-left)) + var(--mobile-stick-size) + var(--mobile-cluster-gap)
    );
  }

  .mobile-hotbar-function {
    right: calc(
      max(16px, env(safe-area-inset-right)) + var(--mobile-stick-size) + var(--mobile-cluster-gap)
    );
  }

  .mobile-side-actions {
    top: 42%;
  }

  .mobile-touchpad::after {
    display: none;
  }

  .mobile-xbox-controller {
    --xbox-stick-size: clamp(82px, 25vh, 118px);
    --xbox-dpad-size: clamp(86px, 27vh, 124px);
    --xbox-face-size: clamp(94px, 29vh, 132px);
    --xbox-button-size: clamp(40px, 11vh, 48px);
  }

  .xbox-left-stick,
  .xbox-face-buttons {
    top: max(54px, calc(env(safe-area-inset-top) + 44px));
  }

  .xbox-left-stick-click {
    top: max(58px, calc(env(safe-area-inset-top) + 48px));
  }

  .xbox-shoulder-button {
    min-width: 48px;
    min-height: 40px;
  }
}

@media (pointer: coarse) and (orientation: portrait) and (max-width: 520px) {
  .mobile-controls {
    --mobile-action-size: 44px;
    --mobile-cluster-gap: 2px;
    --mobile-stick-size: 84px;
  }

  .video-frame.mobile-input-active:not(:fullscreen):not(.viewport-fullscreen) {
    height: clamp(240px, 72vw, 340px);
    aspect-ratio: auto;
  }

  .move-stick,
  .camera-stick {
    bottom: max(62px, calc(env(safe-area-inset-bottom) + 52px));
  }

  .move-stick {
    left: max(10px, env(safe-area-inset-left));
  }

  .camera-stick {
    right: max(10px, env(safe-area-inset-right));
    left: auto;
  }

  .mobile-hotbar-cluster {
    bottom: max(8px, env(safe-area-inset-bottom));
    gap: 4px;
  }

  .mobile-hotbar-primary {
    left: calc(
      max(10px, env(safe-area-inset-left)) + var(--mobile-stick-size) + var(--mobile-cluster-gap)
    );
  }

  .mobile-hotbar-function {
    right: calc(
      max(10px, env(safe-area-inset-right)) + var(--mobile-stick-size) + var(--mobile-cluster-gap)
    );
  }

  .mobile-action-button {
    min-width: 44px;
    min-height: 44px;
  }

  .mobile-side-actions {
    top: 36%;
    right: max(4px, env(safe-area-inset-right));
    gap: 5px;
  }

  .mobile-xbox-controller {
    --xbox-stick-size: 78px;
    --xbox-dpad-size: 82px;
    --xbox-face-size: 92px;
    --xbox-button-size: 42px;
  }

  .xbox-shoulders {
    top: max(6px, env(safe-area-inset-top));
    gap: 4px;
  }

  .xbox-shoulders-left { left: max(6px, env(safe-area-inset-left)); }
  .xbox-shoulders-right { right: max(6px, env(safe-area-inset-right)); }
  .xbox-shoulder-button { min-width: 44px; min-height: 38px; padding: 5px; }
  .xbox-left-stick { top: max(50px, calc(env(safe-area-inset-top) + 44px)); left: max(8px, env(safe-area-inset-left)); }
  .xbox-face-buttons { top: max(48px, calc(env(safe-area-inset-top) + 42px)); right: max(8px, env(safe-area-inset-right)); }
  .xbox-dpad { bottom: max(54px, calc(env(safe-area-inset-bottom) + 44px)); left: max(8px, env(safe-area-inset-left)); }
  .xbox-right-stick { right: max(8px, env(safe-area-inset-right)); bottom: max(54px, calc(env(safe-area-inset-bottom) + 44px)); }
  .xbox-center-buttons { bottom: max(6px, env(safe-area-inset-bottom)); gap: 6px; }
  .xbox-system-button { min-width: 42px; min-height: 38px; }
  .xbox-guide-button { width: 44px; min-width: 44px; height: 44px; min-height: 44px; }
  .xbox-left-stick-click { top: 50%; left: 39%; }
  .xbox-right-stick-click { right: 39%; bottom: 48%; }
}

@media (pointer: coarse) and (orientation: portrait) and (max-width: 380px) {
  .mobile-controls {
    --mobile-action-size: 40px;
    --mobile-cluster-gap: 0px;
    --mobile-stick-size: 72px;
  }

  .move-stick {
    left: max(4px, env(safe-area-inset-left));
  }

  .camera-stick {
    right: max(4px, env(safe-area-inset-right));
  }

  .mobile-hotbar-primary {
    left: calc(max(4px, env(safe-area-inset-left)) + var(--mobile-stick-size));
  }

  .mobile-hotbar-function {
    right: calc(max(4px, env(safe-area-inset-right)) + var(--mobile-stick-size));
  }

  .mobile-hotbar-button {
    min-width: 40px;
    min-height: 40px;
  }
}

/* Dedicated Xbox handheld ergonomics
   -----------------------------------
   Phones and tablets use edge-anchored hand zones instead of vertically
   stacking two controls in each corner. This keeps every Xbox control inside
   a short thumb arc and, on shallow landscape screens, prevents the stick /
   D-pad and ABXY / right-stick overlaps that the desktop geometry could cause.
   These selectors intentionally never address the separate Metin2 surface. */
@media (any-pointer: coarse) {
  .mobile-xbox-controller {
    --xbox-hit-target: 48px;
    --xbox-zone-gap: 12px;
    opacity: 0.7;
  }

  .mobile-xbox-controller .xbox-button {
    min-width: var(--xbox-hit-target);
    min-height: var(--xbox-hit-target);
  }

  .mobile-xbox-controller .xbox-shoulder-button {
    min-width: 52px;
    min-height: var(--xbox-hit-target);
    padding: 7px 10px;
  }

  .mobile-xbox-controller .xbox-stick-click,
  .mobile-xbox-controller .xbox-system-button {
    width: var(--xbox-hit-target);
    min-width: var(--xbox-hit-target);
    height: var(--xbox-hit-target);
    min-height: var(--xbox-hit-target);
    padding: 0;
  }

  .mobile-xbox-controller .xbox-guide-button {
    width: 52px;
    min-width: 52px;
    height: 52px;
    min-height: 52px;
  }

  .video-frame.mobile-xbox-controller-visible .mobile-release-button {
    width: 48px;
    min-width: 48px;
    height: 48px;
    min-height: 48px;
    overflow: hidden;
    padding: 0;
    font-size: 0;
    white-space: nowrap;
  }

  .video-frame.mobile-xbox-controller-visible .mobile-release-button::before {
    content: "\00d7";
    font-size: 1.05rem;
    line-height: 1;
  }

  .video-frame.mobile-xbox-controller-visible .fullscreen-toggle {
    width: 48px;
    min-width: 48px;
    height: 48px;
    min-height: 48px;
    padding: 0;
  }
}

/* Xbox handheld: phone landscape. The most frequently used controls sit at
   the outside edges; secondary controls sit slightly above and inward in the
   same compact thumb band. This mirrors how the device is held with two thumbs. */
@media (any-pointer: coarse) and (orientation: landscape) and (max-height: 560px) {
  .mobile-xbox-controller {
    --xbox-stick-size: clamp(90px, 27vh, 112px);
    --xbox-dpad-size: clamp(88px, 25vh, 106px);
    --xbox-face-size: clamp(116px, 31vh, 128px);
    --xbox-button-size: 48px;
    --xbox-zone-gap: clamp(8px, 1.5vw, 14px);
    --xbox-secondary-lift: clamp(40px, 13vh, 54px);
    --xbox-phone-edge: max(16px, env(safe-area-inset-bottom));
  }

  .mobile-xbox-controller .xbox-shoulders {
    top: max(8px, env(safe-area-inset-top));
    gap: 6px;
  }

  .mobile-xbox-controller .xbox-shoulders-left {
    left: max(8px, env(safe-area-inset-left));
  }

  .mobile-xbox-controller .xbox-shoulders-right {
    right: max(8px, env(safe-area-inset-right));
  }

  .mobile-xbox-controller .xbox-shoulder-button {
    min-width: 48px;
  }

  .mobile-xbox-controller .xbox-left-stick {
    top: auto;
    bottom: var(--xbox-phone-edge);
    left: max(16px, env(safe-area-inset-left));
  }

  .mobile-xbox-controller .xbox-dpad {
    bottom: calc(var(--xbox-phone-edge) + var(--xbox-secondary-lift));
    left: calc(
      max(16px, env(safe-area-inset-left)) + var(--xbox-stick-size) + var(--xbox-zone-gap)
    );
  }

  .mobile-xbox-controller .xbox-face-buttons {
    top: auto;
    right: max(16px, env(safe-area-inset-right));
    bottom: var(--xbox-phone-edge);
  }

  .mobile-xbox-controller .xbox-right-stick {
    right: calc(
      max(16px, env(safe-area-inset-right)) + var(--xbox-face-size) + var(--xbox-zone-gap)
    );
    bottom: calc(var(--xbox-phone-edge) + var(--xbox-secondary-lift));
  }

  .mobile-xbox-controller .xbox-left-stick-click {
    top: auto;
    bottom: calc(var(--xbox-phone-edge) + var(--xbox-stick-size) + 8px);
    left: calc(
      max(16px, env(safe-area-inset-left)) + (var(--xbox-stick-size) - var(--xbox-hit-target)) / 2
    );
  }

  .mobile-xbox-controller .xbox-right-stick-click {
    right: calc(
      max(16px, env(safe-area-inset-right)) + var(--xbox-face-size) + var(--xbox-zone-gap) +
      (var(--xbox-stick-size) - var(--xbox-hit-target)) / 2
    );
    bottom: calc(
      var(--xbox-phone-edge) + var(--xbox-secondary-lift) + var(--xbox-stick-size) + 8px
    );
  }

  .mobile-xbox-controller .xbox-center-buttons {
    top: max(8px, env(safe-area-inset-top));
    bottom: auto;
    gap: 6px;
  }

  .video-frame.mobile-xbox-controller-visible .mobile-release-button,
  .video-frame.mobile-xbox-controller-visible .fullscreen-toggle {
    top: auto;
    bottom: max(8px, env(safe-area-inset-bottom));
    transform: none;
  }

  .video-frame.mobile-xbox-controller-visible .mobile-release-button {
    left: calc(50% - 54px);
  }

  .video-frame.mobile-xbox-controller-visible .fullscreen-toggle {
    right: auto;
    left: calc(50% + 6px);
  }
}

@media (any-pointer: coarse) and (orientation: landscape) and (max-height: 560px) and (max-width: 720px) {
  /* A short double tap directly on a stick emits L3/R3. On very small phones
     the duplicate buttons would only lengthen the thumb path and add clutter. */
  .mobile-xbox-controller .xbox-stick-click {
    display: none;
  }
}

/* Xbox handheld: tablet landscape. The same hand-zone model scales up without
   pushing primary controls away from the edges where the device is held. */
@media (any-pointer: coarse) and (orientation: landscape) and (min-height: 561px) {
  .mobile-xbox-controller {
    --xbox-stick-size: clamp(124px, 20vh, 158px);
    --xbox-dpad-size: clamp(116px, 18vh, 144px);
    --xbox-face-size: clamp(132px, 22vh, 160px);
    --xbox-button-size: clamp(50px, 7vh, 56px);
    --xbox-zone-gap: clamp(16px, 2vw, 26px);
    --xbox-secondary-lift: clamp(52px, 7.5vh, 60px);
    --xbox-tablet-edge: max(30px, env(safe-area-inset-bottom));
  }

  .mobile-xbox-controller .xbox-shoulders {
    top: max(18px, env(safe-area-inset-top));
    gap: 10px;
  }

  .mobile-xbox-controller .xbox-shoulders-left {
    left: max(24px, env(safe-area-inset-left));
  }

  .mobile-xbox-controller .xbox-shoulders-right {
    right: max(24px, env(safe-area-inset-right));
  }

  .mobile-xbox-controller .xbox-shoulder-button {
    min-width: clamp(64px, 8vw, 82px);
    min-height: 52px;
  }

  .mobile-xbox-controller .xbox-left-stick {
    top: auto;
    bottom: var(--xbox-tablet-edge);
    left: max(32px, env(safe-area-inset-left));
  }

  .mobile-xbox-controller .xbox-dpad {
    bottom: calc(var(--xbox-tablet-edge) + var(--xbox-secondary-lift));
    left: calc(
      max(32px, env(safe-area-inset-left)) + var(--xbox-stick-size) + var(--xbox-zone-gap)
    );
  }

  .mobile-xbox-controller .xbox-face-buttons {
    top: auto;
    right: max(32px, env(safe-area-inset-right));
    bottom: var(--xbox-tablet-edge);
  }

  .mobile-xbox-controller .xbox-right-stick {
    right: calc(
      max(32px, env(safe-area-inset-right)) + var(--xbox-face-size) + var(--xbox-zone-gap)
    );
    bottom: calc(var(--xbox-tablet-edge) + var(--xbox-secondary-lift));
  }

  .mobile-xbox-controller .xbox-left-stick-click {
    top: auto;
    bottom: calc(var(--xbox-tablet-edge) + var(--xbox-stick-size) + 12px);
    left: calc(
      max(32px, env(safe-area-inset-left)) + (var(--xbox-stick-size) - var(--xbox-hit-target)) / 2
    );
  }

  .mobile-xbox-controller .xbox-right-stick-click {
    right: calc(
      max(32px, env(safe-area-inset-right)) + var(--xbox-face-size) + var(--xbox-zone-gap) +
      (var(--xbox-stick-size) - var(--xbox-hit-target)) / 2
    );
    bottom: calc(
      var(--xbox-tablet-edge) + var(--xbox-secondary-lift) + var(--xbox-stick-size) + 12px
    );
  }

  .mobile-xbox-controller .xbox-center-buttons {
    top: max(18px, env(safe-area-inset-top));
    bottom: auto;
    gap: 10px;
  }

  .video-frame.mobile-xbox-controller-visible .mobile-release-button,
  .video-frame.mobile-xbox-controller-visible .fullscreen-toggle {
    top: auto;
    bottom: max(20px, env(safe-area-inset-bottom));
    transform: none;
  }

  .video-frame.mobile-xbox-controller-visible .mobile-release-button {
    left: calc(50% - 56px);
  }

  .video-frame.mobile-xbox-controller-visible .fullscreen-toggle {
    right: auto;
    left: calc(50% + 8px);
  }
}

/* Xbox handheld: phones in portrait get a taller, controller-specific stage.
   This avoids shrinking or overlapping targets merely to retain 16:9 inside a
   narrow card. Landscape remains the recommended playing orientation. */
@media (any-pointer: coarse) and (orientation: portrait) and (max-width: 600px) {
  .video-frame.mobile-input-active.mobile-xbox-layout:not(:fullscreen):not(.viewport-fullscreen) {
    height: clamp(400px, 112vw, 560px);
    aspect-ratio: auto;
  }

  .mobile-xbox-controller {
    --xbox-stick-size: clamp(90px, 25vw, 110px);
    --xbox-dpad-size: clamp(92px, 25vw, 110px);
    --xbox-face-size: clamp(116px, 30vw, 132px);
    --xbox-button-size: 48px;
    --xbox-portrait-edge: max(10px, env(safe-area-inset-left));
  }

  .mobile-xbox-controller .xbox-shoulders {
    top: max(6px, env(safe-area-inset-top));
    gap: 4px;
  }

  .mobile-xbox-controller .xbox-shoulders-left {
    left: max(6px, env(safe-area-inset-left));
  }

  .mobile-xbox-controller .xbox-shoulders-right {
    right: max(6px, env(safe-area-inset-right));
  }

  .mobile-xbox-controller .xbox-shoulder-button {
    min-width: 48px;
    padding: 6px;
  }

  .mobile-xbox-controller .xbox-left-stick {
    top: max(64px, calc(env(safe-area-inset-top) + 58px));
    bottom: auto;
    left: var(--xbox-portrait-edge);
  }

  .mobile-xbox-controller .xbox-face-buttons {
    top: max(64px, calc(env(safe-area-inset-top) + 58px));
    right: max(10px, env(safe-area-inset-right));
    bottom: auto;
  }

  .mobile-xbox-controller .xbox-dpad {
    bottom: max(12px, env(safe-area-inset-bottom));
    left: var(--xbox-portrait-edge);
  }

  .mobile-xbox-controller .xbox-right-stick {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .mobile-xbox-controller .xbox-left-stick-click {
    top: calc(max(64px, calc(env(safe-area-inset-top) + 58px)) + var(--xbox-stick-size) + 8px);
    bottom: auto;
    left: calc(
      var(--xbox-portrait-edge) + (var(--xbox-stick-size) - var(--xbox-hit-target)) / 2
    );
  }

  .mobile-xbox-controller .xbox-right-stick-click {
    right: calc(
      max(10px, env(safe-area-inset-right)) + (var(--xbox-stick-size) - var(--xbox-hit-target)) / 2
    );
    bottom: calc(max(12px, env(safe-area-inset-bottom)) + var(--xbox-stick-size) + 8px);
  }

  .mobile-xbox-controller .xbox-center-buttons {
    top: 50%;
    bottom: auto;
    gap: 6px;
    transform: translate(-50%, -50%);
  }

  .video-frame.mobile-xbox-controller-visible .mobile-release-button,
  .video-frame.mobile-xbox-controller-visible .fullscreen-toggle {
    top: auto;
    bottom: calc(
      max(12px, env(safe-area-inset-bottom)) + clamp(92px, 25vw, 110px) + 12px
    );
    transform: none;
  }

  .video-frame.mobile-xbox-controller-visible .mobile-release-button {
    left: calc(50% - 54px);
  }

  .video-frame.mobile-xbox-controller-visible .fullscreen-toggle {
    right: auto;
    left: calc(50% + 6px);
  }
}

/* Xbox handheld: tablet portrait keeps the same four-corner mental model but
   gives each hand a larger target and more breathing room. */
@media (any-pointer: coarse) and (orientation: portrait) and (min-width: 601px) {
  .video-frame.mobile-input-active.mobile-xbox-layout:not(:fullscreen):not(.viewport-fullscreen) {
    height: clamp(560px, 90vw, 760px);
    aspect-ratio: auto;
  }

  .mobile-xbox-controller {
    --xbox-stick-size: clamp(126px, 19vw, 154px);
    --xbox-dpad-size: clamp(122px, 18vw, 148px);
    --xbox-face-size: clamp(142px, 21vw, 166px);
    --xbox-button-size: clamp(52px, 7vw, 58px);
    --xbox-tablet-portrait-edge: max(28px, env(safe-area-inset-left));
  }

  .mobile-xbox-controller .xbox-shoulders {
    top: max(18px, env(safe-area-inset-top));
    gap: 10px;
  }

  .mobile-xbox-controller .xbox-shoulders-left {
    left: max(24px, env(safe-area-inset-left));
  }

  .mobile-xbox-controller .xbox-shoulders-right {
    right: max(24px, env(safe-area-inset-right));
  }

  .mobile-xbox-controller .xbox-shoulder-button {
    min-width: 64px;
    min-height: 52px;
  }

  .mobile-xbox-controller .xbox-left-stick {
    top: max(90px, calc(env(safe-area-inset-top) + 72px));
    bottom: auto;
    left: var(--xbox-tablet-portrait-edge);
  }

  .mobile-xbox-controller .xbox-face-buttons {
    top: max(90px, calc(env(safe-area-inset-top) + 72px));
    right: max(28px, env(safe-area-inset-right));
    bottom: auto;
  }

  .mobile-xbox-controller .xbox-dpad {
    bottom: max(28px, env(safe-area-inset-bottom));
    left: var(--xbox-tablet-portrait-edge);
  }

  .mobile-xbox-controller .xbox-right-stick {
    right: max(28px, env(safe-area-inset-right));
    bottom: max(28px, env(safe-area-inset-bottom));
  }

  .mobile-xbox-controller .xbox-left-stick-click {
    top: calc(max(90px, calc(env(safe-area-inset-top) + 72px)) + var(--xbox-stick-size) + 12px);
    bottom: auto;
    left: calc(
      var(--xbox-tablet-portrait-edge) + (var(--xbox-stick-size) - var(--xbox-hit-target)) / 2
    );
  }

  .mobile-xbox-controller .xbox-right-stick-click {
    right: calc(
      max(28px, env(safe-area-inset-right)) + (var(--xbox-stick-size) - var(--xbox-hit-target)) / 2
    );
    bottom: calc(max(28px, env(safe-area-inset-bottom)) + var(--xbox-stick-size) + 12px);
  }

  .mobile-xbox-controller .xbox-center-buttons {
    top: 50%;
    bottom: auto;
    gap: 10px;
    transform: translate(-50%, -50%);
  }

  .video-frame.mobile-xbox-controller-visible .mobile-release-button,
  .video-frame.mobile-xbox-controller-visible .fullscreen-toggle {
    top: auto;
    bottom: calc(
      max(28px, env(safe-area-inset-bottom)) + clamp(122px, 18vw, 148px) + 16px
    );
    transform: none;
  }

  .video-frame.mobile-xbox-controller-visible .mobile-release-button {
    left: calc(50% - 56px);
  }

  .video-frame.mobile-xbox-controller-visible .fullscreen-toggle {
    right: auto;
    left: calc(50% + 8px);
  }
}

/* Hub controller layouts are opt-in. Keep this block after every established
   responsive Metin2/Xbox rule: a validated saved layout wins while active and
   removing the class restores the existing fixed controls exactly. */
.video-frame.hub-control-layout-active .mobile-hotbar,
.video-frame.hub-control-layout-active .mobile-hotbar-cluster,
.video-frame.hub-control-layout-active .mobile-side-actions,
.video-frame.hub-control-layout-active .xbox-shoulders,
.video-frame.hub-control-layout-active .xbox-face-buttons,
.video-frame.hub-control-layout-active .xbox-center-buttons {
  display: contents;
}

.video-frame.hub-control-layout-active .mobile-xbox-controller {
  opacity: 1;
}

.video-frame.hub-control-layout-active .hub-control-layout-unused {
  display: none !important;
  pointer-events: none !important;
}

.video-frame.hub-control-layout-active .hub-control-layout-element {
  position: absolute !important;
  z-index: 5;
  top: var(--hub-control-y) !important;
  right: auto !important;
  bottom: auto !important;
  left: var(--hub-control-x) !important;
  width: var(--hub-control-width) !important;
  min-width: 48px !important;
  max-width: none !important;
  height: var(--hub-control-height) !important;
  min-height: 48px !important;
  max-height: none !important;
  grid-column: auto !important;
  margin: 0 !important;
  padding: 0 !important;
  transform: none !important;
  aspect-ratio: auto !important;
  opacity: var(--hub-control-opacity) !important;
  box-sizing: border-box;
}

.video-frame.hub-control-layout-active .mobile-touchpad.hub-control-layout-element {
  z-index: 2;
}
