:root {
  --bg: #090a0d;
  --panel: #15171d;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f5f5f5;
  --accent: #e8a84a;
  --accent-hot: #ffd27a;
  --radius: 22px;
  --font: "Outfit", sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

body {
  background:
    radial-gradient(900px 600px at 10% 0%, rgba(232, 168, 74, 0.12), transparent 55%),
    linear-gradient(160deg, #11131a, var(--bg) 55%);
}

button {
  appearance: none;
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(255, 255, 255, 0.07);
  font: 600 0.9rem var(--font);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button:active,
button.pressed {
  background: rgba(255, 255, 255, 0.18);
  transform: scale(0.97);
}

.layout {
  width: min(1400px, 100%);
  margin: 0 auto;
  padding: 1.25rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 1.1rem;
}

.stage { min-width: 0; }

.screen {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #000;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.screen video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}

.loading {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  background: #000;
  opacity: 1;
  transition: opacity 180ms ease, visibility 180ms ease;
  pointer-events: none;
}

.loading.hidden {
  opacity: 0;
  visibility: hidden;
}

.play {
  width: 4.6rem;
  height: 4.6rem;
  padding: 0 0 0 0.25rem;
  border-color: rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  font-size: 1.65rem;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: auto;
}

.loading.idle .spinner { display: none; }
.loading.connecting .play { display: none; }

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent-hot);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.fullscreen {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  z-index: 6;
  width: 2.7rem;
  height: 2.7rem;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  font-size: 1.1rem;
}

.fullscreen:disabled {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.fullscreen-open {
  overflow: hidden;
}

.screen.fallback-fullscreen,
.screen:fullscreen,
.screen:-webkit-full-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  width: 100vw;
  height: 100dvh;
  aspect-ratio: auto;
  border: 0;
  border-radius: 0;
}

@media (orientation: portrait) {
  .screen.fallback-fullscreen,
  .screen:fullscreen,
  .screen:-webkit-full-screen {
    inset: 50% auto auto 50%;
    width: 100dvh;
    height: 100vw;
    transform: translate(-50%, -50%) rotate(90deg);
  }
}

.quality {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.85rem;
}

.quality button {
  padding: 0.55rem 0.85rem;
  border-radius: 999px;
}

.quality button.active {
  color: #1c1409;
  border-color: transparent;
  background: linear-gradient(135deg, var(--accent-hot), var(--accent));
}

.remote {
  min-height: 390px;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(21, 23, 29, 0.86);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

.power {
  display: block;
  width: 4rem;
  height: 2.8rem;
  margin: 0 auto 1rem;
  border-radius: 14px;
  font-size: 1.15rem;
}

.dpad,
.fullscreen-dpad {
  display: grid;
  grid-template-columns: repeat(3, 4.4rem);
  grid-template-rows: repeat(3, 4.4rem);
  gap: 0.4rem;
  justify-content: center;
}

.key,
.fullscreen-key {
  border-radius: 15px;
  font-size: 1rem;
}

.up { grid-area: 1 / 2; }
.left { grid-area: 2 / 1; }
.ok { grid-area: 2 / 2; }
.right { grid-area: 2 / 3; }
.down { grid-area: 3 / 2; }

.ok {
  color: #1c1409;
  border-color: transparent;
  background: linear-gradient(145deg, var(--accent-hot), var(--accent));
}

.navigation {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-top: 1rem;
}

.navigation button {
  min-height: 2.8rem;
  border-radius: 14px;
}

.fullscreen-remote {
  position: absolute;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  z-index: 7;
  padding: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(8, 9, 12, 0.16);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(10px);
  transition: 180ms ease;
}

.fullscreen-dpad {
  grid-template-columns: repeat(3, 3.25rem);
  grid-template-rows: repeat(3, 3.25rem);
  gap: 0.2rem;
}

.fullscreen-key {
  border-radius: 11px;
  background: rgba(0, 0, 0, 0.22);
  font-size: 0.82rem;
}

.fullscreen-key.ok {
  color: #fff;
  background: rgba(180, 117, 31, 0.42);
}

.fullscreen-remote.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
}

.fullscreen-key.back {
  width: 100%;
  min-height: 2.25rem;
  margin-top: 0.25rem;
}

.screen:fullscreen,
.screen:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    padding: 0.75rem;
  }

  .remote {
    width: min(420px, 100%);
    min-height: 0;
    margin: 0 auto;
  }
}

@media (max-width: 520px) {
  .layout { padding: 0.45rem; }
  .screen { border-radius: 14px; }
  .remote { padding: 0.75rem; }
  .dpad {
    grid-template-columns: repeat(3, 3.7rem);
    grid-template-rows: repeat(3, 3.7rem);
  }
}
