* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #6db2ec; }
body { font-family: "VT323", "Courier New", monospace; color: #fff; font-size: 18px; }
body.nocursor { cursor: none; }
body.grab:not(.nocursor) { cursor: grab; }
body.grabbing:not(.nocursor) { cursor: grabbing; }
#field { display: block; position: fixed; inset: 0; touch-action: none; image-rendering: pixelated; image-rendering: crisp-edges; }

/* HUD fades in on mouse move, out after a few seconds */
#hud { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .35s; }
#hud.visible { opacity: 1; }
#hud > * { pointer-events: auto; }

#gear {
  position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; border-radius: 0;
  border: 0; background: rgba(0,0,0,.45); color: #fff; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; backdrop-filter: blur(6px);
}
#gear:hover { background: rgba(0,0,0,.65); }
#info {
  position: absolute; top: 14px; right: 60px; width: 40px; height: 40px; border-radius: 0;
  border: 0; background: rgba(0,0,0,.45); color: #fff; font-size: 22px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; backdrop-filter: blur(6px); font-family: inherit;
}
#info:hover { background: rgba(0,0,0,.65); }

#statusbar {
  position: absolute; left: 14px; bottom: 12px; display: flex; align-items: center; gap: 8px;
  background: rgba(0,0,0,.45); padding: 4px 12px; border-radius: 0; font-size: 17px; backdrop-filter: blur(6px);
}
#dot { width: 9px; height: 9px; border-radius: 50%; background: #888; }
#dot.on { background: #4ade80; box-shadow: 0 0 8px #4ade80; }
#dot.wait { background: #facc15; }
#dot.off { background: #ef4444; }

#settings {
  position: absolute; top: 64px; right: 14px; width: 340px; max-width: calc(100vw - 28px);
  background: rgba(18,20,34,.92); border-radius: 16px; padding: 18px; display: none;
  box-shadow: 0 10px 40px rgba(0,0,0,.4); backdrop-filter: blur(10px); font-size: 18px; border: 3px solid #fff; border-radius: 0;
}
#settings.open { display: block; }
#settings h1 { margin: 0 0 4px; font-size: 28px; font-weight: 400; }
#settings p { margin: 0 0 12px; opacity: .75; line-height: 1.35; }
#settings label { display: block; margin: 8px 0; }
#settings label.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
#settings label.slider span { float: right; opacity: .75; font-variant-numeric: tabular-nums; }
#settings input[type=range] { display: block; width: 100%; margin: 6px 0 0; accent-color: #9146ff; cursor: pointer; }
#settings input[type=text] {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.15);
  background: rgba(255,255,255,.08); color: #fff; font: inherit; font-size: 20px; margin-top: 4px; border-radius: 0;
}
#settings input[type=text]:focus, #settings textarea:focus, #settings input[type=number]:focus { outline: 2px solid #a78bfa; }
.row.nums { gap: 12px; margin: 6px 0 0; }
.row.nums label { flex: 1; margin: 4px 0; font-size: 15px; line-height: 1.1; }
#settings input[type=number] {
  width: 100%; padding: 6px 8px; border: 1px solid rgba(255,255,255,.15); border-radius: 0;
  background: rgba(255,255,255,.08); color: #fff; font: inherit; font-size: 18px; margin-top: 4px;
}
#settings textarea {
  width: 100%; padding: 6px 10px; border: 1px solid rgba(255,255,255,.15); border-radius: 0; resize: vertical;
  background: rgba(255,255,255,.08); color: #fff; font: inherit; font-size: 16px; margin-top: 4px; line-height: 1.2;
}
.row { display: flex; gap: 8px; margin: 10px 0 6px; }
button.btn {
  flex: 1; padding: 10px; border-radius: 0; border: 0; font: inherit; font-size: 18px; cursor: pointer;
  background: rgba(255,255,255,.12); color: #fff;
}
button.btn.primary { background: #9146ff; }
button.btn:hover { filter: brightness(1.15); }
#close { position: absolute; top: 10px; right: 12px; background: none; border: 0; color: #fff; font-size: 18px; cursor: pointer; opacity: .7; }
#settings .links { margin: 12px 0 0; font-size: 16px; opacity: .85; }
#settings .links a { color: #ffd166; }
#settings a { color: #c4b5fd; }

/* Version tag: shown for a few seconds after load, outside the auto-hiding HUD */
#version {
  position: fixed; right: 14px; bottom: 12px; padding: 4px 10px; background: rgba(0,0,0,.55); color: #ffd166;
  font-size: 17px; letter-spacing: .5px; opacity: 0; transition: opacity .6s; pointer-events: none; z-index: 5;
}
#version.show { opacity: 1; }

