/* The room (PC): Multiface | TV | joystick on top, manual | computer | recorder below;
   TV beside the keyboard (phone, landscape); everything stacked (phone, portrait).
   --P is one key pitch of the 48K; every object is sized from it. The TV's picture is as wide as
   the 48K (11.3 pitches = 68.6% of the TV's width); the Spectrum+ and 128 may be a little wider. */
:root {
  --P: min(calc((var(--vh100) - 44px) / 18.3), calc((var(--vw100) - 40px) / 29.2), 64px);
  --W: calc(var(--P) * 16.5);
  --tvw: var(--W);
}
.room {
  width: auto; display: grid; justify-content: center; align-items: end;
  grid-template-columns: auto auto auto; grid-template-areas: "mf tv joy" "man desk rec"; align-items: center;
  column-gap: calc(var(--P) * .4); row-gap: calc(var(--P) * .3); padding: 12px 20px;
}
.tv { grid-area: tv; margin: 0; }
.desk {
  grid-area: desk; position: relative; width: auto; margin: 0; display: flex; align-items: center; justify-content: center; gap: 0;
  --p: var(--P); --q: calc(var(--P) * 7.06 / 7.3);
}
.note { grid-column: 1 / -1; }
button { font-family: Tahoma, sans-serif; }
/* buttons sized in em must take their parent's font size, not the browser's 13px */
.creset, .autoload, .mfred, .slide { font-size: inherit; }

