:root {
  --blue: #2a8cff;
  --orange: #ff8a1c;
  --ink: #e9edf2;
  --muted: #9aa4af;
  --bg: #05070a;
  --panel: rgba(12, 15, 19, 0.82);
  --glass: rgba(14, 18, 24, 0.42);
  --glass-edge: rgba(233, 237, 242, 0.28);
  color-scheme: dark;
}

[hidden] {
  display: none !important;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--ink);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  cursor: crosshair;
  touch-action: none;
}

#hud {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

#crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 48px;
  height: 48px;
  transform: translate(-50%, -50%);
}

#crosshair .arc {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  opacity: 0.55;
  transition: stroke-width 0.15s, opacity 0.15s;
}

#crosshair .arc.blue {
  stroke: var(--blue);
}

#crosshair .arc.orange {
  stroke: var(--orange);
}

#crosshair .arc.placed {
  stroke-width: 4;
  opacity: 1;
  filter: drop-shadow(0 0 3px currentColor);
}

#hint {
  position: absolute;
  left: 50%;
  top: calc(50% + 48px);
  transform: translateX(-50%);
  padding: 6px 12px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.45);
  font-size: 14px;
  letter-spacing: 0.04em;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s;
}

#hint.show {
  opacity: 1;
}

#subtitle {
  position: absolute;
  left: 50%;
  bottom: 9vh;
  transform: translateX(-50%);
  max-width: min(720px, 90vw);
  padding: 10px 18px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 17px;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  transition: opacity 0.6s;
}

#subtitle.show {
  opacity: 1;
}

#debug {
  position: absolute;
  left: 10px;
  top: 8px;
  font: 12px/1.3 ui-monospace, Menlo, monospace;
  color: #8f8;
}

.screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: calc(12px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px))
    calc(12px + env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px));
  overflow-y: auto;
  background: radial-gradient(ellipse at center, rgba(10, 14, 20, 0.55), rgba(3, 4, 6, 0.9));
  z-index: 10;
  touch-action: pan-y; /* scroll a tall panel, but no pinch zoom the game can't undo */
}

.screen.hidden {
  display: none;
}

#loading {
  font-size: 16px;
  letter-spacing: 0.08em;
  color: var(--muted);
}

#loading.hidden {
  display: none;
}

.panel {
  width: min(440px, calc(100vw - 32px));
  padding: 32px 32px 26px;
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  text-align: center;
  backdrop-filter: blur(6px);
}

.badge {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
}

.dot {
  width: 22px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid;
}

.dot.blue {
  border-color: var(--blue);
  box-shadow: 0 0 14px var(--blue), inset 0 0 8px var(--blue);
}

.dot.orange {
  border-color: var(--orange);
  box-shadow: 0 0 14px var(--orange), inset 0 0 8px var(--orange);
}

h1 {
  margin: 0;
  font-size: 34px;
  font-weight: 300;
  letter-spacing: 0.18em;
}

h1 span {
  font-weight: 700;
}

.chamber {
  margin: 8px 0 22px;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 13px;
}

button {
  font: inherit;
  font-size: 15px;
  letter-spacing: 0.06em;
  padding: 12px 22px;
  color: #0b0d10;
  background: var(--ink);
  border: 0;
  border-radius: 4px;
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
}

button:hover {
  background: #fff;
  transform: translateY(-1px);
}

button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 3px;
}

.controls {
  margin: 24px auto 4px;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.controls td {
  padding: 4px 10px;
}

.controls td:first-child {
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}

.note {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--muted);
}

body.touch .desktop-only,
body:not(.touch) .touch-only {
  display: none;
}

/* ------------------------------------------------------ chamber select */

.menu-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 12px;
}

button.secondary {
  padding: 9px 16px;
  font-size: 13px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--glass-edge);
}

button.secondary:hover {
  background: rgba(233, 237, 242, 0.1);
}

.chambers {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 10px;
  margin-top: 18px;
}

/* view picker: two toggle buttons */
.skins {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.skins-label {
  min-width: 3.2em;
  text-align: right;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-right: 4px;
}

button.skin {
  padding: 7px 14px;
  font-size: 12px;
}

button.skin[aria-pressed="true"] {
  color: #0b0d10;
  background: var(--ink);
  border-color: var(--ink);
}

/* each chamber is shown as its wall sign */
.chamber-tile {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  min-width: 0;
  padding: 10px 10px 12px;
  text-align: left;
  color: #2b2b2b;
  background: #eceae4;
  border: 2px solid transparent;
  border-radius: 2px;
}

.chamber-tile:hover {
  background: #fff;
}

.chamber-tile.current {
  border-color: var(--blue);
}

.tile-num {
  font-size: 40px;
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.02em;
}

.tile-bar {
  display: flex;
  gap: 3px;
}

.tile-bar i {
  flex: 1;
  height: 5px;
  background: #c9c7c0;
}

.tile-bar i.on {
  background: #2b2b2b;
}

.tile-line {
  font-size: 11px;
  line-height: 1.3;
  letter-spacing: 0;
  text-transform: none;
}

.tile-state {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #6b6a65;
}

.chamber-tile.done .tile-state {
  color: #1f7a3d;
}

/* ---------------------------------------------------------- touch controls */

#touch {
  position: fixed;
  inset: 0;
  z-index: 5;
  touch-action: none;
}

