:root {
  color-scheme: dark;
  --bg: #071018;
  --panel: #101b24;
  --panel-2: #142636;
  --line: rgba(160, 213, 238, .26);
  --text: #ecf8ff;
  --muted: #93aaba;
  --good: #58d68d;
  --warn: #ffd166;
  --bad: #ff5b5b;
  --accent: #35c8ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: radial-gradient(circle at top left, #12304a, var(--bg) 45%, #02060b);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body[data-page="lobby"] {
  background:
    linear-gradient(rgba(3, 8, 13, .86), rgba(3, 8, 13, .9)),
    radial-gradient(circle at 22% 18%, rgba(54, 167, 255, .22), transparent 34%),
    radial-gradient(circle at 78% 24%, rgba(85, 216, 121, .13), transparent 28%),
    radial-gradient(circle at 62% 86%, rgba(255, 179, 46, .12), transparent 32%),
    url("images/baggrund.png") center / cover fixed,
    #02060b;
}

button,
select,
input {
  font: inherit;
}

button,
select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #122737;
  color: var(--text);
}

button {
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: rgba(53, 200, 255, .7);
}

.app-shell {
  min-height: 100vh;
  padding: 18px;
}

body[data-page="phone"] {
  overscroll-behavior: none;
}

body[data-page="phone"].phone-fullscreen,
body[data-page="phone"].phone-fullscreen .app-shell {
  min-height: 100dvh;
  overflow: hidden;
}

body[data-page="phone"].phone-fullscreen .app-shell {
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 18px;
  max-width: 1440px;
}

.eyebrow,
.label {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.45rem, 3vw, 2.4rem);
}

.mode-tabs {
  display: flex;
  gap: 8px;
}

.mode-button.active {
  background: var(--accent);
  color: #031018;
}

.lobby-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(300px, .9fr);
  gap: 18px;
  max-width: 1180px;
  margin: 0 auto;
}

.lobby-panel {
  display: grid;
  gap: 16px;
  padding: 20px;
  border: 1px solid rgba(160, 213, 238, .32);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(28, 41, 53, .92), rgba(8, 15, 23, .94)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .035) 0 1px, transparent 1px 58px);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .38), inset 0 1px 0 rgba(255, 255, 255, .08);
}

.lobby-hero {
  display: grid;
  gap: 6px;
  min-height: 170px;
  align-content: center;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(53, 200, 255, .4);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(13, 37, 56, .96), rgba(4, 10, 16, .98)),
    repeating-linear-gradient(0deg, rgba(53, 200, 255, .08) 0 1px, transparent 1px 16px);
  box-shadow: inset 0 0 44px rgba(53, 200, 255, .1);
  text-align: center;
}

.lobby-hero::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(255, 179, 46, .28);
  border-radius: 6px;
  pointer-events: none;
}

#gameCode {
  color: #c8f4ff;
  font-size: clamp(3rem, 10vw, 6.5rem);
  letter-spacing: .08em;
  text-shadow: 0 0 18px rgba(53, 200, 255, .55);
}

#lobbyPhase {
  color: var(--muted);
  font-weight: 700;
}

.lobby-settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.lobby-settings label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .86rem;
  font-weight: 700;
}

.lobby-settings input {
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid rgba(160, 213, 238, .34);
  border-radius: 8px;
  background: linear-gradient(180deg, #08131d, #04090f);
  color: var(--text);
  font-size: 1.2rem;
  font-weight: 900;
  text-align: center;
  box-shadow: inset 0 0 18px rgba(53, 200, 255, .06);
}

.lobby-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.lobby-actions button {
  border-color: rgba(160, 213, 238, .34);
  background: linear-gradient(180deg, #21384a, #0d1b27);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .08);
  font-weight: 850;
}

.lobby-actions button:hover {
  border-color: rgba(53, 200, 255, .82);
  box-shadow: 0 0 18px rgba(53, 200, 255, .16), inset 0 1px 0 rgba(255, 255, 255, .12);
}

.lobby-actions button:disabled {
  cursor: not-allowed;
  opacity: .38;
  box-shadow: none;
}

#releaseCode {
  border-color: rgba(53, 200, 255, .58);
}

#startLobbyGame {
  border-color: rgba(88, 214, 141, .58);
  background: linear-gradient(180deg, #1f5b45, #0f2b25);
}

#endGame {
  border-color: rgba(255, 91, 91, .48);
}

#resetLobby {
  border-color: rgba(255, 179, 46, .5);
}

.joined-panel {
  align-content: start;
}

.joined-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.joined-card {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px;
  border: 1px solid rgba(160, 213, 238, .18);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(22, 35, 48, .84), rgba(7, 14, 22, .84));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05);
}

.joined-card.empty {
  opacity: .42;
  background: rgba(2, 8, 13, .62);
}

.joined-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--bot-color, var(--accent));
}

