/* The web simulator's page (web/README.md), in the website's look
   (site/assets/site.css): its colours, its header, Sora for the name. The
   teal of the focus highlight, on a navy that frames the console's screen. */
/* Light by default; dark when the page says so (data-theme, set before the
   first paint from the URL, the choice kept or the system's). */
@font-face {
  font-family: "Sora";
  src: url("sora.woff2") format("woff2");
  font-weight: 100 800;
  font-display: swap;
}
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f8;
  --text: #121b2c;
  --muted: #536079;
  --line: #dbe2ec;
  --accent: #0a705f;
  --accent-text: #ffffff;
  --warn: #a8720a;
  --stop: #c62a2f;
  --frame: #0f1724;
  --radius: 10px;
  --display: "Sora", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0b1424;
  --surface: #111d31;
  --surface-2: #17253d;
  --text: #e8eef7;
  --muted: #a9b6cc;
  --line: #22324f;
  --accent: #2ec4a6;
  --accent-text: #05140f;
  --warn: #f0b429;
  --stop: #ff7a7e;
  --frame: #05090f;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  display: flex;
  flex-direction: column;
}
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.top {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 16px;
  /* Under an iPhone's notch or status bar (viewport-fit=cover; from the
     home screen, the status bar over the page): kept clear of them. */
  padding-top: max(10px, env(safe-area-inset-top));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; font: 700 20px var(--display); letter-spacing: -0.01em; }
.brand b { color: var(--accent); font-weight: 700; }
.nav { display: flex; gap: 18px; }
.nav a { color: var(--muted); text-decoration: none; font-weight: 500; font-size: 15px; white-space: nowrap; }
.nav a:hover { color: var(--text); }
.brand .tag {
  font-size: 12px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.build { flex: 1; min-width: 0; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.build a { color: inherit; }
.build code { font-size: 12px; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 0;
}
.layout.no-panel { grid-template-columns: minmax(0, 1fr); }
.layout.no-panel .panel { display: none; }

.stage { padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; overflow: auto; }
.screen {
  position: relative;
  width: 100%;
  max-width: calc((100vh - 236px) * 16 / 9);
  min-width: 0;
  margin: 0 auto;
  background: var(--frame);
  border-radius: 14px;
  padding: 10px;
  box-shadow: 0 8px 30px rgb(0 0 0 / 0.18);
}
canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  outline: none;
  touch-action: none;
  background: #000;
}
canvas:focus-visible { box-shadow: 0 0 0 3px var(--accent); }

.overlay {
  position: absolute;
  inset: 10px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--frame);
  color: #c9d3e1;
  text-align: center;
  padding: 24px;
}
.overlay.error .spinner { display: none; }
.overlay p { margin: 0; max-width: 46ch; }
.overlay button { margin-top: 4px; }
.spinner {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 3px solid rgb(255 255 255 / 0.15);
  border-top-color: #22b39a;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.controls {
  width: 100%;
  max-width: calc((100vh - 236px) * 16 / 9);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.keys { margin: 0; color: var(--muted); font-size: 13px; }
@media (pointer: coarse) { .keys { display: none; } }
kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: center;
}
.control-actions { display: flex; gap: 8px; flex-wrap: wrap; }
/* The tools (simulator.js' setUpTools()): a row, behind a button on a phone. */
.tools > summary { display: none; list-style: none; cursor: pointer; }
.tools > summary::-webkit-details-marker { display: none; }
.tool-list { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 600px) {
  .tools > summary { display: inline-block; }
  .tools > summary::after { content: " ▾"; }
  .tools[open] > summary::after { content: " ▴"; }
  .tools[open] .tool-list { margin-top: 8px; }
}
/* Data saver: the start waits for a touch (simulator.js' waitForTap()). */
.overlay.waiting .spinner { display: none; }
#record[aria-pressed="true"] { border-color: #d1495b; color: #d1495b; }
#record[aria-pressed="true"]::before { content: "● "; }

/* The console's time moved on (skip=): a row under the controls. */
.time {
  width: 100%;
  max-width: calc((100vh - 236px) * 16 / 9);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}
.time-label { color: var(--muted); }
.time-buttons { display: flex; gap: 6px; flex-wrap: wrap; }
.time .btn { padding: 4px 10px; font-size: 13px; }
.time .btn:disabled { opacity: 0.45; cursor: default; }
.skip-shown { color: var(--accent); font-weight: 600; font-variant-numeric: tabular-nums; }

/* What the simulated console does now, under the time. */
.console-line {
  width: 100%;
  max-width: calc((100vh - 236px) * 16 / 9);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 13px;
}
.console-line[hidden] { display: none; }
.console-label { color: var(--muted); }
.console-text { font-variant-numeric: tabular-nums; }
.console-text::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
}
.console-line[data-tone="warn"] .console-text::before { background: var(--warn); }
.console-line[data-tone="stop"] .console-text { color: var(--stop); font-weight: 600; }
.console-line[data-tone="stop"] .console-text::before { background: var(--stop); }
.console-line[data-tone="free"] .console-text::before { background: var(--muted); }
.console-living { color: var(--muted); font-size: 12px; }
.console-line .btn { padding: 4px 10px; font-size: 13px; }

