:root {
  color-scheme: dark;
  --ink: #eaf8ff;
  --muted: #93a9bd;
  --panel: rgba(3, 8, 18, 0.82);
  --panel-border: rgba(116, 232, 255, 0.22);
  --accent: #5eead4;
  --danger: #f43f5e;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #02040b;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  user-select: none;
}

button {
  min-height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  padding: 0 14px;
  background: #101827;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: var(--accent);
  outline: none;
}

button[aria-pressed="true"] {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(76, 201, 240, 0.55);
}

#gameCanvas {
  display: block;
  width: 100vw;
  height: 100vh;
  touch-action: none;
}

#gameCanvas:focus {
  outline: none;
}

.profile-dialog[hidden] {
  display: none;
}

html[data-protocol="file"] #gameCanvas,
html[data-protocol="file"] #gameOverlay,
html[data-protocol="file"] #debugOverlay,
html[data-protocol="file"] #crosshair,
html[data-protocol="file"] #touchLookZone,
html[data-protocol="file"] #touchControls,
html[data-protocol="file"] #profileDialog,
html[data-protocol="file"] #pauseDialog {
  display: none;
}

html[data-protocol="file"] #protocolDialog {
  display: grid;
}

.profile-dialog {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(2, 4, 11, 0.76);
  pointer-events: auto;
}

.profile-card {
  width: min(360px, 100%);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 18px;
  background: rgba(3, 8, 18, 0.96);
  box-shadow: 0 18px 54px rgba(0, 0, 0, 0.46), 0 0 34px rgba(37, 211, 255, 0.08);
}

.profile-card h1 {
  margin: 0 0 14px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1.2;
}

.profile-card p {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.profile-card label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.profile-card input {
  width: 100%;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  padding: 0 12px;
  background: #07111e;
  color: var(--ink);
  font: inherit;
}

.profile-card input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px rgba(76, 201, 240, 0.28);
}

.profile-card button {
  width: 100%;
  margin-top: 12px;
  background: #0f766e;
}

.primary-link {
  display: flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  padding: 0 14px;
  background: #0f766e;
  color: var(--ink);
  font: inherit;
  text-decoration: none;
}

.primary-link:hover,
.primary-link:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.pause-player {
  display: flex;
  gap: 6px;
  align-items: center;
}

.pause-player strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pause-field {
  display: grid;
  gap: 6px;
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.pause-field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  padding: 0 10px;
  background: #07111e;
  color: var(--ink);
  font: inherit;
  text-transform: none;
}

.pause-field select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 2px rgba(76, 201, 240, 0.28);
}

.pause-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.pause-actions button {
  width: 100%;
}

#exitButton {
  border-color: rgba(244, 63, 94, 0.42);
  background: rgba(69, 10, 10, 0.86);
}

.game-overlay {
  position: fixed;
  left: 14px;
  top: 14px;
  z-index: 4;
  display: flex;
  max-width: min(560px, calc(100vw - 28px));
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  border: 1px solid rgba(116, 232, 255, 0.24);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(3, 8, 18, 0.72);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.2;
  pointer-events: none;
}

.selected-color-swatch {
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.72);
  border-radius: 4px;
  background: #2dd4bf;
  box-shadow: 0 0 14px rgba(45, 212, 191, 0.34);
}

.overlay-text,
.overlay-status {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.overlay-status {
  color: var(--muted);
}

.debug-overlay {
  position: fixed;
  left: 14px;
  top: 64px;
  z-index: 4;
  max-width: min(520px, calc(100vw - 28px));
  border: 1px solid rgba(76, 201, 240, 0.34);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgba(2, 6, 12, 0.78);
  color: #c7f9ff;
  pointer-events: none;
}

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

.debug-overlay pre {
  margin: 0;
  overflow: hidden;
  font: 11px/1.35 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

#statusText {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crosshair {
  position: fixed;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  display: none;
}

.crosshair::before,
.crosshair::after {
  content: "";
  position: absolute;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.65);
}

.crosshair::before {
  left: 10px;
  top: 2px;
  width: 2px;
  height: 18px;
}

.crosshair::after {
  left: 2px;
  top: 10px;
  width: 18px;
  height: 2px;
}

body[data-view="firstPerson"] .crosshair {
  display: block;
}

.touch-controls {
  position: fixed;
  inset: auto 14px 14px 14px;
  z-index: 5;
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  pointer-events: none;
}

.touch-look-zone {
  position: fixed;
  inset: 0 0 0 32%;
  z-index: 3;
  display: none;
  touch-action: none;
  pointer-events: auto;
}

.touch-stick,
.touch-actions {
  pointer-events: auto;
  touch-action: none;
}

.touch-stick {
  width: 132px;
  height: 132px;
  display: grid;
  place-items: center;
}

.touch-stick-base {
  position: relative;
  width: 112px;
  height: 112px;
  border: 1px solid rgba(116, 232, 255, 0.24);
  border-radius: 50%;
  background: rgba(3, 8, 18, 0.38);
  box-shadow: inset 0 0 28px rgba(37, 211, 255, 0.08), 0 0 18px rgba(37, 211, 255, 0.06);
}

.touch-stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 50%;
  background: rgba(15, 118, 110, 0.82);
  box-shadow: 0 0 18px rgba(94, 234, 212, 0.2);
  transform: translate(-50%, -50%);
}

.touch-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(58px, auto));
  align-content: end;
  gap: 8px;
}

.touch-controls button {
  min-width: 58px;
  min-height: 48px;
  padding: 0 9px;
  border-color: rgba(116, 232, 255, 0.28);
  background: rgba(3, 8, 18, 0.74);
  box-shadow: 0 0 18px rgba(37, 211, 255, 0.08);
  font-size: 12px;
}

.touch-controls button:active,
.touch-controls button[data-active="true"] {
  border-color: var(--accent);
  background: rgba(15, 118, 110, 0.84);
}

@media (hover: none), (pointer: coarse) {
  .touch-look-zone {
    display: block;
  }

  .touch-controls {
    display: flex;
  }
}

@media (max-width: 860px) {
  .game-overlay {
    left: 10px;
    top: 10px;
    max-width: calc(100vw - 20px);
    gap: 8px;
    font-size: 12px;
  }

  .debug-overlay {
    left: 10px;
    top: 58px;
    max-width: calc(100vw - 20px);
  }
}

@media (hover: none) and (orientation: portrait), (pointer: coarse) and (orientation: portrait) {
  .game-overlay {
    max-width: calc(100vw - 20px);
  }

  .touch-controls {
    inset: auto 10px 10px 10px;
  }

  .touch-stick {
    width: 116px;
    height: 116px;
  }

  .touch-stick-base {
    width: 98px;
    height: 98px;
  }

  .touch-stick-knob {
    width: 42px;
    height: 42px;
  }

  .touch-actions {
    grid-template-columns: repeat(2, minmax(54px, auto));
  }

  .touch-controls button {
    min-width: 54px;
    min-height: 44px;
    font-size: 11px;
  }
}