.joined-bot {
  width: 24px;
  height: 24px;
  clip-path: polygon(78% 50%, 62% 88%, 28% 88%, 8% 50%, 28% 12%, 62% 12%);
  background: var(--bot-color, var(--accent));
  border: 2px solid rgba(5, 12, 20, .9);
  filter: drop-shadow(0 0 7px rgba(53, 200, 255, .18));
  flex: 0 0 auto;
}

.screen-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  width: 100%;
  max-width: none;
  margin: 0 auto;
}

.blueprint-panel,
.status-panel,
.phone-frame {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(9, 18, 28, .86);
  box-shadow: 0 18px 60px rgba(0, 0, 0, .28);
}

.blueprint-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.screen-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#blueprint {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1100 / 720;
  background: #071018;
}

.status-panel {
  display: none;
  align-content: start;
  gap: 18px;
  padding: 14px;
  max-height: calc(100vh - 112px);
  overflow: auto;
}

body[data-page="screen"] .app-shell {
  min-height: 100dvh;
  padding: 0;
}

body[data-page="screen"] .screen-layout,
body[data-page="screen"] .blueprint-panel {
  min-height: 100dvh;
}

body[data-page="screen"] .blueprint-panel {
  border: 0;
  border-radius: 0;
}

body[data-page="screen"] #blueprint {
  height: calc(100dvh - 74px);
  aspect-ratio: auto;
}

.blueprint-panel:fullscreen {
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
  background: #071018;
}

.blueprint-panel:fullscreen #blueprint {
  height: calc(100vh - 74px);
  aspect-ratio: auto;
}

.station-list,
.crew-list {
  display: grid;
  gap: 8px;
}

.station-row,
.crew-row {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 8px;
  background: rgba(255, 255, 255, .04);
}

.station-row strong,
.crew-row strong {
  font-size: .94rem;
}

.meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: .82rem;
}

.broken {
  border-color: rgba(255, 91, 91, .5);
}

.sabotaged {
  border-color: rgba(255, 209, 102, .6);
}

.out {
  opacity: .42;
}

.end-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(1, 6, 10, .72);
}

.end-modal-card {
  display: grid;
  gap: 12px;
  width: min(680px, 100%);
  padding: 34px;
  border: 1px solid rgba(53, 200, 255, .55);
  border-radius: 8px;
  background: rgba(6, 16, 24, .96);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55);
  text-align: center;
}

.end-modal-card strong {
  color: #ecf8ff;
  font-size: clamp(2rem, 5vw, 4.6rem);
  line-height: 1;
  text-transform: uppercase;
}

.end-modal-card span {
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.35rem);
  font-weight: 700;
}

.phone-end .end-modal-card {
  padding: 28px 20px;
}

.phone-end .end-modal-card strong {
  font-size: 2.6rem;
}

.phone-layout {
  display: grid;
  grid-template-columns: minmax(320px, 430px);
  justify-content: center;
  max-width: 460px;
  margin: 0 auto;
}

body[data-page="phone"].phone-fullscreen .phone-layout {
  grid-template-columns: minmax(0, 1fr);
  width: 100vw;
  max-width: none;
  min-height: 100dvh;
}

.phone-frame {
  padding: 12px;
}

body[data-page="phone"].phone-fullscreen .phone-frame {
  min-height: 100dvh;
}

.phone-lobby {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(3, 8, 13, .72);
  text-align: center;
}

.phone-lobby strong {
  font-size: 1.15rem;
}

.phone-lobby input {
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #071018;
  color: var(--text);
  font-size: 1.25rem;
  font-weight: 900;
  letter-spacing: .08em;
  text-align: center;
  text-transform: uppercase;
}

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

.phone-hud-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.fullscreen-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 1.05rem;
  font-weight: 900;
}

.player-badge {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--accent);
  color: #031018;
  font-weight: 900;
}

#playerSelect {
  max-width: 165px;
  min-height: 38px;
  padding: 0 8px;
}

.viewport-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #02060b;
}

#phoneView {
  display: block;
  width: 100%;
  aspect-ratio: 390 / 440;
}

.task-prompt,
.task-feedback {
  position: absolute;
  left: 10px;
  right: 10px;
  z-index: 3;
  bottom: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(6, 13, 20, .94);
}

.task-feedback {
  bottom: auto;
  top: 10px;
  border-color: rgba(53, 200, 255, .55);
  font-weight: 800;
}

.task-feedback.good {
  border-color: rgba(88, 214, 141, .8);
  color: var(--good);
}

.task-feedback.bad {
  border-color: rgba(255, 91, 91, .8);
  color: var(--bad);
}

.task-feedback.warn {
  border-color: rgba(255, 209, 102, .8);
  color: var(--warn);
}

.task-prompt form,
.mode-choice {
  display: grid;
  gap: 10px;
}

.lever-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lever-row button:disabled {
  cursor: not-allowed;
  opacity: .42;
}