/* What's new: shown once after an update, and from the settings panel */
#whatsnew { position: fixed; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.35); }
#whatsnew[hidden] { display: none; }
#whatsnew .box {
  position: relative; width: 460px; max-width: calc(100vw - 28px); max-height: calc(100vh - 28px); overflow-y: auto;
  background: rgba(18,20,34,.94); padding: 18px 22px; border: 3px solid #fff; box-shadow: 0 10px 40px rgba(0,0,0,.4);
  backdrop-filter: blur(10px); font-size: 18px;
}
#whatsnew h1 { margin: 0 0 2px; font-size: 28px; font-weight: 400; }
#whatsnew .sub { margin: 0 0 12px; opacity: .8; font-size: 16px; }
#whatsnew h2 { margin: 12px 0 4px; font-size: 20px; font-weight: 400; color: #ffd166; }
#whatsnew ul { margin: 0; padding-left: 20px; }
#whatsnew li { margin: 4px 0; line-height: 1.25; }
#whatsnew .row { margin-top: 14px; }
#wn-close { position: absolute; top: 10px; right: 12px; background: none; border: 0; color: #fff; font-size: 18px; cursor: pointer; opacity: .7; }
#wn-close:hover { opacity: 1; }

/* Stats panel: the i button next to the cog, or I */
#stats { position: fixed; inset: 0; z-index: 8; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.35); }
#stats[hidden] { display: none; }
#stats .box {
  position: relative; width: 520px; max-width: calc(100vw - 28px); max-height: calc(100vh - 28px); overflow-y: auto;
  background: rgba(18,20,34,.94); padding: 18px 22px; border: 3px solid #fff; box-shadow: 0 10px 40px rgba(0,0,0,.4);
  backdrop-filter: blur(10px); font-size: 18px;
}
#stats h1 { margin: 0 0 2px; font-size: 28px; font-weight: 400; }
#stats .sub { margin: 0 0 8px; opacity: .8; font-size: 16px; }
#stats h2 { margin: 12px 0 4px; font-size: 20px; font-weight: 400; color: #ffd166; border-bottom: 1px solid rgba(255,255,255,.15); padding-bottom: 2px; }
#stats .stat { display: flex; justify-content: space-between; gap: 12px; margin: 3px 0; line-height: 1.25; }
#stats .stat span { opacity: .8; flex: 0 0 auto; }
#stats .stat b { font-weight: 400; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
#stats ol { margin: 0; padding-left: 22px; }
#stats ol li { margin: 4px 0; line-height: 1.25; }
#stats ol b { font-weight: 400; white-space: pre; }
#stats-close { position: absolute; top: 10px; right: 12px; background: none; border: 0; color: #fff; font-size: 18px; cursor: pointer; opacity: .7; }
#stats-close:hover { opacity: 1; }

/* Advanced settings panel (Shift+S) */
#advanced {
  position: absolute; top: 64px; right: 14px; bottom: 14px; width: 440px; max-width: calc(100vw - 28px);
  background: rgba(18,20,34,.94); padding: 18px; display: none; overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.4); backdrop-filter: blur(10px); font-size: 17px; border: 3px solid #fff;
}
#advanced.open { display: block; }
#advanced h1 { margin: 0 0 4px; font-size: 26px; font-weight: 400; }
#advanced h2 { margin: 16px 0 6px; font-size: 20px; font-weight: 400; color: #ffd166; border-bottom: 1px solid rgba(255,255,255,.15); padding-bottom: 2px; }
#advanced p { margin: 0 0 8px; opacity: .75; line-height: 1.3; }
#advanced #adv-close { position: absolute; top: 10px; right: 12px; background: none; border: 0; color: #fff; font-size: 18px; cursor: pointer; opacity: .7; }
.opt-row { display: grid; grid-template-columns: 1fr 120px; gap: 4px 10px; align-items: center; margin: 6px 0; }
.opt-row.opt-bool { grid-template-columns: auto 1fr; }
.opt-row.opt-text, .opt-row.opt-textarea, .opt-row.opt-multi { grid-template-columns: 1fr; }
.opt-row label { font-size: 16px; line-height: 1.15; }
.opt-row small { grid-column: 1 / -1; color: #9aa4b8; font-size: 14px; line-height: 1.2; margin-top: -2px; }
.opt-row input[type=number], .opt-row input[type=text], .opt-row input[type=password], .opt-row select, .opt-row textarea {
  width: 100%; padding: 5px 8px; border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.08); color: #fff; font: inherit; font-size: 16px;
}
.opt-row select option { color: #000; }
.opt-row .multi { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.opt-row .multi label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
#advanced textarea#adv-io { width: 100%; margin-top: 8px; padding: 6px 10px; border: 1px solid rgba(255,255,255,.15); background: rgba(255,255,255,.08); color: #fff; font: inherit; font-size: 14px; }
#advanced .row .btn { font-size: 16px; padding: 8px 4px; }

/* Giveaway race page: streamer controls along the bottom, results in the panel */
#controls {
  position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); display: flex; gap: 8px;
  background: rgba(0,0,0,.45); padding: 8px; backdrop-filter: blur(6px); max-width: calc(100vw - 28px); flex-wrap: wrap; justify-content: center;
}
#controls .btn { flex: none; padding: 8px 14px; white-space: nowrap; }
.btn:disabled { opacity: .4; cursor: default; filter: none; }
#results { margin: 10px 0 0; padding: 8px 10px; background: rgba(255,255,255,.08); border-left: 3px solid #ffd166; line-height: 1.45; }
#results b { font-weight: 400; }
#results .btn { margin-top: 6px; width: 100%; font-size: 16px; padding: 6px; }
details { margin-top: 10px; }
details summary { cursor: pointer; opacity: .8; }
details ul { margin: 6px 0 0; padding-left: 18px; line-height: 1.5; opacity: .85; }
code { background: rgba(255,255,255,.1); padding: 1px 5px; border-radius: 0; font-size: 16px; }
kbd { background: rgba(255,255,255,.15); padding: 1px 6px; border-radius: 0; font-size: 16px; }

