:root{
  /* layout: one column, room canvas first, then the controls for the current mode, then settings */
  --stone:#15120f; --panel:#221d18; --line:#3a322a; --ink:#f0e7d8; --muted:#ab9f8c;
  --gold:#e3a72a; --teal:#2fa89e; --danger:#e5593f;
  --display:"Silkscreen","Courier New",monospace; --body:"Atkinson Hyperlegible",system-ui,sans-serif;
  color-scheme:dark;
}
*{box-sizing:border-box}
html,body{margin:0;background:var(--stone);color:var(--ink);font-family:var(--body);font-size:16px;line-height:1.45}
/* A finger may scroll the page, and nothing else: no zooming by pinching or by tapping twice. */
html,body{touch-action:pan-x pan-y}
/* NOTHING ON THE PAGE CAN BE SELECTED, except the writing in a text box. On a
   phone a long press on any words otherwise selects them, with a magnifying
   glass and a Copy menu over the game; and a press on a picture offers to
   save it ("touch-callout"). The grey flash on a tapped button goes too.
   "text-size-adjust" stops a phone enlarging the writing when it is turned. */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
body{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none;-webkit-tap-highlight-color:transparent}
input,textarea,select{-webkit-user-select:text;user-select:text}
main{max-width:560px;margin:0 auto;padding:14px 16px 40px;display:flex;flex-direction:column;gap:12px}
header{display:flex;align-items:center;justify-content:space-between;gap:10px;flex-wrap:wrap}
.undoButtons{display:flex;gap:6px;margin-left:auto}
.undoButtons button{width:48px;height:42px;padding:0;display:flex;align-items:center;justify-content:center}
.undoButtons svg{width:26px;height:26px;fill:none;stroke:var(--gold);stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round}
.undoButtons button:disabled{opacity:.3;cursor:default}
h1{font-family:var(--display);font-size:18px;font-weight:700;margin:0;color:var(--gold);letter-spacing:.5px}
h2{font-family:var(--display);font-size:13px;font-weight:400;margin:0 0 8px;color:var(--muted);text-transform:uppercase;letter-spacing:1px}
.seg{display:flex;border:1px solid var(--line);border-radius:8px;overflow:hidden}
.seg button{border:0;border-radius:0;background:transparent;color:var(--muted);padding:8px 16px;font-family:var(--display);font-size:13px}
.seg button[aria-pressed="true"]{background:var(--gold);color:#1b1408}
button{font-family:var(--body);font-size:15px;color:var(--ink);background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:9px 12px;cursor:pointer;touch-action:manipulation}
button:focus-visible,input:focus-visible{outline:2px solid var(--gold);outline-offset:2px}
canvas{width:100%;height:auto;display:block;image-rendering:pixelated;border:1px solid var(--line);border-radius:6px;background:#0b0a12;touch-action:none}
.status{font-size:14px;color:var(--muted);min-height:1.45em;font-variant-numeric:tabular-nums}
.status b{color:var(--ink);font-weight:700}
.status .bad{color:var(--danger)}
.tools{display:grid;grid-template-columns:repeat(auto-fill,minmax(58px,1fr));gap:6px}
.tools button{padding:4px;font-size:14px;display:flex;align-items:center;justify-content:center;min-height:56px}
.tools button canvas.icon{width:44px;height:44px;image-rendering:pixelated;pointer-events:none}
.toolGroup{font-family:var(--display);font-size:11px;font-weight:400;margin:14px 0 6px;color:var(--muted);text-transform:uppercase;letter-spacing:1px}
.toolTop{margin-bottom:4px}
.tools button.eraseTool{border-color:#7a2a22}
.tools button.eraseTool[aria-pressed="true"]{border-color:var(--danger,#d9483b);background:#2b1715}
/* The beat as circles (editor.js). */
.turnIcon{width:40px;height:30px;fill:none;stroke:var(--gold);stroke-width:2.5;stroke-linecap:round;stroke-linejoin:round;display:block}
#turnRound{min-width:64px}
#sizes button{min-height:64px;display:flex;align-items:center;justify-content:center}
.sizeIcon rect{fill:#3a3226;stroke:var(--muted);stroke-width:1}
#sizes button[aria-pressed="true"] .sizeIcon rect{fill:#5a4520;stroke:var(--gold)}
.beatDots{display:grid;grid-template-columns:5.5em auto 1fr;gap:10px;align-items:center;margin-bottom:8px;font-size:14px}
.beatDots .dots{display:flex;gap:8px}
.beatDots .dots button{width:30px;height:30px;padding:0;border-radius:50%;border:2px solid var(--gold);background:transparent}
.beatDots .dots button.on{background:var(--gold)}
.beatDots .dots button:disabled{opacity:.25;cursor:default}
.beatDots output{font-size:13px;color:var(--muted)}
.tools button[aria-pressed="true"],#preview[aria-pressed="true"]{border-color:var(--gold);color:var(--gold);background:#2b2315}
.row{display:flex;gap:8px;flex-wrap:wrap}
.pad{touch-action:none;display:flex;justify-content:space-between;align-items:center;gap:12px;padding:4px 6px;user-select:none;-webkit-user-select:none}
.dpad{touch-action:none;position:relative;width:156px;height:156px;flex:none;border-radius:50%;background:radial-gradient(circle,#2a241d 0 62%,transparent 63%)}
.dpad .arm{position:absolute;width:52px;height:52px;display:flex;align-items:center;justify-content:center;background:var(--panel);border:1px solid var(--line);color:var(--muted);font-size:15px;pointer-events:none}
.dpad .on{background:#2b2315;border-color:var(--gold);color:var(--gold)}
#bU{left:52px;top:0;border-radius:10px 10px 0 0;border-bottom:0}
#bD{left:52px;top:104px;border-radius:0 0 10px 10px;border-top:0}
#bL{left:0;top:52px;border-radius:10px 0 0 10px;border-right:0}
#bR{left:104px;top:52px;border-radius:0 10px 10px 0;border-left:0}
.dpad .hub{left:52px;top:52px;border:0}
.face{touch-action:none;position:relative;width:150px;height:156px;flex:none}
.face button{position:absolute;border-radius:50%;font-family:var(--display);padding:0;touch-action:none}
.face .on{filter:brightness(1.25)}
#bT{left:0;top:6px;width:64px;height:64px;font-size:13px;color:var(--gold);border-color:var(--gold);background:#2b2315}
#bX{left:6px;bottom:0;width:48px;height:48px;font-size:11px;color:var(--ink);border-color:var(--line);background:#26201a}
#bJ{right:0;bottom:6px;width:84px;height:84px;font-size:16px;background:var(--teal);border-color:var(--teal);color:#06211f}
.panel{background:var(--panel);border:1px solid var(--line);border-radius:10px;padding:12px}
/* The Tuning section opens and shuts. Its heading is the summary line, with
   a triangle that turns when it is open. */
#tuning summary{cursor:pointer;list-style:none;display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}
#tuning summary::-webkit-details-marker{display:none}
#tuning summary h2{margin:0}
#tuning summary h2::before{content:'';display:inline-block;margin-right:8px;border-left:6px solid currentColor;border-top:5px solid transparent;border-bottom:5px solid transparent;transition:transform .15s}
#tuning[open] summary h2::before{transform:rotate(90deg)}
#tuning[open] summary{margin-bottom:8px}
.set{display:grid;grid-template-columns:1fr auto;gap:2px 10px;align-items:center;margin-bottom:10px}
.set label{font-size:14px}
.set output{font-variant-numeric:tabular-nums;font-size:14px;color:var(--gold)}
.set input{grid-column:1 / span 2;width:100%;accent-color:var(--gold)}
.hint{font-size:13px;color:var(--muted);margin:0}
/* A number with a button either side to lower and raise it: its name, minus, the number, plus, its units. */
.stepper{display:grid;grid-template-columns:4.5em 44px 2.5em 44px 1fr;gap:8px;align-items:center;margin-bottom:8px;font-size:14px}
.stepper output{text-align:center;font-size:18px;color:var(--gold);font-variant-numeric:tabular-nums}
.stepper button{padding:8px 0;font-size:18px}
.stepper button:disabled{opacity:.35}
/* The level's song: Auto and 1 to 8. The pressed one is the choice; under Auto, the one its place gives is outlined. */
.songs{display:grid;grid-template-columns:4.5em 1fr;gap:8px;align-items:center;margin-bottom:8px;font-size:14px}
.songs #songButtons{display:flex;flex-wrap:wrap;gap:4px}
.songs button{min-width:32px;padding:6px 8px;font-size:14px}
.songs button[aria-pressed="true"]{border-color:var(--gold);color:var(--gold);background:#2b2315}
.songs button.byPlace{border-color:var(--gold);border-style:dashed}
.songs output{grid-column:2;color:var(--muted,#a8998a);font-size:13px}
/* A dropdown with its name to the left of it. 16px type stops an iPhone zooming in when it is tapped. */
.leads{display:grid;grid-template-columns:4.5em 1fr;gap:8px;align-items:center;font-size:14px}
.leads select{min-width:0;font-family:var(--body);font-size:16px;color:var(--ink);background:var(--stone);border:1px solid var(--line);border-radius:8px;padding:9px 10px}
.leads select:focus-visible{outline:2px solid var(--gold);outline-offset:2px}
/* The explanations are hidden until asked for with the Show help button. */
.help{display:none}
html.show-help .help{display:block}
textarea{width:100%;height:90px;background:#0f0d0b;color:var(--ink);border:1px solid var(--line);border-radius:8px;font-family:monospace;font-size:12px;padding:8px}
/* On a touch screen every box that can be typed in has 16px writing: an
   iPhone zooms the whole page in when one with smaller writing is tapped,
   and does not zoom out again. ("pointer: coarse" is a finger, not a mouse.) */
@media (pointer:coarse){input,select,textarea{font-size:16px}}
[hidden]{display:none!important}

/* 16px, not smaller: an iPhone zooms the page in when a text box with smaller writing is tapped. */
#layoutName{flex:1;min-width:0;font-family:var(--body);font-size:16px;color:var(--ink);background:var(--stone);border:1px solid var(--line);border-radius:8px;padding:9px 10px}
.layout{display:flex;gap:8px;align-items:center;padding:6px 0;border-top:1px solid var(--line)}
.layout span{flex:1;min-width:0;font-size:14px;overflow-wrap:anywhere}
.layout button{padding:7px 10px;font-size:14px}
.layout.current span{color:var(--gold)}
.layout.draft span{font-style:italic}
.layout .tag{flex:none;font-size:11px;font-style:normal;color:var(--muted);border:1px solid var(--line);border-radius:6px;padding:1px 6px}
.newRoom{width:100%;font-size:16px;display:flex;align-items:center;justify-content:center;gap:10px}
.newRoom .plus{font-size:28px;line-height:1;color:var(--gold);font-weight:700}
.askBox{margin-top:8px;padding:10px;border:1px solid var(--gold);border-radius:8px}
.askBox label{display:block;font-size:14px;margin-bottom:6px}
.askBox input{min-width:0;flex:1;font-size:16px}
.pinRow{margin-top:8px;align-items:center;font-size:13px;color:var(--muted)}
.pinRow span{flex:1}
.layout button:disabled{opacity:.35}

/* The two halves of the page. In one column they simply follow each other. */
.stage,.controls{display:flex;flex-direction:column;gap:12px;min-width:0}

/* WIDE MODE: in a window wide enough, in the Windows app or a browser (the
   website's builder since 23 November 2026, at Jon's asking): the room on
   the left, as large as the window's height allows, and the controls in a column of their own on
   the right that scrolls by itself. The room keeps its shape (768 by 672), so
   its width is worked out from the height left over once the title and the
   status line are allowed for. Making the window bigger makes the room bigger. */
@media (min-width:900px){
  html:not(.game-only),html:not(.game-only) body{height:100%;overflow:hidden}
  html:not(.game-only) main{max-width:none;height:100vh;margin:0;padding:12px;flex-direction:row;gap:16px;align-items:stretch}
  html:not(.game-only) .stage{flex:1 1 auto;align-items:center}
  html:not(.game-only) .stage header{width:100%}
  /* As wide as there is room for, or as wide as the height left over allows, whichever is less. */
  html:not(.game-only) .stage canvas{width:min(100%, calc((100vh - 110px) * 768 / 672));height:auto}
  /* PLAYING, the room is never magnified more than 4 times. Play shows one
     SNES screen, 256 pixels wide, so 4 times is 1024. (Editing shows the whole
     room at once, which wants all the space it can have.) */
  html:not(.game-only)[data-mode="play"] .stage canvas{width:min(100%, calc((100vh - 110px) * 768 / 672), 1024px)}
  html:not(.game-only) .stage .status{width:100%}
  html:not(.game-only) .controls{flex:0 0 440px;overflow-y:auto;padding-right:6px}
}

/* IN GAME MODE only the screen, the on-screen controls and the mode buttons
   are shown: the status line, the panels and the help are the builder's, not
   the game's. (state.js sets data-run on the page.) */
html[data-run="game"] .stage .status,
html[data-run="game"] .controls > section.panel,
html[data-run="game"] #playUI .hint{display:none}

/* GAME MODE LAYOUT. The page's boxes are set aside ("display: contents" lets
   their insides be laid out as if the boxes were not there), so that the
   title bar, the screen, the d-pad and the buttons can be placed on one grid.

   WIDER THAN TALL: the screen in the middle, as large as the height allows,
   with the d-pad on its left and the buttons on its right. */
html[data-run="game"] .stage,
html[data-run="game"] .controls,
html[data-run="game"] #playUI,
html[data-run="game"] .pad{display:contents}
/* THE GAME IS PINNED TO THE SCREEN. In Game mode the page is exactly the size
   of the screen and cannot be scrolled, dragged or bounced: a thumb sliding
   off the d-pad moves nothing. "dvh" is the height of the part of the screen
   that can be seen now, which on a phone is less than "vh" while the
   browser's address bar is showing; each height is given in vh first for
   browsers that do not know dvh. (Edit and Play still scroll: their tools
   and settings do not fit on one screen.) */
html[data-run="game"],html[data-run="game"] body{height:100%;overflow:hidden;overscroll-behavior:none;touch-action:none}
html[data-run="game"] body{position:fixed;left:0;right:0;top:0;bottom:0}
html[data-run="game"] main,
html.in-app[data-run="game"] main{
  display:grid;max-width:none;height:100vh;height:100dvh;margin:0;padding:12px 16px;gap:12px 24px;
  grid-template-columns:1fr auto 1fr;grid-template-rows:auto 1fr;
  grid-template-areas:"head head head" "left screen right";align-items:center}
html[data-run="game"] header{grid-area:head;width:100%}
/* Low down, level with the bottom of the screen, where the thumbs rest. */
html[data-run="game"] .dpad{grid-area:left;justify-self:end;align-self:end}
html[data-run="game"] .face{grid-area:right;justify-self:start;align-self:end}
/* As wide as the height left under the title allows, but leaving room either
   side for the d-pad and the buttons (156 pixels each, plus the gaps), and
   never more than 4 times the SNES screen. */
html[data-run="game"][data-mode="play"] .stage canvas,
html.in-app[data-run="game"][data-mode="play"] .stage canvas{
  grid-area:screen;width:min(calc((100vh - 90px) * 768 / 672), calc(100vw - 420px), 1024px);
  width:min(calc((100dvh - 90px) * 768 / 672), calc(100vw - 420px), 1024px)}

/* THE GAME ON ITS OWN (the page asked for as /play: see index.html). There is
   no title bar: nothing to switch to. So the screen has the height the bar
   took. Installed on a phone the page reaches the very edges of the glass,
   so its padding is at least as much as the phone says its notch and rounded
   corners need ("safe-area-inset"). */
html.game-only header{display:none}
/* The builder's tools are never used on the game's own page. Hidden here,
   in the stylesheet, they never show at all: until 23 November 2026 they
   were hidden by the scripts, and on a slow connection the tools showed for
   several seconds while those arrived. */
html.game-only #editUI{display:none}
html.game-only[data-run="game"] main{
  padding:max(12px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left))}
/* "--bar" is the height the offer to install takes at the top of the page,
   with its gap: nothing, until the offer is showing (below). */
html.game-only{--bar:0px}
html.game-only[data-run="game"][data-mode="play"] .stage canvas{
  width:min(calc((100vh - 24px - var(--bar)) * 768 / 672), calc(100vw - 420px), 1024px);
  width:min(calc((100dvh - 24px - var(--bar) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 768 / 672), calc(100vw - 420px - env(safe-area-inset-left) - env(safe-area-inset-right)), 1024px)}

/* THE FULL HEIGHT, ON ITS SIDE (Jon, 23 November 2026). The game on its own,
   wider than tall, with the offer to install not showing: the screen is the
   whole height of the glass, top to bottom, with no margin above or below
   (only what a notch or rounded corners need). Its width allows exactly for
   the d-pad (156), the buttons (150), the two gaps beside the screen (24
   each) and the edges (16 each): 392 in all. Where that is not room enough
   for the full height (a small phone), it is as tall as the width allows.
   Touch screens only ("pointer: coarse": a finger, not a mouse), so phones
   and tablets: a computer's window keeps its margins. */
@media (orientation:landscape) and (pointer:coarse){
  html.game-only:not(.install-offered)[data-run="game"] main{
    row-gap:0;padding-top:env(safe-area-inset-top);padding-bottom:env(safe-area-inset-bottom)}
  html.game-only:not(.install-offered)[data-run="game"][data-mode="play"] .stage canvas{
    width:min(calc(100vh * 768 / 672), calc(100vw - 392px), 1024px);
    width:min(calc((100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 768 / 672), calc(100vw - 392px - env(safe-area-inset-left) - env(safe-area-inset-right)), 1024px)}
}

/* THE OFFER TO INSTALL (ui/install.js): a slim bar where the title bar would
   be, on the game's title screen. While it shows, the screen gives up its
   height to it, so that nothing is pushed off the bottom. */
#installBar{grid-area:head;display:flex;align-items:center;gap:10px;width:100%;min-height:44px;padding:6px 8px 6px 12px;
  background:var(--panel);border:1px solid var(--gold);border-radius:8px;font-size:14px;line-height:1.3}
#installBar .words{flex:1;min-width:0}
#installBar b{color:var(--gold);font-weight:700}
#installBar svg{width:18px;height:18px;vertical-align:-4px;fill:none;stroke:var(--gold);stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
#installBar .go{flex:none;padding:7px 14px;font-size:14px;font-weight:700;background:var(--gold);border-color:var(--gold);color:#1b1408}
#installBar .close{flex:none;width:36px;height:32px;padding:0;font-size:14px;color:var(--muted);background:transparent;border-color:transparent}
html.install-offered{--bar:56px}

/* TALLER THAN WIDE: the screen at the top, the d-pad and the buttons under it. */
@media (orientation:portrait){
  html[data-run="game"] main,
  html.in-app[data-run="game"] main{
    max-width:560px;height:100vh;height:100dvh;margin:0 auto;
    grid-template-columns:minmax(0,1fr) minmax(0,1fr);grid-template-rows:auto auto 1fr;
    grid-template-areas:"head head" "screen screen" "left right"}
  /* The last row takes whatever height is left, and the d-pad and buttons
     sit at the bottom of it: at the foot of the screen, where thumbs rest,
     however tall the phone. */
  html[data-run="game"] .dpad{justify-self:start;align-self:end}
  html[data-run="game"] .face{justify-self:end;align-self:end}
  /* As wide as the page, unless that would push the d-pad and the buttons
     off the bottom of the screen: then as wide as the height left over
     allows, once the title bar (up to 100 pixels), the controls (156) and
     the gaps and edges (48) are taken off. */
  html[data-run="game"][data-mode="play"] .stage canvas,
  html.in-app[data-run="game"][data-mode="play"] .stage canvas{
    justify-self:center;
    width:min(100%, calc((100vh - 304px) * 768 / 672));
    width:min(100%, calc((100dvh - 304px) * 768 / 672))}
  /* The game on its own has no title bar to allow for: only the controls (156) and the gaps and edges (48). */
  html.game-only[data-run="game"][data-mode="play"] .stage canvas{
    width:min(100%, calc((100vh - 204px - var(--bar)) * 768 / 672));
    width:min(100%, calc((100dvh - 204px - var(--bar) - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 768 / 672))}
}