/* ----- TV: ZOOM beside POWER, channel names, on-screen messages ----- */
#btnZoom {
  font-size: 1.1cqw; letter-spacing: .1cqw; color: #ccc; padding: .9cqw 1cqw; border: 0; border-radius: .5cqw;
  background: linear-gradient(#55524d, #33312e); box-shadow: 0 .35cqw 0 #111;
}
#btnZoom:active { transform: translateY(.25cqw); box-shadow: 0 1px 0 #111; }
.power { gap: .8cqw; }
.chan { font-size: 1.15cqw; font-weight: bold; }
.osd {
  position: absolute; left: 7%; top: 7%; z-index: 2; pointer-events: none; opacity: 0; transition: opacity .3s;
  font: bold 3.4cqw 'Courier New', monospace; color: #3dff6a; text-shadow: 0 0 .6cqw #0f0, .2cqw .2cqw 0 #000;
}
.osd.show { opacity: 1; }
.osd.error { color: #ff6a50; text-shadow: 0 0 .6cqw #f30, .2cqw .2cqw 0 #000; }


/* ----- reset button on the side of the computer ----- */
.resetbtn {
  align-self: center; width: calc(var(--P) * .16); height: calc(var(--P) * .6); padding: 0; border: 0;
  border-radius: calc(var(--P) * .06) 0 0 calc(var(--P) * .06);
  background: linear-gradient(90deg, #5a5a5a, #2a2a2a); box-shadow: -2px 2px 3px rgba(0,0,0,.7);
}
.resetbtn:active { transform: translateX(2px); }

/* ----- gadgets: Multiface One, the manual, the joystick ----- */
.gear { display: contents; } /* on a PC each gadget has its own place around the TV and the computer */
.gear .multiface { grid-area: mf; justify-self: end; align-self: end; margin-bottom: calc(var(--P) * .5); }
.gear .joystick { grid-area: joy; justify-self: start; align-self: end; }
.gear .manualbook { grid-area: man; justify-self: end; }
.multiface {
  position: relative; flex: 0 0 auto; font-size: calc(var(--P) * 3 / 124); width: 124em; height: 80em; border-radius: 5em;
  background: linear-gradient(#262626, #141414 45%, #101010 46%, #181818);
  box-shadow: 0 10em 18em rgba(0,0,0,.6), inset 0 1px 0 rgba(255,255,255,.18);
}
.mfgrooves { position: absolute; left: 3em; right: 3em; top: 32em; height: 16em; background: repeating-linear-gradient(180deg, #050505 0 1em, #222 1em 3em); }
.sticker { position: absolute; left: 6em; top: 5em; width: 60em; height: 24em; background: #fbfbf8; border-radius: 1em; overflow: hidden; }
.sticker b {
  position: absolute; left: .9em; top: .3em; font: 900 italic 10em/1.1 'Arial Black', Arial, sans-serif; letter-spacing: -.05em; color: #e2231a;
  -webkit-mask: repeating-linear-gradient(115deg, #000 0 .3em, transparent .3em .4em); mask: repeating-linear-gradient(115deg, #000 0 .3em, transparent .3em .4em);
}
.sticker b.one { left: auto; right: .4em; top: 1.1em; }
.sticker i { position: absolute; left: 3em; top: 2em; width: 5em; height: 4em; background: #e2231a; }
.mfslot {
  position: absolute; right: 5em; bottom: 6em; width: 64em; height: 12em; border-radius: 1em; box-shadow: inset 0 0 0 1em #000;
  background: repeating-linear-gradient(90deg, transparent 0 2em, #cfcfcf 2em 3em, transparent 3em 5em) 0 50% / 100% 30% no-repeat, #050505;
}
.mfred {
  position: absolute; left: 92em; top: -12em; width: 13em; height: 10em; padding: 0; border: 0; border-radius: 4em 4em 0 0;
  background: radial-gradient(circle at 40% 30%, #ff6a5a, #c3160b 70%); box-shadow: 0 0 6em rgba(255,40,20,.5);
}
.mfred::after { content: ''; position: absolute; left: -2em; bottom: -3em; width: 17em; height: 3em; background: linear-gradient(#bbb, #555); }
.mfred:active { top: -9em; height: 7em; }
.mflever { position: absolute; right: -8em; top: 34em; width: 9em; height: 3em; background: #6a6a6a; transform: rotate(8deg); }

.manualbook { /* the cover of the 1982 Introduction booklet, as tall as the computer */
  --mh: calc(var(--P) * 7.06);
  position: relative; flex: 0 0 auto; width: calc(var(--mh) * .706); height: var(--mh); padding: 0; border: 0; border-radius: 3px; overflow: hidden;
  background: #e5843a; box-shadow: 6px 9px 16px rgba(0,0,0,.55), inset 0 0 0 1px rgba(0,0,0,.25); transition: transform .15s;
}
.manualbook:hover { transform: translateY(-4px) rotate(-1deg); }
.manualbook .cover { display: block; width: 100%; height: 100%; }
.joystick {
  position: relative; flex: 0 0 auto; font-size: calc(var(--P) * 4.3 / 130); width: 130em; height: 140em; padding: 0; border: 0; background: none;
  filter: grayscale(.6) brightness(.75); transition: filter .2s;
}
.joystick.on { filter: none; }
.joystick span { position: absolute; }
.jbase { left: 10em; bottom: 20em; width: 110em; height: 44em; border-radius: 20em 20em 10em 10em; background: linear-gradient(#333, #111); box-shadow: 0 8em 12em rgba(0,0,0,.6); }
.jstick { left: 57em; bottom: 50em; width: 16em; height: 70em; border-radius: 8em 8em 4em 4em; background: linear-gradient(90deg, #222, #555, #222); transform: rotate(8deg); transform-origin: bottom; }
/* the fire button sits on top of the stick and tilts with it, about the same pivot */
.jfire { left: 52em; bottom: 116em; width: 26em; height: 14em; border-radius: 7em 7em 4em 4em; background: radial-gradient(ellipse at 40% 30%, #ff5a48, #c3160b 70%); transform: rotate(8deg); transform-origin: 13em 80em; }
.jfire2 { left: 22em; bottom: 46em; width: 18em; height: 12em; border-radius: 50%; background: #d71e10; }
.jcable { left: 65em; bottom: 0; width: 70em; height: 22em; border-bottom: 4em solid #111; border-left: 4em solid #111; border-radius: 0 0 0 30em; opacity: 0; }
.joystick.on .jcable { opacity: 1; }
.jtype { /* which kind is plugged in, printed on the base; its em is 10 of the joystick's */
  left: 1em; bottom: 2.7em; width: 11em; text-align: center; font: bold 10em/1 Arial, sans-serif; letter-spacing: .08em; color: #ffcf6b;
}
.joystick:active .jstick, .joystick:active .jfire { transform: rotate(-10deg); }

/* ----- Datacorder: 1em = 1/330 of its width (full size) or 1/520 (strip) ----- */
.recwrap { grid-area: rec; position: relative; justify-self: start; font-size: calc(var(--P) * 5.5 / 330); }
.recorder {
  position: relative; font-size: 1em;
  display: grid; grid-template-columns: 230em 62em; grid-template-areas: "brand brand" "door side" "speed speed" "keys keys";
  gap: 10em 12em; padding: 10em 14em 22em; border-radius: 14em 14em 10em 10em; color: #a8a49c;
  background: linear-gradient(180deg, #4a4a4c, #2e2e30 60%, #262628);
  box-shadow: 0 20em 30em rgba(0,0,0,.55), inset 0 1px 0 rgba(255,255,255,.25);
}
.rbrand { grid-area: brand; font: bold italic 13em Georgia, serif; color: #d8d2c4; letter-spacing: .08em; }
.rbrand small { font: normal .7em Tahoma, sans-serif; color: #8d8a84; letter-spacing: .2em; margin-left: .6em; }
.cap { font-size: 8em; letter-spacing: .1em; text-align: center; }
.door {
  grid-area: door; position: relative; height: 150em; border-radius: 6em; background: #111; cursor: pointer; overflow: hidden;
  box-shadow: inset 0 0 0 2em #000, inset 0 4em 10em rgba(0,0,0,.9), 0 1px 0 rgba(255,255,255,.15);
}
.door::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(160deg, rgba(255,255,255,.14), transparent 40%); }
.cass, .deckbed { position: absolute; left: 10em; top: 12em; width: 210em; height: 128em; }
.cass {
  border-radius: 6em; display: none;
  background: linear-gradient(#e4ddcc, #cfc6b0); box-shadow: inset 0 0 0 2em #b8ae96;
}
.recorder.loaded .cass { display: block; }
/* what an empty deck shows: the two drive spindles, the tape head, capstan and pinch roller */
.spindle {
  position: absolute; top: 50em; width: 30em; height: 30em; margin: -15em 0 0 -15em; border-radius: 50%;
  background: radial-gradient(circle, #f2f2f2 0 3em, transparent 3.5em), repeating-conic-gradient(#e8e8e8 0 14deg, transparent 14deg 60deg),
    radial-gradient(circle, #9a9a9a 0 9em, #5a5a5a 9.5em 13em, #3c3c3c 13.5em);
  box-shadow: 0 2em 4em rgba(0,0,0,.8);
}
.spindle.l { left: 65em; } .spindle.r { left: 145em; }
.recorder.playing .spindle { animation: spin 1.1s linear infinite; }
.head { position: absolute; left: 88em; top: 106em; width: 34em; height: 18em; border-radius: 3em 3em 0 0; background: linear-gradient(#f4f4f4, #9a9a9a 60%, #6e6e6e); box-shadow: 0 0 0 1.5em #222; }
.head::after { content: ''; position: absolute; left: 13em; top: 2em; width: 8em; height: 6em; background: #2a2a2a; border-radius: 1em; }
.capstan { position: absolute; left: 140em; top: 110em; width: 5em; height: 5em; border-radius: 50%; background: #ddd; box-shadow: 0 0 0 1em #555; }
.roller { position: absolute; left: 150em; top: 106em; width: 14em; height: 14em; border-radius: 50%; background: radial-gradient(circle, #666 0 2em, #111 2.5em); }
.guide { position: absolute; top: 112em; width: 6em; height: 6em; border-radius: 50%; background: #bbb; box-shadow: 0 0 0 1em #444; }
.guide.l { left: 40em; } .guide.r { left: 172em; }
.clabel { position: absolute; left: 10em; right: 10em; top: 8em; height: 76em; border-radius: 3em; background: #f7f2e6; border-top: 9em solid #d70000; }
.clabel::after { content: ''; position: absolute; left: 0; right: 0; bottom: 6em; height: 4em; background: #00a7d6; }
.clabel b { position: absolute; left: .67em; right: .67em; top: .25em; font: bold 12em 'Courier New', monospace; color: #222; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cwin { position: absolute; left: 34em; right: 34em; top: 30em; height: 40em; border-radius: 20em; background: #2a2018; box-shadow: inset 0 0 0 2em #111; overflow: hidden; }
.pack { position: absolute; top: 50%; border-radius: 50%; background: #4a2c16; transform: translate(-50%, -50%); }
.pack.l { left: 22%; width: calc(26em + 34em * (1 - var(--f, 0))); height: calc(26em + 34em * (1 - var(--f, 0))); }
.pack.r { left: 78%; width: calc(26em + 34em * var(--f, 0)); height: calc(26em + 34em * var(--f, 0)); }
.hub {
  position: absolute; top: 50%; width: 22em; height: 22em; margin: -11em 0 0 -11em; border-radius: 50%;
  background: repeating-conic-gradient(#eee 0 30deg, #555 30deg 60deg); box-shadow: 0 0 0 3em #ddd;
}
.hub.l { left: 22%; } .hub.r { left: 78%; }
.recorder.playing .hub { animation: spin 1.1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.cbottom { position: absolute; left: 40em; right: 40em; bottom: 6em; height: 26em; background: #bfb59c; clip-path: polygon(8% 0, 92% 0, 100% 100%, 0 100%); }
.rside { grid-area: side; display: flex; flex-direction: column; align-items: center; gap: 8em; }
.counter { display: flex; gap: 2em; padding: 4em; background: #0b0b0b; border-radius: 4em; box-shadow: inset 0 2em 4em #000; }
.counter i { width: .87em; height: 1.33em; background: linear-gradient(#ddd, #fff 50%, #ccc); color: #111; font: bold 15em/1.33 'Courier New', monospace; text-align: center; border-radius: .13em; }
.creset { width: 12em; height: 12em; padding: 0; border: 0; border-radius: 50%; background: #777; box-shadow: 0 2em 0 #111; }
.creset:active { transform: translateY(2em); box-shadow: none; }
.autoload { display: flex; flex-direction: column; align-items: center; gap: 8em; padding: 4em 0 0; border: 0; background: none; }
.autoload .aled { width: 9em; height: 9em; border-radius: 50%; background: #3a0d0d; }
.autoload[aria-pressed="true"] .aled { background: #ff2a1a; box-shadow: 0 0 8em #ff2a1a; }
.autoload .tog { position: relative; width: 34em; height: 16em; border-radius: 8em; background: #111; box-shadow: inset 0 1em 3em #000; }
.autoload .tog::after { content: ''; position: absolute; left: 2em; top: 2em; width: 12em; height: 12em; border-radius: 50%; background: linear-gradient(#ddd, #888); transition: left .15s; }
.autoload[aria-pressed="true"] .tog::after { left: 20em; }
.rspeed { grid-area: speed; display: flex; align-items: center; gap: 10em; }
.slide { cursor: pointer; }
.slot { position: relative; width: 120em; height: 12em; border-radius: 6em; background: #0e0e0e; box-shadow: inset 0 2em 3em #000; }
.sknob {
  position: absolute; left: 0; top: -5em; width: 30em; height: 22em; border-radius: 3em; box-shadow: 0 2em 2em #000; transition: left .15s;
  background: repeating-linear-gradient(90deg, rgba(0,0,0,.25) 0 2em, transparent 2em 5em), linear-gradient(#cfcfcf, #8a8a8a);
}
.slide[data-pos="1"] .sknob { left: 45em; }
.slide[data-pos="2"] .sknob { left: 90em; }
.marks { display: flex; justify-content: space-between; width: 140em; margin-top: 6em; }
.marks span { font-size: 8em; letter-spacing: .1em; }
.slide[data-pos="0"] [data-pos="0"], .slide[data-pos="1"] [data-pos="1"], .slide[data-pos="2"] [data-pos="2"] { color: #ffcf6b; }
.pkeys { grid-area: keys; display: flex; gap: 4em; }
.pk { /* sized in its own em: 15 recorder units */
  flex: 1; min-width: 0; height: 4.13em; padding: 0; border: 0; border-radius: .27em .27em .4em .4em; color: #eee; font: 15em/1 Tahoma, sans-serif;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .27em;
  background: linear-gradient(#a3a3a6, #6c6c70 60%, #5b5b5f); box-shadow: 0 .4em 0 #18181a, inset 0 1px 0 rgba(255,255,255,.45);
}
.pk small { font-size: .53em; letter-spacing: .07em; }
.pk:active, .pk.on { transform: translateY(.33em); box-shadow: 0 .07em 0 #18181a, inset 0 1px 0 rgba(255,255,255,.3); }
.pk.on { color: #7dff8a; }
.pk.rec { background: linear-gradient(#c94136, #8e241c 60%, #7a1d17); }
.pk.rec.on { color: #ffd0c8; text-shadow: 0 0 .4em #ff3a2a; } /* recording */
/* the insert card: the tape's blocks, folded out of the cassette box */
.card {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 5; width: 21.7em; max-height: 25em; overflow-y: auto; margin: 0; padding: .67em 0 .83em;
  background: #f7f2e6; border-top: .75em solid #d70000; border-radius: .33em; box-shadow: 0 .83em 1.67em rgba(0,0,0,.5); list-style: none;
  font: 12em 'Courier New', monospace; color: #333;
}
.card[hidden] { display: none; }
.card li { padding: .1em 1em; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card li:hover { background: #eadfc4; }
.card li.current { background: #ffe79a; }
.card li.head { font-weight: bold; cursor: default; background: none; border-bottom: 1px solid #c8bfa8; margin-bottom: .3em; }

/* ----- hover labels on Dymo tape ----- */
.dymo {
  position: fixed; z-index: 20; pointer-events: none; padding: 3px 10px 4px; border-radius: 2px;
  background: linear-gradient(#2a2a2a, #0d0d0d); box-shadow: 0 2px 4px rgba(0,0,0,.6);
  font: bold 12px Arial, sans-serif; letter-spacing: .12em; text-transform: uppercase; color: #f4f4f4;
  text-shadow: 0 -1px 0 rgba(0,0,0,.9), 0 1px 0 rgba(255,255,255,.35);
  clip-path: polygon(4px 0, calc(100% - 4px) 0, 100% 50%, calc(100% - 4px) 100%, 4px 100%, 0 50%);
}
.dymo[hidden] { display: none; }

/* ----- the manual, opened -----
   Every page has the same shape (11:14) and is laid out as 550 x 700 or smaller. retro.js sets --pw and --ph (a page's
   size on the screen), --z (how much the text is scaled, never below .85) and --bw (the open book: one or two pages),
   and flows longer chapters onto more pages. */
.book {
  --pw: 550px; --ph: 700px; --z: 1; --bw: 1100px;
  width: var(--bw); max-width: none; max-height: none; padding: 0; border: 0; background: none; overflow: visible; color: #111;
}
.book::backdrop { background: rgba(10,6,3,.7); }
.pages { display: flex; zoom: var(--z); filter: drop-shadow(0 18px 24px rgba(0,0,0,.6)); }
.page {
  position: relative; flex: none; width: calc(var(--pw) / var(--z)); height: calc(var(--ph) / var(--z)); overflow-y: auto;
  padding: 46px 52px 54px; background: #fbfaf6; font: 13.5px/1.4 Arial, Helvetica, sans-serif; text-align: justify;
}
.page[hidden] { display: none; }
/* in a spread the odd pages are on the left, the even ones on the right, shaded towards the binding */
.book:not(.single) .page:nth-child(odd) { border-radius: 4px 0 0 4px; background: linear-gradient(90deg, #fbfaf6 85%, #e9e6dd); }
.book:not(.single) .page:nth-child(even) { border-radius: 0 4px 4px 0; background: linear-gradient(90deg, #e9e6dd, #fbfaf6 15%); }
.page.contents h1 { margin-bottom: 24px; }
.toc { list-style: none; margin: 0 0 28px; padding: 0; }
.toc button { display: flex; align-items: baseline; gap: 6px; width: 100%; padding: 9px 0; border: 0; background: none; cursor: pointer; font: bold 16px Arial, sans-serif; color: #111; text-align: left; }
.toc button i { flex: 1; border-bottom: 2px dotted #555; }
.toc button:hover span { text-decoration: underline; }
.tocnote { color: #444; }
.page h1 { font: bold 25px/1.1 Arial, sans-serif; margin: 0 0 10px; text-align: left; }
.page h2 { font: bold 15px Arial, sans-serif; margin: 16px 0 4px; }
.page p { margin: 0 0 8px; }
.page p + p { text-indent: 1em; }
.page ol { margin: 0 0 8px; padding: 0; list-style: none; }
.page ol li { margin-bottom: 6px; }
.page ol li b:first-child { display: inline-block; width: 18px; }
.page table { border-collapse: collapse; width: 100%; font-size: 13px; margin: 4px 0 8px; }
.page td { padding: 4px 6px; border-bottom: 1px solid #ccc; vertical-align: top; text-align: left; }
.page td:first-child { width: 34%; }
.page kbd { display: inline-block; font: bold 11px Arial, sans-serif; padding: 1px 5px; border: 1px solid #333; border-radius: 3px; background: #fff; box-shadow: 0 1px 0 #333; }
.skey { display: inline-block; font: bold 10px Arial, sans-serif; color: #fff; background: #222; padding: 2px 5px; border-radius: 2px; }
.page .figure { display: block; width: 100%; max-width: 440px; max-height: calc(100% - 12px); margin: 4px auto 8px; } /* never taller than a page */
.page ol.parts li { margin-bottom: 3px; font-size: 13px; }
.page ol.parts li b + b { width: auto; margin-right: 4px; }
.tabs button:last-child { color: #fff; }
.page .fig { border: 1px solid #111; padding: 8px 10px; margin: 8px 0 10px; font: 12px 'Courier New', monospace; background: #fff; text-align: left; }
.page .pn { position: absolute; bottom: 20px; font-size: 13px; }
.page:nth-child(odd) .pn { left: 52px; } .page:nth-child(even) .pn { right: 52px; }
.page .stripes { position: absolute; right: 52px; top: 24px; height: 10px; }
.page .stripes i { width: 9px; }
.pages::after { /* spiral binding down the middle */
  content: ''; position: absolute; left: 50%; top: 14px; bottom: 14px; width: 24px; margin-left: -12px; border-radius: 12px; pointer-events: none;
  background: repeating-linear-gradient(180deg, transparent 0 6px, #1b1b1b 6px 10px, #555 10px 11px, transparent 11px 18px);
}
.pages { position: relative; }
.tabs { position: absolute; left: 100%; top: 50px; display: flex; flex-direction: column; gap: 6px; }
.tabs button {
  width: 98px; padding: 8px 10px; border: 0; border-radius: 0 4px 4px 0; text-align: left; color: #fff; background: var(--c);
  font: bold 12px Arial, sans-serif; box-shadow: 2px 2px 4px rgba(0,0,0,.4); transform: translateX(-6px); transition: transform .1s;
}
.tabs button.on, .tabs button:hover { transform: none; }
.bclose { position: absolute; left: calc(100% + 8px); top: 0; width: 34px; height: 34px; border: 0; border-radius: 50%; background: #f3e6d2; color: #111; font-size: 15px; }
.turn { /* turned-up page corners */
  position: absolute; bottom: 0; z-index: 2; width: 46px; height: 46px; padding: 0; border: 0;
  background: linear-gradient(135deg, transparent 50%, #d8d3c6 50%, #f3f0e8); box-shadow: -2px -2px 4px rgba(0,0,0,.15);
}
.turn.prev { left: 0; transform: scaleX(-1); }
.turn.next { right: 0; }
.turn[hidden] { display: none; }

/* ================= phones =================
   The recorder keeps its full layout (tape on top, keys below); in portrait it is turned 90 degrees.
   --B is the height of the row of gadgets: the manual, the recorder, the Multiface and the joystick. */
@media (max-height: 520px) and (orientation: landscape), (max-width: 700px) {
  .room { align-items: end; column-gap: 8px; row-gap: 8px; padding: 8px; }
  .recorder { width: 330em; height: 334em; }
  .card { right: auto; left: 0; }
  .gear .multiface { margin: 0; }
}

/* ================= phone, landscape: the TV, with its controls at the side, fills the height on the left;
   on the right the Multiface and joystick, then the manual and the Datacorder, then the computer in front.
   --R is the width left of the TV, --B the height of the manual and recorder, --G of the Multiface and joystick. */
@media (max-height: 520px) and (orientation: landscape) {
  :root {
    --H: calc(var(--vh100) - 20px); --W: calc(var(--H) / .646);
    --R: calc(var(--vw100) - 24px - var(--W));
    --B: min(calc((var(--R) - 8px) / 1.72), calc(var(--H) * .42)); --G: calc(var(--B) * .35);
    --P: min(calc(var(--R) / 11.4), calc((var(--H) - var(--B) - var(--G) - 16px) / 7.1));
  }
  .room {
    grid-template-columns: auto 1fr auto auto; justify-content: stretch; align-items: center;
    grid-template-areas: "tv mf joy rack" "tv man rec rec" "tv desk desk desk";
  }
  .tv { align-self: start; }
  .desk { justify-self: center; --p: var(--P); --q: min(calc(var(--P) * 7.06 / 7.3), calc(var(--R) / 18.4)); }
  .gear .manualbook { --mh: var(--B); justify-self: end; }
  .recwrap { font-size: calc(var(--B) / 334); justify-self: start; }
  .gear .multiface { font-size: calc(var(--G) * .8 / 80); justify-self: end; align-self: end; }
  .gear .joystick { font-size: calc(var(--G) / 140); justify-self: center; align-self: end; }
  .gear .rack { --P: calc(var(--G) / 2.9); align-self: end; } /* as tall as the Multiface-and-joystick row */
}

/* ================= phone, portrait: TV, computer, then the manual beside the turned recorder ================= */
@media (max-width: 700px) {
  :root { --W: min(calc(var(--vw100) - 16px), calc((var(--vh100) - 40px) / 2.2)); --P: calc(var(--W) / 13); }
  .room {
    grid-template-columns: auto auto auto; justify-content: center;
    grid-template-areas: "tv tv tv" "desk desk desk" "man rec rack" "man mf joy";
  }
  .tv { justify-self: center; }
  #btnZoom { font-size: calc(var(--W) * .025); padding: calc(var(--W) * .0195) calc(var(--W) * .022); }
  .desk { --p: calc(var(--W) / 13); --q: calc(var(--W) / 18.6); }
  .gear .manualbook { --mh: calc(var(--W) * .56); justify-self: end; align-self: start; }
  .recwrap { font-size: calc(var(--W) * .37 / 330); width: 334em; height: 330em; justify-self: center; }
  .recorder { position: absolute; left: 0; top: 0; transform-origin: 0 0; transform: translateX(334em) rotate(90deg); }
  .gear .multiface { font-size: calc(var(--W) * .22 / 124); justify-self: center; align-self: center; }
  .gear .joystick { font-size: calc(var(--W) * .16 / 140); justify-self: center; align-self: center; }
}



/* ================= the cassette rack: my tapes ================= */
.rack {
  position: relative; display: flex; flex-direction: column; gap: 2px; padding: 3px 4px 6px;
  width: calc(var(--P) * 2.6); border-radius: 3px; background: linear-gradient(90deg, #2b2b2b, #3c3c3c 50%, #262626);
  box-shadow: 4px 6px 10px rgba(0,0,0,.5), inset 0 0 0 2px #1a1a1a;
}
.racklabel { /* a strip of label tape on the front of the rack */
  margin: 0 0 2px; padding: 0; border: 0; border-radius: 1px; cursor: pointer; background: #111;
  font: bold calc(var(--P) * .15)/calc(var(--P) * .3) Arial, sans-serif; letter-spacing: .12em; color: #eee;
}
.racklabel:hover { color: #ffcf6b; }
.rack .slots { display: flex; flex-direction: column; gap: 2px; }
.spine { /* cassette boxes seen from the spine */
  display: block; width: 100%; height: calc(var(--P) * .36); padding: 0 0 0 4px; border: 0; border-radius: 1px; cursor: pointer;
  background: linear-gradient(#f4f1ea, #dcd6c8); border-left: calc(var(--P) * .3) solid var(--c); box-shadow: 0 1px 0 rgba(0,0,0,.5);
  font: bold calc(var(--P) * .15)/calc(var(--P) * .36) Arial, sans-serif; color: #222; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.spine:hover { transform: translateX(3px); }
.spine.empty { background: #121212; border-left-color: #121212; box-shadow: inset 0 1px 3px #000; } /* an empty place */
.spine.empty:hover { background: #1c1c1c; }
.gear .rack { grid-area: mf; justify-self: end; align-self: start; margin-top: calc(var(--P) * 1.5); }
/* phones: the rack has its own place (portrait: beside the recorder; landscape: beside the joystick) */
@media (max-height: 520px), (max-width: 700px) { .gear .rack { grid-area: rack; justify-self: center; align-self: center; margin: 0; } }


/* one page at a time (portrait): the spiral binding down its left edge, the page number in the outer corner */
.book.single .pages::after { left: 0; }
.book.single .page { border-radius: 0 4px 4px 0 !important; background: linear-gradient(90deg, #e9e6dd, #fbfaf6 15%) !important; }
.book.single .page .pn { left: auto !important; right: 52px !important; }
/* small pages (phones): narrower margins */
.book.compact .page { padding: 30px 30px 50px; }
.book.compact .page:nth-child(odd) { padding-right: 40px; } .book.compact .page:nth-child(even), .book.compact.single .page { padding-left: 40px; } /* clear of the binding */
.book.compact .page .pn { bottom: 18px; } .book.compact .page:nth-child(odd) .pn { left: 30px; } .book.compact .page:nth-child(even) .pn, .book.compact.single .page .pn { right: 30px !important; }
.book.compact .page .stripes { right: 30px; top: 14px; }
/* narrow screens (phones held upright): the chapter tabs in a row above the page, the close button above them */
.book.tabtop { margin-top: 56px; translate: 6px; } /* a little right of centre: the binding sticks out on the left */
.book.tabtop .tabs { position: static; flex-direction: row; gap: 4px; margin-bottom: 4px; }
.book.tabtop .tabs button { width: auto; flex: 1; transform: none; border-radius: 4px 4px 0 0; padding: 6px 3px; font-size: 11px; white-space: nowrap; overflow: hidden; opacity: .7; }
.book.tabtop .tabs button.on { opacity: 1; }
.book.tabtop .bclose { left: auto; right: 0; top: -44px; }
/* short landscape screens (phones held sideways): slim tabs with only the chapter number */
.book.tabslim .tabs button { width: 40px; padding: 7px 0 7px 8px; }
.book.tabslim .tabs button span { display: none; }
/* small pages: a two-column table puts each name above its text */
.book.compact .page table:not(.keys2) tr { display: block; border-bottom: 1px solid #ccc; }
.book.compact .page table:not(.keys2) td { display: block; width: auto; border: 0; padding: 3px 4px; }
.book.compact .page table:not(.keys2) td:first-child { padding-bottom: 0; font-weight: bold; }
.page p.cont { text-indent: 0; } /* the rest of a paragraph, carried over from the page before */

/* menus drawn on the Spectrum's screen (screenmenu.js): over the picture, only while one is open */
.osdscreen { display: none; position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; z-index: 3; cursor: pointer; }
.osdscreen.on { display: block; }

/* the shortcuts in the manual: two columns of key and action */
.page table.keys2 tbody { display: grid; grid-template-columns: 1fr 1fr; column-gap: 14px; }
.page table.keys2 tr { display: flex; align-items: baseline; border-bottom: 1px solid #ccc; }
.page table.keys2 td { padding: 3px 4px; border: 0; }
.page table.keys2 td:first-child { flex: 0 0 auto; min-width: 52px; width: auto; white-space: nowrap; } /* "Num +" stays on one line */
/* volume and picture: one row per action, every-keyboard key then number-pad key */
.page table.keys2.tv tbody { display: table-row-group; }
.page table.keys2.tv tr { display: table-row; }
.page table.keys2.tv td { border-bottom: 1px solid #ccc; padding: 3px 8px 3px 4px; white-space: nowrap; }
.page table.keys2.tv td:last-child { white-space: normal; width: 100%; }

/* the author's note on the About page */
.page .memoir { font-style: italic; }
.page .sign { text-align: right; font: italic bold 15px Georgia, serif; margin-top: 4px; }

/* the knob labels can be clicked: VOLUME mutes, COLOUR changes the picture */
.knobwrap span { cursor: pointer; user-select: none; }
.knobwrap span:hover { color: #e0d6c4; }

/* browsers with a minimum font size (Messenger's on Android) would enlarge the tiny labels: textfix.js then sets
   --k (2-4) and the class upscale, the desk is laid out k times larger and shrunk back to the screen */
html.upscale { --vw100: calc(100vw * var(--k)); --vh100: calc(100vh * var(--k)); }
@supports (height: 100svh) { html.upscale { --vh100: calc(100svh * var(--k)); } }
html.upscale body { overflow-x: hidden; }
html.upscale .room { position: absolute; left: 0; top: 0; width: calc(100vw * var(--k)); transform: scale(calc(1 / var(--k))); transform-origin: 0 0; }

/* inside Messenger, Facebook or Instagram: offer the phone's own browser */
.inapp { position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 30; display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 6px; background: #f6f1e4; color: #1b1b1b; box-shadow: 0 6px 20px rgba(0,0,0,.6); font: 14px/1.35 Arial, Helvetica, sans-serif; }
.inapp p { flex: 1; margin: 0; }
.inapp a { flex: 0 0 auto; padding: 8px 12px; border-radius: 4px; background: #d70000; color: #fff; font-weight: bold; text-decoration: none; }
.inapp button { flex: 0 0 auto; border: 0; background: none; font-size: 18px; color: #555; }

/* touch screens: a long press on a key, a label or a gadget must not select its text or open the phone's menu */
.room { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.room dialog.book { -webkit-user-select: text; user-select: text; } /* the manual can still be selected */

/* the touch joystick, over the bottom corners of the screen */
#touchJoy { --fs: min(22vmin, 110px); --fb: calc(24px + env(safe-area-inset-bottom, 0px)); position: fixed; inset: 0; pointer-events: none; z-index: 40; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#touchJoy[hidden] { display: none; }
.tjstick, .tjfire, .tjoff { position: fixed; pointer-events: auto; touch-action: none; -webkit-tap-highlight-color: transparent; }
.tjstick {
  left: calc(14px + env(safe-area-inset-left, 0px)); bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  width: min(34vmin, 170px); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, rgba(0,0,0,.15), rgba(0,0,0,.45)); border: 2px solid rgba(255,255,255,.3);
}
.tjknob {
  position: absolute; left: 30%; top: 30%; width: 40%; height: 40%; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #555, #111 70%); box-shadow: 0 3px 8px rgba(0,0,0,.6); opacity: .85;
}
.tjfire {
  right: calc(18px + env(safe-area-inset-right, 0px)); bottom: var(--fb);
  width: var(--fs); aspect-ratio: 1; border-radius: 50%; border: 0; padding: 0;
  background: radial-gradient(circle at 35% 30%, #ff5a4a, #b00000 70%); box-shadow: 0 4px 10px rgba(0,0,0,.6); opacity: .8;
  font: bold min(4vmin, 18px) Arial, sans-serif; color: #fff; letter-spacing: .05em;
}
.tjfire.down { transform: scale(.92); opacity: 1; }
.tjoff { /* unplugs it: on a phone the desk's joystick can be under FIRE */
  right: calc(12px + env(safe-area-inset-right, 0px)); bottom: calc(var(--fb) + var(--fs) + 10px);
  padding: 4px 8px; border: 1px solid rgba(255,255,255,.35); border-radius: 12px; background: rgba(0,0,0,.55);
  font: bold 10px Arial, sans-serif; color: #ddd; letter-spacing: .04em;
}
@media (orientation: landscape) { #touchJoy { --fb: 34vh; } } /* above the keyboard's ENTER and SPACE */