.answer-display {
  display: grid;
  place-items: center;
  min-height: 46px;
  border: 1px solid rgba(53, 200, 255, .45);
  border-radius: 8px;
  background: #071018;
  color: #ecf8ff;
  font-size: 1.55rem;
  font-weight: 900;
  letter-spacing: .04em;
}

.answer-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.answer-keypad button,
.task-form > button[type="submit"] {
  min-height: 42px;
  padding: 0;
  border-color: rgba(53, 200, 255, .34);
  background: linear-gradient(180deg, #183346, #0d1d2a);
  font-size: 1.1rem;
  font-weight: 900;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.task-form > button[type="submit"] {
  background: linear-gradient(180deg, #2fd477, #168043);
  color: #031018;
}

.wrong-answer-panel {
  display: grid;
  gap: 10px;
  text-align: center;
}

.wrong-answer-panel strong {
  color: #fff2f2;
  font-size: 1.35rem;
  text-transform: uppercase;
}

.wrong-answer-panel span {
  padding: 10px;
  border: 1px solid rgba(255, 91, 91, .85);
  border-radius: 8px;
  background: rgba(255, 40, 40, .18);
  color: #ffb8b8;
  font-size: 1.05rem;
  font-weight: 900;
}

.wrong-answer-panel button {
  border-color: rgba(255, 91, 91, .85);
  background: linear-gradient(180deg, #ff5b5b, #9d1f27);
  color: #fff;
  font-weight: 900;
}

.suspect-frame {
  margin-top: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(3, 8, 13, .72);
}

.suspect-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 5px;
}

.suspect-limit {
  margin-bottom: 5px;
  color: var(--muted);
  font-size: .68rem;
  text-align: center;
}

.suspect-card {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 0;
  min-height: 44px;
  padding: 3px 1px;
  border: 0;
  background: transparent;
  color: var(--text);
}

.suspect-card:disabled {
  cursor: default;
  opacity: .38;
}

.suspect-card.self {
  border-radius: 7px;
  background: rgba(255, 255, 255, .86);
}

.suspect-card.self .suspect-name {
  color: #061018;
}

.suspect-bot {
  position: relative;
  width: 26px;
  height: 26px;
  clip-path: polygon(78% 50%, 62% 88%, 28% 88%, 8% 50%, 28% 12%, 62% 12%);
  background: var(--bot-color, #9deeff);
  border: 2px solid #071018;
}

.suspect-card.selected {
  border-radius: 7px;
  box-shadow: inset 0 0 0 2px #ffd166;
}

.suspect-card.selected .suspect-bot {
  outline: 2px solid #ffd166;
  outline-offset: 2px;
}

.vote-count {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: #061018;
  font-size: .72rem;
  font-weight: 900;
  text-shadow: 0 1px 0 rgba(255, 255, 255, .35);
}

.suspect-name {
  max-width: 100%;
  overflow: hidden;
  color: var(--muted);
  font-size: .58rem;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suspect-card.spy-known .suspect-name {
  border-bottom: 2px solid #ff4b4b;
  padding-bottom: 1px;
}

.phone-controls {
  display: grid;
  place-items: center;
  margin-top: 10px;
}

.phone-controls.button-pad {
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.phone-controls.button-pad button {
  min-height: 43px;
  font-size: 1.35rem;
  font-weight: 900;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.phone-controls.button-pad button:focus {
  outline: none;
}

.phone-controls.button-pad span {
  min-height: 43px;
}

.joystick {
  position: relative;
  width: min(148px, 42vw);
  aspect-ratio: 1;
  border: 1px solid rgba(160, 213, 238, .36);
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(53, 200, 255, .14) 0 5px, transparent 6px),
    rgba(7, 16, 24, .88);
  box-shadow: inset 0 0 26px rgba(53, 200, 255, .12);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.joystick::before,
.joystick::after {
  content: "";
  position: absolute;
  background: rgba(160, 213, 238, .18);
}

.joystick::before {
  left: 50%;
  top: 12%;
  width: 1px;
  height: 76%;
}

.joystick::after {
  left: 12%;
  top: 50%;
  width: 76%;
  height: 1px;
}

.joystick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  aspect-ratio: 1;
  border: 3px solid rgba(255, 210, 210, .75);
  border-radius: 50%;
  background: #ff3434;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .42), inset 0 0 10px rgba(255, 255, 255, .22);
  transform: translate(calc(-50% + var(--joy-x, 0px)), calc(-50% + var(--joy-y, 0px)));
  transition: transform .16s ease-out;
}

.joystick.active .joystick-knob {
  transition: none;
}

.hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .topbar,
  .screen-toolbar,
  .phone-hud {
    align-items: stretch;
    flex-direction: column;
  }

  .lobby-layout,
  .screen-layout,
  .phone-layout {
    grid-template-columns: 1fr;
  }

  .lobby-settings,
  .lobby-actions,
  .joined-list {
    grid-template-columns: 1fr;
  }

  .status-panel {
    max-height: none;
  }
}
