:root {
  --cream: #fff3d6;
  --cream-dim: #d9d2bd;
  --lamp: #ffd24a;
  --ink: #0d1826;
  --board: #0d1826e6;
  --edge: #3f6375;
  --text: 'Jersey 15', ui-monospace, Menlo, monospace;
  --shadow: 2px 0 #08111f, -2px 0 #08111f, 0 2px #08111f, 0 -2px #08111f, 0 0 10px #08111f;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: #12283f; }

body {
  position: relative;
  margin: 0;
  min-height: max(100dvh, 35rem);
  overflow-x: hidden;
  color: var(--cream);
  font: 400 1.375rem/1.2 var(--text);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.stage { position: absolute; inset: 0; overflow: hidden; }

#scene {
  display: block;
  image-rendering: pixelated;
  user-select: none;
  -webkit-user-select: none;
}

.panel {
  position: relative;
  display: grid;
  gap: 0.75rem;
  padding: 1.25rem 1rem 0.75rem;
  pointer-events: none;
}
.panel button, .panel a { pointer-events: auto; }

h1 { margin: 0; line-height: 0; }
.mark { display: flex; flex-wrap: wrap; gap: 0.75rem 1.75rem; }
.mark svg { height: min((100vw - 4rem) * 0.134, 3.5rem); width: auto; filter: drop-shadow(0 3px 0 #08111f); }
.mark .wall { fill: var(--cream); }
.mark .lamp { fill: var(--lamp); }

.sub { margin: 0; max-width: 34ch; text-shadow: var(--shadow); }

.rooms {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 1.25rem;
}
.rooms li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  background: var(--board);
  box-shadow: 0 0 0 2px var(--edge);
}
.bulbs { display: flex; gap: 0.25rem; }
.bulb { width: 8px; height: 8px; background: #3a4c5c; }
.bulb.on { background: var(--lamp); box-shadow: 0 0 8px 1px #ffd24a99; }
.rooms .more { background: none; box-shadow: none; color: var(--cream-dim); padding-left: 0; text-shadow: var(--shadow); }

.action { min-height: 5.25rem; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.hint { margin: 0.75rem 0 0; font-size: 1.25rem; color: var(--cream-dim); text-shadow: var(--shadow); }

button {
  min-height: 2.75rem;
  padding: 0.25rem 0.75rem;
  border: 0;
  color: var(--cream);
  background: var(--board);
  box-shadow: 0 0 0 2px var(--edge);
  font: 400 1.25rem/1 var(--text);
  cursor: pointer;
}
button:hover { box-shadow: 0 0 0 2px var(--cream); }
button:active { transform: translateY(2px); }
button:focus-visible { outline: 3px solid var(--cream); outline-offset: 4px; }
.primary {
  padding: 0.5rem 1rem;
  color: var(--ink);
  background: var(--lamp);
  box-shadow: 0 4px 0 #b5762a;
  font-size: 1.5rem;
}
.primary:hover { background: #ffe08a; box-shadow: 0 4px 0 #b5762a; }

#time { font-size: 2.25rem; line-height: 1; min-width: 4ch; font-variant-numeric: tabular-nums; text-shadow: var(--shadow); }
#count { text-shadow: var(--shadow); }
#result h2 { margin: 0; font-size: 2rem; line-height: 1; color: var(--lamp); outline: 0; text-shadow: var(--shadow); }
#result p { margin: 0.25rem 0 0.75rem; max-width: 36ch; font-size: 1.25rem; text-shadow: var(--shadow); }

#mute { position: absolute; right: 0.75rem; bottom: max(0.75rem, env(safe-area-inset-bottom)); min-height: 2.25rem; font-size: 1.125rem; }

dialog {
  width: min(26rem, 100vw - 2rem);
  padding: 0;
  border: 0;
  color: var(--cream);
  background: var(--ink);
  box-shadow: 0 0 0 4px var(--lamp);
  font: inherit;
}
dialog::backdrop { background: #08111fcc; }
dialog > * { padding: 1.5rem; }
dialog h2 { margin: 0; font-size: 2rem; font-weight: 400; line-height: 1; color: var(--lamp); outline: 0; }
dialog p { margin: 0.75rem 0 1rem; font-size: 1.25rem; }
dialog label { display: block; font-size: 1.25rem; }
dialog input {
  width: 100%;
  min-height: 3rem;
  margin-top: 0.25rem;
  padding: 0.25rem 0.75rem;
  border: 2px solid #6f94a8;
  border-radius: 0;
  color: var(--ink);
  background: var(--cream);
  font: 400 1.375rem/1 var(--text);
}
dialog input:focus-visible { outline: 3px solid var(--lamp); outline-offset: 2px; }
dialog input[aria-invalid='true'] { border-color: #ff8a73; }
dialog #email-error { min-height: 1.5rem; margin: 0.5rem 0; color: #ffb09f; }
button:disabled { cursor: default; opacity: 0.6; }
.trap { position: absolute; left: -100vw; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (min-width: 56rem), (orientation: landscape) and (min-width: 40rem) {
  body { min-height: max(100dvh, 24rem); }
  .panel {
    position: absolute;
    inset: 0 auto 0 0;
    width: clamp(18rem, 36vw, 34rem);
    align-content: center;
    gap: 1rem;
    padding: 1rem 0 3rem clamp(1rem, 4vw, 4rem);
  }
  .mark { flex-direction: column; gap: clamp(0.5rem, 1.4vw, 1.25rem); }
  .mark svg { height: clamp(2.5rem, 6.5vw, 6rem); align-self: flex-start; }
}

@media (min-width: 56rem) and (min-height: 40rem) {
  .panel { gap: 1.5rem; }
  .sub { font-size: 1.75rem; max-width: 27ch; }
  .rooms { font-size: 1.375rem; max-width: 26rem; }
}

/* Short screens: while playing, the house matters more than the pitch. */
@media (max-height: 42rem) and (max-width: 39.99rem) {
  .hint { display: none; }
  .action { min-height: 3.5rem; }
  body:is([data-mode='play'], [data-mode='won']) :is(.sub, .more) { display: none; }
}

@media (max-height: 32rem) and (min-width: 40rem) {
  .panel { gap: 0.75rem; padding-bottom: 1rem; }
  .mark { flex-direction: row; gap: 0.5rem 1rem; }
  .mark svg { height: 2rem; }
  .sub { font-size: 1.25rem; }
  .rooms { font-size: 1.125rem; }
  .hint { display: none; }
  .action { min-height: 3.5rem; }
  body:is([data-mode='play'], [data-mode='won']) .sub { display: none; }
}

/* Until the script runs (or if it can't), don't offer a game that won't start. */
body:not([data-mode]) :is(.action, #mute) { visibility: hidden; }