/* Splash screen */
#splash {
  position: fixed; inset: 0; z-index: 10; background: #0a0f2a;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  transition: opacity .9s; cursor: default;
}
#splash.hide { opacity: 0; pointer-events: none; }
#splash canvas { image-rendering: pixelated; image-rendering: crisp-edges; margin-bottom: 8px; }
#splash h1 { margin: 0; font-size: clamp(40px, 8vw, 96px); font-weight: 400; color: #fff; text-shadow: 4px 4px 0 #3b2d6e; letter-spacing: 1px; }
#splash p { margin: 0; font-size: clamp(20px, 3vw, 36px); color: #ffd166; text-shadow: 3px 3px 0 #3b2d6e; }

/* In-game confirm / alert (U.dialog) */
#dialog { position: fixed; inset: 0; z-index: 9; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.45); }
#dialog .box {
  width: 380px; max-width: calc(100vw - 28px); background: rgba(18,20,34,.96); padding: 18px 22px;
  border: 3px solid #fff; box-shadow: 0 10px 40px rgba(0,0,0,.4); backdrop-filter: blur(10px); font-size: 19px;
}
#dialog p { margin: 0 0 4px; line-height: 1.35; white-space: pre-wrap; }
#dialog .row { margin-top: 14px; }
#dialog .btn.danger { background: #dc2626; }
#dialog .btn:focus-visible { outline: 2px solid #ffd166; outline-offset: 2px; }

/* !photo: the flash, then a polaroid feeds out from the top edge, develops, hangs for a bit and drops off the bottom */
.photo-flash { position: fixed; inset: 0; z-index: 7; background: #fff3dc; pointer-events: none; animation: photo-flash .4s ease-out forwards; }
@keyframes photo-flash { 0% { opacity: .35; } 100% { opacity: 0; } }
.polaroid {
  --w: min(58vw, 76vh);
  position: fixed; left: 50%; top: 0; z-index: 6; pointer-events: none; width: var(--w);
  transform: translate(-50%, -104%) rotate(0deg);
  transition: transform 1.3s cubic-bezier(.3, 1.25, .5, 1);
  filter: drop-shadow(0 18px 28px rgba(0,0,0,.5));
}
.polaroid.eject { transform: translate(-50%, 5vh) rotate(-2deg); }
.polaroid.drop { transform: translate(-50%, 130vh) rotate(10deg); transition: transform 1.5s cubic-bezier(.55, 0, .9, .45); }
.polaroid .print { background: #f4f0e6; padding: 3.5% 3.5% 0; }
.polaroid .shot { position: relative; background: #23283a; overflow: hidden; line-height: 0; }
.polaroid .shot img { width: 100%; height: auto; image-rendering: pixelated; image-rendering: crisp-edges; filter: saturate(0) brightness(.4) contrast(.7); transition: filter 2.6s ease-out; }
.polaroid .shot::after { content: ''; position: absolute; inset: 0; background: #2b3042; opacity: .92; transition: opacity 2.6s ease-out; }
.polaroid.developed .shot img { filter: none; }
.polaroid.developed .shot::after { opacity: 0; }
.polaroid .strip { display: flex; align-items: stretch; justify-content: space-between; gap: 3%; height: calc(var(--w) * .3); padding: calc(var(--w) * .03) 1% calc(var(--w) * .03); color: #2a2a3a; }
.polaroid .cap { align-self: center; font-size: calc(var(--w) * .062); line-height: 1.05; min-width: 0; overflow: hidden; }
.polaroid .cap b { font-weight: normal; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.polaroid .cap small { display: block; font-size: .62em; opacity: .7; }
.polaroid .qr { display: grid; grid-template-rows: 1fr auto; justify-items: center; align-items: center; height: 100%; flex: none; }
.polaroid .qr canvas { height: 100%; width: auto; aspect-ratio: 1; image-rendering: pixelated; opacity: 0; transition: opacity .6s; }
.polaroid .qr .scan { font-size: calc(var(--w) * .036); line-height: 1; white-space: nowrap; opacity: 0; transition: opacity .6s; }
.polaroid .qr.ready canvas, .polaroid .qr.ready .scan { opacity: 1; }
.polaroid .qr.none canvas { display: none; }
.polaroid .qr.none { grid-template-rows: auto; }
.polaroid .qr.none .scan { opacity: .55; }
