* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #1b1424; color: #fff;
  font: 500 17px system-ui, -apple-system, "Segoe UI", sans-serif; overscroll-behavior: none; }
[hidden] { display: none !important; }
h1 { font-size: 26px; margin: 8px 0; color: #ffd9ec; }
h2 { font-size: 14px; margin: 14px 0 6px; color: #bfb3d6; text-transform: uppercase; letter-spacing: 0.06em; }
p { margin: 6px 0; color: #e9e2f7; }
.tip { color: #bfb3d6; font-size: 15px; }

.screen { min-height: 100dvh; padding: 16px max(16px, env(safe-area-inset-right)) 28px max(16px, env(safe-area-inset-left));
  max-width: 560px; margin: 0 auto; text-align: center; }
.centre { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; }

button, input { font: inherit; color: inherit; }
button { border: 0; border-radius: 14px; background: #3a2c55; cursor: pointer; touch-action: manipulation; }
button.big { display: block; width: 100%; margin-top: 18px; padding: 16px; font-size: 21px; font-weight: 700;
  background: #ee6fa8; color: #2a0f1d; }
button.big:disabled { background: #4a3d60; color: #8f84a8; }
button.small { margin-top: 14px; padding: 10px 18px; font-size: 16px; }
input { width: 100%; padding: 14px; font-size: 22px; text-align: center; border-radius: 14px;
  border: 2px solid #5a4a7a; background: #2a2038; }
input:focus { outline: none; border-color: #ee6fa8; }
#code { letter-spacing: 0.4em; text-transform: uppercase; font-weight: 700; max-width: 260px; }
#code-form { width: 100%; max-width: 300px; display: flex; flex-direction: column; align-items: center; }

#preview { width: 150px; height: 150px; }
#mine { width: 170px; height: 170px; }
.row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
#colours { grid-template-columns: repeat(6, 1fr); }
.row button { padding: 6px 2px 8px; border: 3px solid transparent; font-size: 13px; line-height: 1.15; min-height: 56px; }
.row button canvas { width: 100%; aspect-ratio: 1; display: block; }
.row button.on { border-color: #ee6fa8; background: #4a3766; }
.row button:disabled { opacity: 0.35; }
#colours button { aspect-ratio: 1; min-height: 0; border-radius: 50%; }
#colours button.on { border-color: #fff; }

/* The controller. Laid out for a phone on its side; when the phone itself stays in
   portrait (rotation lock), the whole pad is turned so it still reads sideways. */
/* Its position and size are set in phone.js from the area the browser is really
   showing (Safari's bars change it), so the whole pad always fits.
   --pl/--pr/--pt/--pb are the pad's own left/right/top/bottom safe margins. */
#s-pad { position: fixed; left: 0; top: 0; width: 100vw; height: 100dvh; display: flex; flex-direction: column;
  background: #1b1424; overflow: hidden;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none;
  --pl: env(safe-area-inset-left, 0px); --pr: env(safe-area-inset-right, 0px);
  --pt: env(safe-area-inset-top, 0px); --pb: env(safe-area-inset-bottom, 0px); }
/* Turned a quarter: the pad's left is the phone's top and its right is the phone's
   bottom, where Safari keeps its toolbar, so that end gets a little extra room. */
#s-pad.rot { transform-origin: top left; transform: rotate(90deg) translateY(-100%);
  --pl: env(safe-area-inset-top, 0px); --pr: calc(env(safe-area-inset-bottom, 0px) + 14px);
  --pt: env(safe-area-inset-right, 0px); --pb: env(safe-area-inset-left, 0px); }
.bar { display: flex; justify-content: space-between; align-items: center; flex: none;
  height: clamp(28px, 11%, 40px); margin-top: var(--pt);
  padding: 0 max(14px, var(--pr)) 0 max(14px, var(--pl)); color: #bfb3d6; font-weight: 700; }
#safe-probe { position: fixed; visibility: hidden; pointer-events: none; top: 0; left: 0;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px); }
/* What this sock can do in this room: one line, always there, under the name. */
#power { flex: none; margin: 0 max(10px, var(--pr)) 2px max(10px, var(--pl)); padding: 3px 12px; border-radius: 10px;
  background: #2a2038; color: #e9e2f7; text-align: center; text-wrap: balance; overflow: hidden; /* (two lines on a narrow pad) */
  font-size: clamp(11px, 3.7vmin, 16px); font-weight: 500; line-height: 1.3; pointer-events: none; }
#power-lead { color: #bfb3d6; }
#power-name { color: var(--sock, #ffd9ec); font-weight: 800; filter: brightness(1.35); letter-spacing: 0.03em; }
.bar-right { display: flex; align-items: center; gap: 10px; height: 100%; }
.bar button { width: 56px; height: 85%; font-weight: 800; touch-action: none; }
#mute.off { opacity: 0.55; }
.keys { flex: 1; display: grid; grid-template-columns: 22fr 22fr 5fr 22fr 29fr; gap: 10px;
  padding: 4px max(10px, var(--pr)) max(10px, var(--pb)) max(10px, var(--pl)); min-height: 0; }
.key { display: grid; place-items: center; border-radius: 22px; background: #3a2c55; color: #fff;
  font-size: clamp(20px, 6vmin, 34px); font-weight: 800; border: 3px solid #5a4a7a; text-align: center; }
.key.move { font-size: clamp(34px, 11vmin, 64px); }
.key.jump { background: #2f4a6b; border-color: #4f78a8; }
.key.do { background: var(--sock, #ee6fa8); border-color: #fff; color: #1b1424; }
.key.do { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
#do-how { font-size: clamp(11px, 3.4vmin, 18px); letter-spacing: 0.08em; background: #1b1424; color: #fff;
  padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.key.do.hold.on { animation: holding 0.7s ease-in-out infinite alternate; }
@keyframes holding { from { box-shadow: inset 0 0 0 4px #fff; } to { box-shadow: inset 0 0 0 14px #fff; } }
.key.do.idle { opacity: 0.45; } /* nothing to do right now (in mid-air) */
.key { min-width: 0; min-height: 0; overflow: hidden; }
.space { display: grid; grid-template-rows: minmax(0, 1fr); }
.key.swap { width: 100%; height: 100%; background: #ffd400; border-color: #fff3a8; color: #1b1424;
  font-size: clamp(12px, 3.6vmin, 20px); }
.keys.test { grid-template-columns: 20fr 20fr 11fr 21fr 28fr; }
#test-flag { background: #ffd400; color: #1b1424; padding: 2px 10px; border-radius: 8px; font-size: 13px; }
.key.on { filter: brightness(1.5); transform: scale(0.97); }
#skip { position: absolute; left: 50%; top: var(--pt); transform: translateX(-50%); max-width: 70%; padding: 6px 16px;
  background: #ffd9ec; color: #1b1424; font-weight: 800; font-size: clamp(12px, 3.6vmin, 18px); border-radius: 0 0 14px 14px;
  text-align: center; pointer-events: none; z-index: 2; }
#over { position: absolute; inset: 0; background: rgba(20, 14, 30, 0.93); display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 16px 20%; touch-action: manipulation; }
#over-rooms { margin-top: 12px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 14px; color: #bfb3d6; }
#room-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
#room-list button { min-width: 40px; min-height: 40px; padding: 0 6px; font-size: 17px; font-weight: 800; border-radius: 10px;
  border: 0; background: #3a2c55; color: #fff; }
#room-list button.here { background: #ffd76a; color: #1b1424; }
#banner { position: fixed; top: 0; left: 0; right: 0; padding: 8px; background: #b3402a; text-align: center;
  font-weight: 700; z-index: 5; }
#build { position: fixed; right: max(6px, var(--pr, 0px)); bottom: 4px; font-size: 11px; color: #8f84a8; pointer-events: none; }
#tester-build { font-size: 12px; font-weight: 500; color: #8f84a8; margin-left: 8px; }
#tester-note { margin: 0; padding: 6px 12px; border-radius: 10px; background: #b3402a; font-weight: 700; font-size: 15px; text-align: center; }
#stuck { position: fixed; inset: 0; background: #1b1424; display: grid; place-items: center; z-index: 9; }
/* SM-61, test mode only: the tester's button and its menu (any room, reload, change my sock). */
/* (The button stays in reach over the pause and end-of-room cards; its menu covers everything.) */
.bar #tester { width: auto; padding: 0 12px; background: #ffd400; color: #1b1424; font-size: 15px; position: relative; z-index: 4; }
#tester-menu { position: absolute; inset: 0; z-index: 5; background: rgba(20, 14, 30, 0.96); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; overflow-y: auto; touch-action: manipulation;
  padding: max(8px, var(--pt)) max(5%, var(--pr)) max(8px, var(--pb)) max(5%, var(--pl)); }
#tester-menu h1 { margin: 0; font-size: 22px; }
#tester-rooms, #tester-socks { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 15px; color: #bfb3d6; }
#tester-room-list, #tester-sock-list { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
#tester-room-list button { min-width: 46px; min-height: 46px; padding: 0 10px; font-size: 18px; font-weight: 800; border-radius: 10px;
  background: #3a2c55; color: #fff; }
#tester-room-list button.here { background: #ffd76a; color: #1b1424; }
#tester-sock-list button { min-height: 46px; padding: 0 12px; font-size: 16px; font-weight: 700; border-radius: 10px; background: #2f4a6b; color: #fff; }
#tester-sock-list button.take { background: #ffd400; color: #1b1424; }
#tester-sock-list button:disabled { opacity: 0.4; }
#tester-acts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 4px; }
#tester-acts button { min-height: 52px; padding: 8px 16px; font-size: 18px; font-weight: 700; background: #ee6fa8; color: #2a0f1d; }
#tester-acts #tester-close { background: #3a2c55; color: #fff; }
#sound-note { position: absolute; left: 50%; top: var(--pt); transform: translateX(-50%); max-width: 70%; padding: 6px 16px;
  background: #ffd76a; color: #1b1424; font-weight: 800; font-size: clamp(12px, 3.6vmin, 18px); border-radius: 0 0 14px 14px;
  text-align: center; pointer-events: none; z-index: 2; }
