:root {
  --bg-dark: #100c1c;
  --cabinet-bg: #1b1530;
  --cabinet-border: #4a356d;
  --gold: #f5c542;
  --gold-dim: #b5851d;
  --crimson: #b8293d;
  --text: #f3ead3;
  --muted: #b7aacf;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 20% 20%, #241744 0%, transparent 45%),
    radial-gradient(circle at 80% 80%, #2a1333 0%, transparent 45%),
    var(--bg-dark);
  color: var(--text);
  font-family: "Courier New", Courier, monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(10px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.cabinet {
  width: 100%;
  max-width: 980px;
  background: var(--cabinet-bg);
  border: 4px solid var(--cabinet-border);
  border-radius: 12px;
  box-shadow:
    0 20px 60px rgba(0, 0, 0, 0.7),
    inset 0 0 0 2px #2b2049;
  padding: 12px 14px 14px;
}

.cabinet.theater-mode {
  position: fixed;
  inset: 0;
  max-width: none;
  width: 100vw;
  height: 100dvh;
  border-radius: 0;
  border: none;
  z-index: 999;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding:
    max(8px, env(safe-area-inset-top))
    max(10px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom))
    max(10px, env(safe-area-inset-left));
}

.cabinet.theater-mode .screen-frame {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cabinet.theater-mode canvas#game {
  width: auto;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  background: var(--crimson);
  color: #fff6d6;
  border: 2px solid var(--gold);
  font-size: 11px;
  font-weight: bold;
  padding: 3px 6px;
  letter-spacing: 0.8px;
  white-space: nowrap;
}

.brand h1 {
  font-family: Georgia, "Palatino Linotype", "Book Antiqua", serif;
  font-size: clamp(15px, 2.6vw, 21px);
  font-weight: bold;
  letter-spacing: 1px;
  background: linear-gradient(180deg, #fff5b8 0%, #f5c542 55%, #b87c14 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(2px 2px 0 #090612);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.retro-btn {
  background: #2b2049;
  color: var(--text);
  border: 2px solid #664c94;
  border-bottom-width: 4px;
  padding: 6px 10px;
  font-family: inherit;
  font-size: 12px;
  font-weight: bold;
  cursor: pointer;
  border-radius: 4px;
  touch-action: manipulation;
  transition: transform 0.06s ease, background 0.12s ease;
}

.retro-btn:hover {
  background: #3a2b61;
  border-color: var(--gold);
}

.retro-btn:active {
  transform: translateY(2px);
}

.screen-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #070510;
  border: 4px solid #090612;
  box-shadow:
    inset 0 0 0 2px #3c2b5e,
    0 0 24px rgba(120, 72, 220, 0.25);
  border-radius: 6px;
  overflow: hidden;
}

canvas#game {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  outline: none;
  touch-action: none;
}

.controls-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 2px solid #2d214b;
  font-size: 12px;
  color: var(--muted);
}

.key-group {
  display: flex;
  align-items: center;
  gap: 5px;
}

kbd {
  background: #2c2246;
  color: var(--gold);
  border: 1px solid #614b91;
  border-bottom-width: 3px;
  border-radius: 4px;
  padding: 2px 6px;
  font-family: inherit;
  font-size: 11px;
  font-weight: bold;
}

.touch-controls {
  display: none;
  position: absolute;
  inset: auto 0 10px 0;
  padding: 0 12px;
  justify-content: space-between;
  pointer-events: none;
}

.touch-controls.force-show {
  display: flex;
}

@media (hover: none) and (pointer: coarse) {
  .touch-controls {
    display: flex;
  }

  .controls-bar {
    display: none;
  }

  /* Na iPhonu / iPadu na výšku umístit tlačítka čistě pod obrazovku, ať nezakrývají hru */
  @media (orientation: portrait) {
    .screen-frame {
      overflow: visible;
      margin-bottom: 76px;
    }

    .touch-controls {
      bottom: -66px;
      padding: 0 4px;
    }
  }

  /* Na iPhonu na šířku zmenšit horní lištu, aby se hra pohodlně vešla na výšku displeje */
  @media (orientation: landscape) and (max-height: 460px) {
    body {
      padding: 4px env(safe-area-inset-right) 4px env(safe-area-inset-left);
    }

    .cabinet {
      padding: 6px 8px;
      border-width: 2px;
    }

    .topbar {
      margin-bottom: 4px;
    }

    .brand h1 {
      font-size: 14px;
    }

    .retro-btn {
      padding: 3px 7px;
      font-size: 11px;
    }

    .screen-frame {
      max-height: calc(100dvh - 52px);
      width: auto;
      margin: 0 auto;
    }

    .t-btn {
      height: 44px;
      min-width: 52px;
      font-size: 15px;
    }
  }
}

.touch-left,
.touch-right {
  display: flex;
  gap: 10px;
  pointer-events: auto;
}

.t-btn {
  background: rgba(27, 21, 48, 0.78);
  color: var(--gold);
  border: 2px solid rgba(245, 197, 66, 0.78);
  border-radius: 12px;
  min-width: 58px;
  height: 52px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 16px;
  font-weight: bold;
  touch-action: none;
  cursor: pointer;
}

.t-btn.active,
.t-btn:active {
  background: rgba(184, 41, 61, 0.9);
  border-color: #fff199;
}

.screen-frame:fullscreen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
}

.screen-frame:fullscreen canvas#game {
  max-width: 100vw;
  max-height: 100vh;
  width: auto;
  height: 100%;
}