.stick,
.stick-hint {
  position: absolute;
  width: 124px;
  height: 124px;
  border-radius: 50%;
  border: 2px solid var(--glass-edge);
  background: var(--glass);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.stick-hint {
  left: calc(96px + env(safe-area-inset-left, 0px));
  top: auto;
  bottom: calc(34px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  opacity: 0.55;
}

.stick {
  display: none;
}

.stick.active {
  display: block;
}

.stick.active ~ .stick-hint {
  opacity: 0;
}

.stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(233, 237, 242, 0.55);
}

.tbtn {
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  border: 2px solid var(--glass-edge);
  background: var(--glass);
  color: var(--ink);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  touch-action: none;
  transition: transform 0.08s, background 0.15s, box-shadow 0.2s;
}

.tbtn:hover {
  background: var(--glass);
  transform: none;
}

.tbtn.pressed {
  transform: scale(0.9);
  background: rgba(233, 237, 242, 0.3);
}

.tbtn.pause {
  position: absolute;
  left: calc(14px + env(safe-area-inset-left, 0px));
  top: calc(14px + env(safe-area-inset-top, 0px));
  width: 44px;
  height: 44px;
  display: flex;
  gap: 5px;
  justify-content: center;
  align-items: center;
}

.tbtn.pause span {
  width: 4px;
  height: 15px;
  border-radius: 2px;
  background: var(--ink);
}

.cluster {
  position: absolute;
  right: calc(18px + env(safe-area-inset-right, 0px));
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  display: grid;
  grid-template-columns: auto auto;
  gap: 14px 16px;
  align-items: center;
  justify-items: center;
}

.tbtn.small {
  width: 58px;
  height: 58px;
}

.tbtn.fire {
  width: 78px;
  height: 78px;
  border-width: 3px;
}

.tbtn.fire i {
  width: 22px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid currentColor;
}

.tbtn.fire.blue {
  color: var(--blue);
  border-color: var(--blue);
  box-shadow: 0 0 14px rgba(42, 140, 255, 0.45);
}

.tbtn.fire.orange {
  color: var(--orange);
  border-color: var(--orange);
  box-shadow: 0 0 14px rgba(255, 138, 28, 0.45);
}

.tbtn.use.ready {
  border-color: var(--ink);
  background: rgba(233, 237, 242, 0.25);
  box-shadow: 0 0 16px rgba(233, 237, 242, 0.5);
}

#rotate {
  position: fixed;
  left: 50%;
  top: calc(70px + env(safe-area-inset-top, 0px));
  transform: translateX(-50%);
  z-index: 9;
  padding: 8px 14px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.6);
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
}

body.touch #subtitle {
  top: calc(66px + env(safe-area-inset-top, 0px));
  bottom: auto;
  max-width: min(520px, 62vw);
  font-size: 14px;
}

@media (orientation: portrait) {
  body.touch #subtitle {
    top: calc(112px + env(safe-area-inset-top, 0px));
  }
}

body.touch #hint {
  top: calc(50% + 40px);
  font-size: 13px;
}

/* ------------------------------------------------- elevator transitions */

#fade {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: grid;
  place-items: center;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1s ease;
}

#fade.on {
  opacity: 1;
}

/* the same chamber sign as on the walls, between chambers */
.card {
  width: min(260px, 70vw);
  padding: 22px 22px 20px;
  background: #eceae4;
  color: #2b2b2b;
  border-radius: 2px;
  opacity: 0;
  animation: card-in 0.6s ease 0.5s forwards;
}

@keyframes card-in {
  to {
    opacity: 1;
  }
}

.card-number {
  font-size: 108px;
  font-weight: 700;
  line-height: 0.9;
  letter-spacing: -0.02em;
}

.card-count {
  margin-top: 10px;
  font-size: 20px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.card-bar {
  display: flex;
  gap: 5px;
  margin-top: 10px;
}

.card-bar i {
  flex: 1;
  height: 7px;
  background: #c9c7c0;
}

.card-bar i.on {
  background: #2b2b2b;
}

.card-rule {
  height: 2px;
  margin: 14px 0 8px;
  background: #2b2b2b;
}

.card-label {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.card-lines {
  margin-top: 16px;
  font-size: 13px;
  line-height: 1.35;
}

.card-lines p {
  margin: 0 0 4px;
}

@media (max-height: 420px) {
  .card {
    padding: 14px 16px;
  }

  .card-number {
    font-size: 64px;
  }
}

/* short screens: a phone held sideways */
@media (max-height: 520px) {
  .panel {
    padding: 18px 22px 16px;
  }

  .badge {
    margin-bottom: 8px;
  }

  .dot {
    width: 16px;
    height: 26px;
  }

  h1 {
    font-size: 26px;
  }

  .chamber {
    margin: 4px 0 14px;
  }

  .controls {
    margin-top: 14px;
    font-size: 12px;
  }

  .chambers {
    margin-top: 12px;
  }

  .skins {
    margin-top: 8px;
  }

  button.skin {
    padding: 5px 12px;
  }

  .tile-num {
    font-size: 30px;
  }

  .controls td {
    padding: 2px 8px;
  }

  .note {
    margin-top: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tbtn,
  #hint,
  #subtitle {
    transition: none;
  }
}