.overlay progress { width: min(260px, 70%); accent-color: #22b39a; }
.toast {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 7px 14px;
  border-radius: 8px;
  background: rgb(15 23 36 / 0.9);
  color: #e6ebf2;
  font-size: 13px;
  pointer-events: none;
}

.pad {
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
/* The screen and the pad are played with: a long press opens no loupe,
   selection or menu (iOS), a tap leaves no grey flash. */
.screen, .pad {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.pad button {
  touch-action: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  min-width: 48px;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
}
.pad button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.pad-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.shoulders button.small { min-width: 40px; border-radius: 999px; }
.dpad, .face { display: grid; grid-template: repeat(3, 48px) / repeat(3, 48px); gap: 4px; }
.dpad .up { grid-area: 1 / 2; } .dpad .left { grid-area: 2 / 1; }
.dpad .right { grid-area: 2 / 3; } .dpad .down { grid-area: 3 / 2; }
.face button { border-radius: 50%; }
.face .x { grid-area: 1 / 2; } .face .y { grid-area: 2 / 1; }
.face .a { grid-area: 2 / 3; } .face .b { grid-area: 3 / 2; }

.panel {
  border-left: 1px solid var(--line);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tab {
  border: 0;
  background: none;
  padding: 10px 12px;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
}
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab-body { flex: 1; overflow: auto; padding: 12px 16px; min-height: 0; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 0 0 10px; }
.field > span { font-size: 13px; color: var(--muted); }
.field.check { flex-direction: row; align-items: flex-start; gap: 8px; }
.field.check > span { color: var(--text); font-size: 14px; }
.field.check input { margin-top: 3px; accent-color: var(--accent); }
.field.changed > span { color: var(--accent); font-weight: 600; }
.help { margin: -2px 0 10px; font-size: 12px; color: var(--muted); }
.field.check + .help { margin-left: 24px; }
input:not([type="checkbox"]), select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.preset { padding-bottom: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

.group { border-bottom: 1px solid var(--line); padding: 8px 0; }
.group summary { cursor: pointer; font-weight: 600; padding: 4px 0; list-style-position: inside; }
.group summary .count {
  font-weight: 500;
  font-size: 12px;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
}
.group[open] summary { margin-bottom: 8px; }
.multi { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 10px; margin-bottom: 10px; }
.multi .field.check { margin: 0; }
.multi .field.check > span { font-size: 13px; }

.other-row { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.other-row code { flex: 0 0 auto; font-size: 12px; }
.other-row input { flex: 1; }
.add-other { display: flex; gap: 6px; }

.log {
  margin: 0;
  font: 11.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
}
.log .err { color: #d1495b; }

.panel-actions { display: flex; gap: 8px; padding: 12px 16px 6px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.note { margin: 0; padding: 0 16px 12px; font-size: 12px; color: var(--muted); }

.btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary.pending { box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.ghost { background: transparent; }
.header-settings { display: flex; gap: 8px; margin-left: auto; }
.header-settings select { width: auto; padding: 5px 8px; font-size: 14px; color: var(--text); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; }
.picker { position: relative; display: inline-flex; }
.picker-face { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.notice {
  width: 100%;
  max-width: calc((100vh - 236px) * 16 / 9);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--surface);
  font-size: 13px;
}
.icon-btn { border: 0; background: none; font-size: 20px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: var(--surface-2); }

@media (max-width: 900px) {
  html, body { height: auto; }
  .layout { display: block; }
  .stage { padding: 12px 16px; overflow: visible; }
  .screen, .controls, .time, .console-line { max-width: none; }
  .screen { padding: 6px; border-radius: 10px; }
  .overlay { inset: 6px; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .tab-body { max-height: none; overflow: visible; }
  .build { display: none; }
  .notice { max-width: none; }
  .panel-actions { position: sticky; bottom: 0; background: var(--surface); }
}

/* The header on a tablet or a phone, as the website's: no links (the name
   leads to it), the menus as a short face (the language's code, the
   theme's icon) over the system's list, on the name's row. */
@media (max-width: 900px) {
  .nav { display: none; }
  .top { flex-wrap: nowrap; gap: 10px; }
  .header-settings { gap: 6px; }
  .picker-face { display: flex; align-items: center; justify-content: center; gap: 5px; min-width: 44px; height: 40px; padding: 0 10px;
                 border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); color: var(--text); font: 600 14px system-ui, sans-serif; }
  .picker-face::before { content: ""; width: 18px; height: 18px; background: currentColor;
                         -webkit-mask: var(--glyph) center / contain no-repeat; mask: var(--glyph) center / contain no-repeat; }
  .picker-lang .picker-face { --glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3Cpath d='M3 12h18M12 3a14 14 0 0 1 0 18a14 14 0 0 1 0-18'/%3E%3C/svg%3E"); }
  .picker-theme .picker-face { --glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Ccircle cx='12' cy='12' r='9' fill='none' stroke='%23000' stroke-width='2'/%3E%3Cpath d='M12 3a9 9 0 0 1 0 18z'/%3E%3C/svg%3E"); }
  :root[data-theme-choice="light"] .picker-theme .picker-face { --glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath d='M12 2v2M12 20v2M2 12h2M20 12h2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4'/%3E%3C/svg%3E"); }
  :root[data-theme-choice="dark"] .picker-theme .picker-face { --glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20 14.5A8 8 0 0 1 9.5 4a8 8 0 1 0 10.5 10.5z'/%3E%3C/svg%3E"); }
  .picker select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; font-size: 16px; cursor: pointer; }
  .picker:focus-within .picker-face { outline: 2px solid var(--accent); outline-offset: 2px; }
}
@media (max-width: 480px) {
  .brand { font-size: 18px; gap: 8px; }
  .brand img { width: 28px; height: 28px; }
  .brand .tag { display: none; }
}

/* A touch screen (a phone, a tablet). */
@media (pointer: coarse) {
  /* 16px: iOS zooms into a smaller field when it is touched. */
  input:not([type="checkbox"]), select, textarea, .header-settings select { font-size: 16px; }
  /* The pad right under the screen, the time and the tools after it. */
  .pad { order: 1; }
  .time, .console-line { order: 2; }
  .controls { order: 3; }
}

/* A phone in landscape: the screen as high as it can be, the pad on either
   side of it as on a Switch (the shoulders and − / + above and under its
   stick and buttons); the rest under it. */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 540px) {
  html, body { height: auto; }
  .top { padding: 4px 12px; flex-wrap: nowrap; }
  .brand .tag, .build, .nav { display: none; }
  .layout { display: block; }
  .stage {
    display: grid;
    grid-template-columns: 140px minmax(0, 1fr) 140px;
    grid-template-areas: "lsh screen rsh" "dpad screen face" "lmid screen rmid";
    align-items: center;
    gap: 8px 12px;
    padding: 8px max(12px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    overflow: visible;
  }
  .stage:has(> .pad[hidden]) { grid-template-columns: 0 minmax(0, 1fr) 0; column-gap: 0; }
  .screen { grid-area: screen; width: 100%; max-width: calc((100dvh - 76px) * 16 / 9); padding: 6px; border-radius: 10px; }
  .overlay { inset: 6px; }
  .stage > .notice, .stage > .controls, .stage > .time, .stage > .console-line { grid-column: 1 / -1; max-width: none; }
  .pad, .pad-row { display: contents; }
  .dpad, .face { grid-template: repeat(3, 44px) / repeat(3, 44px); }
  .dpad { grid-area: dpad; }
  .face { grid-area: face; }
  .pad [data-button="0"] { grid-area: lsh; justify-self: start; }
  .pad [data-button="1"] { grid-area: lsh; justify-self: end; }
  .pad [data-button="15"] { grid-area: rsh; justify-self: start; }
  .pad [data-button="16"] { grid-area: rsh; justify-self: end; }
  .pad [data-button="7"] { grid-area: lmid; justify-self: center; }
  .pad [data-button="9"] { grid-area: rmid; justify-self: center; }
}

/* Playing: in full screen (the Fullscreen button, simulator.js: html.game),
   or from the home screen held in landscape. Only the screen and the pad,
   as on a Switch; turned back upright (or out of full screen), the rest is
   there again. */
@media (display-mode: standalone) and (pointer: coarse) and (orientation: landscape) and (max-height: 540px) {
  .top, .panel, .stage > .notice:not(#steps-notice), .stage > .controls, .stage > .time, .stage > .console-line { display: none !important; }
  .stage { min-height: 100dvh; align-content: center; }
  .screen { max-width: calc((100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 16 / 9); }
}
html.game, html.game body { background: #000; }
html.game .top, html.game .panel, html.game .stage > .notice:not(#steps-notice),
html.game .stage > .controls, html.game .stage > .time, html.game .stage > .console-line { display: none !important; }
html.game .layout { display: block; }
html.game .stage { min-height: 100dvh; justify-content: center; align-content: center; }
html.game .screen { max-width: calc((100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) * 16 / 9); }
.fs-exit {
  position: fixed;
  top: max(8px, env(safe-area-inset-top));
  right: max(8px, env(safe-area-inset-right));
  z-index: 5;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.14);
  color: #fff;
  font-size: 18px;
}
html:not(.game) .fs-exit { display: none; }

