:root {
  --background: #111;
  --surface: #1c1c1c;
  --text: #e8e6e1;
  --muted: #a3a09a;
  --border: #3a3a3a;
  --accent: #d9c98f;
  --warning: #e0a458;
  --error: #e57373;
  --paper: #eae2b2;
  --rust: #9c5a2e;
  --blood: #a3231b;
  --rivet: #8f8270;
  --plate-top: #2e2823;
  --plate-bottom: #14110f;
  --plate-edge: #5f4331;
  --plate-dim: #85796a;
  --plate-height: 27px;
  --plate-gap: 4px;
  --plate-background:
    radial-gradient(circle, var(--rivet) 0 1px, transparent 1.5px) 1px 1px / 5px 5px no-repeat,
    radial-gradient(circle, var(--rivet) 0 1px, transparent 1.5px) calc(100% - 1px) 1px / 5px 5px no-repeat,
    radial-gradient(circle, var(--rivet) 0 1px, transparent 1.5px) 1px calc(100% - 1px) / 5px 5px no-repeat,
    radial-gradient(circle, var(--rivet) 0 1px, transparent 1.5px) calc(100% - 1px) calc(100% - 1px) / 5px 5px no-repeat,
    linear-gradient(to bottom, var(--plate-top), var(--plate-bottom));
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  gap: 12px;
  background: radial-gradient(ellipse 90% 60% at 50% 0%, rgba(150, 150, 140, 0.16), transparent 70%), var(--background);
  color: var(--text);
  font:
    16px / 1.5 system-ui,
    sans-serif;
}
button {
  min-height: 44px;
  padding: 8px 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
button:hover {
  border-color: var(--accent);
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button:disabled:hover {
  border-color: var(--border);
}
/* The start page: a title over the dark, and a notepad page like the games' own menus,
   drawn in CSS because the games' art only arrives with a JAR. */
#title {
  width: min(440px, 100%);
  text-align: center;
}
h1 {
  margin: 0;
  color: #f2f0eb;
  font:
    400 clamp(2.25rem, 11vw, 3.25rem) / 1 "Times New Roman",
    Times,
    serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  text-shadow:
    0 0 1px #fff,
    0 0 18px rgba(255, 255, 255, 0.28),
    0 2px 0 #000;
}
h1 span {
  display: block;
  margin-top: 6px;
  /* Brighter than the blood red elsewhere, to read at 4.5:1 on the dark. */
  color: #ec7468;
  font-size: 0.36em;
  letter-spacing: 0.6em;
  /* The letter spacing also follows the last letter, so this keeps the word centered. */
  margin-right: -0.6em;
  text-shadow: 0 0 10px rgba(163, 35, 27, 0.8);
}
#drop {
  --ink: #241d13;
  /* At least 4.5:1 against the paper, even where its edges darken. */
  --ink-muted: #54462d;
  --rings: 28px;
  position: relative;
  width: min(440px, calc(100% - 12px));
  margin: 16px 0 16px 12px;
  padding: 22px 22px 18px calc(var(--rings) + 6px);
  color: var(--ink);
  text-align: left;
  background: radial-gradient(ellipse at 50% 40%, transparent 55%, rgba(120, 88, 38, 0.22)), var(--paper);
  border: 1px solid #5e4d31;
  border-radius: 3px 6px 6px 3px;
  box-shadow:
    inset 0 0 0 2px rgba(255, 250, 225, 0.5),
    inset 0 0 0 4px rgba(140, 110, 62, 0.35),
    0 10px 36px rgba(0, 0, 0, 0.85);
  transition: box-shadow 120ms;
}
/* The spiral: a punched hole for each ring, and a wire loop around the paper's edge. */
#drop::before {
  content: "";
  position: absolute;
  top: 14px;
  bottom: 14px;
  left: -12px;
  width: calc(var(--rings) + 8px);
  background:
    radial-gradient(circle at 27px 50%, #1b150d 0 3.5px, rgba(60, 45, 25, 0.45) 4px, transparent 5px) 0 0 / 100% 24px
    repeat-y,
    radial-gradient(16px 6.5px at 15px 50%, transparent 58%, #8a8a86 63%, #2a2a2a 78%, #0d0d0d 86%, transparent 93%) 0 0
    / 100% 24px repeat-y;
  pointer-events: none;
}
#drop.dragging {
  box-shadow:
    inset 0 0 0 2px rgba(255, 250, 225, 0.5),
    inset 0 0 0 4px var(--blood),
    0 0 28px rgba(163, 35, 27, 0.55),
    0 10px 36px rgba(0, 0, 0, 0.85);
}
#drop h2 {
  margin: 0 0 6px;
  color: var(--ink-muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
}
#drop p {
  margin: 8px 0 0;
  color: var(--ink-muted);
  font-size: 0.875rem;
}
/* Like the games' own delimiter between a menu's parts. */
#drop hr {
  height: 2px;
  margin: 18px 0;
  background: linear-gradient(to right, transparent, #8c7650 12%, #8c7650 88%, transparent);
  border: 0;
  box-shadow: 0 1px rgba(255, 250, 225, 0.6);
}
/* Menu rows, picked out with the grey bar the games use for the chosen row. */
#archive-sources button,
#choose {
  display: flex;
  align-items: center;
  gap: 0.5em;
  width: calc(100% + 20px);
  margin: 0 -10px;
  min-height: 40px;
  padding: 8px 10px;
  color: var(--ink);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 0;
  font-size: 1.0625rem;
  font-weight: 400;
  cursor: pointer;
}
#archive-sources button:hover:not(:disabled),
#archive-sources button:focus-visible,
#choose:hover,
#choose:focus-within {
  color: #fff;
  background: #66625b;
  outline: none;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.35);
}
#archive-sources button:disabled {
  color: var(--ink-muted);
}
/* The row a game is downloading or loading from keeps its ink, with a spinner after its
   title. For your own JAR, it takes the place of the ellipsis. */
#archive-sources button[aria-busy="true"] {
  color: var(--ink);
}
#archive-sources button[aria-busy="true"]::after,
#choose[aria-busy="true"]::after {
  content: "";
  flex: none;
  margin-left: 0;
  box-sizing: border-box;
  width: 0.875em;
  height: 0.875em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(1turn);
  }
}
@media (prefers-reduced-motion: reduce) {
  #archive-sources button[aria-busy="true"]::after,
  #choose[aria-busy="true"]::after {
    animation-duration: 2.4s;
  }
}
/* Flex drops the space before it, so the gap stands in for one. */
#choose::after {
  content: "…";
  margin-left: -0.25em;
}
#file {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
#archive-sources {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}
#credits {
  width: min(440px, 100%);
  color: #96928b;
  font-size: 0.75rem;
  text-align: center;
}
#credits p {
  margin: 0;
}
#credits a {
  color: inherit;
}
#credits a:hover {
  color: #ddd8cf;
}
#message {
  width: min(440px, 100%);
  margin: 0;
  text-align: left;
}
/* During play, a message floats over the page instead of pushing the game down. */
body.playing #message {
  position: fixed;
  top: 8px;
  left: 50%;
  z-index: 1;
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 4px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  transform: translateX(-50%);
}
#message:empty {
  display: none;
}
#message.warning {
  color: var(--warning);
}
#message.error {
  color: var(--error);
}
#message.screen-reader-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
#game {
  display: none;
  width: min(calc(100vw - 32px), calc((100vh - 32px - var(--panel-height, 0px)) / var(--page-ratio, 1.27)));
  aspect-ratio: var(--game-aspect, 1);
  background: #000;
  cursor: none;
  touch-action: none;
}
/* The page puts the game's own rusted steel art behind this, once a JAR is loaded.
   Everything in it keeps its place, so that nothing moves as buttons come and go. */
#panel {
  display: none;
  align-items: center;
  width: min(calc(100vw - 32px), calc((100vh - 32px - var(--panel-height, 0px)) / var(--page-ratio, 1.27)));
  aspect-ratio: 240 / 64;
  container: panel / inline-size;
  margin-top: -12px;
  padding: 14px 10px 8px;
  background-color: #000;
  background-size: 100% 100%;
  image-rendering: pixelated;
}
body.playing #panel {
  display: flex;
}
/* Mobile 2 has no art in the shape of the first game's panel, only long thin strips,
   so its panel is as tall as its controls, with a strip repeated behind them. */
body.strip-panel #panel {
  aspect-ratio: auto;
  min-height: var(--panel-height);
  padding: 8px 10px;
  background-size: 100% auto;
  background-repeat: repeat-y;
}
#actions {
  display: none;
  flex: 1;
  min-width: 0;
  grid-template-columns: max(17%, 84px) minmax(0, 1fr) max(17%, 84px);
  gap: var(--plate-gap);
}
#controls {
  display: grid;
  grid-auto-rows: var(--plate-height);
  gap: var(--plate-gap);
  min-width: 0;
}
.plate-row {
  display: flex;
  gap: var(--plate-gap);
  min-width: 0;
}
.plate-row > * {
  flex: 1 1 0;
  min-width: 0;
}
/* These labels never change, so they can take the space they need. */
#item-keys {
  container: item-keys / inline-size;
}
#item-keys > * {
  flex-basis: auto;
}
/* As large as the largest icon, whose art stays at its own size, so nothing moves when one changes. */
.item-icon {
  width: 26px;
  height: 24px;
  margin-right: 2px;
  object-fit: none;
  image-rendering: pixelated;
  vertical-align: middle;
}
/* With no room for icon, word and key together, the word stays only for screen readers. */
@container item-keys (max-width: 340px) {
  body.item-icons .item-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
  }
}
/* Wide enough for "Sound: off" in any font, so that the row doesn't move when it changes. */
#panel #sound {
  flex: 0 0 calc(8.5ch + 14px);
}
/* Every part of this row has a width of its own rather than one from its contents, which
   some browsers didn't update when the remove button came and went. The volume stays the
   same width, and the soundfont menu takes what's left. */
#soundfont-control {
  flex: 1 1 250px;
  /* Room for its name and "Symbiote BSD". */
  min-width: 224px;
  display: flex;
  gap: 2px;
}
/* The menu's name is written on its plate, as the volume's is, and lets clicks through
   to the menu, so that the whole plate opens it. */
#soundfont-menu {
  position: relative;
  display: flex;
  flex: 1 1 0;
  min-width: 0;
}
#soundfont-menu span {
  position: absolute;
  top: 50%;
  left: 7px;
  color: var(--paper);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  text-shadow: 0 1px 1px #000;
  transform: translateY(-50%);
  pointer-events: none;
}
#soundfont-menu:has(select:disabled) span {
  color: var(--plate-dim);
  text-shadow: none;
}
#panel #soundfont {
  flex: 1 1 0;
  min-width: 0;
  /* Past the menu's name, measured in the same font. */
  padding-left: calc(7px + 5.8em);
  padding-right: 16px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  appearance: none;
  /* The arrow that appearance: none takes away. */
  background:
    linear-gradient(225deg, var(--paper) 50%, transparent 50%) calc(100% - 10px) 55% / 4px 4px no-repeat,
    linear-gradient(135deg, var(--paper) 50%, transparent 50%) calc(100% - 6px) 55% / 4px 4px no-repeat,
    var(--plate-background);
}
#soundfont option {
  color: var(--paper);
  background: var(--plate-bottom);
  text-shadow: none;
}
#panel #soundfont-open,
#panel #soundfont-remove {
  flex: 0 0 max(34px, var(--plate-height));
  padding: 0;
}
#soft-left[hidden],
#soft-right[hidden] {
  display: block;
  visibility: hidden;
}
#panel #soft-left,
#panel #soft-right {
  padding: 0 3px;
  /* In proportion to the button. fit-text.mjs shrinks a word too long for it. */
  font-size: clamp(0.875rem, 3.1cqi, 1.25rem);
}
/* Bolted steel plates, one rivet in each corner, with text in the notepad's color. */
#panel button,
#panel select,
#volume-control {
  min-height: 0;
  padding: 0 6px;
  color: var(--paper);
  background: var(--plate-background);
  border: 1px solid var(--plate-edge);
  border-radius: 1px;
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.1),
    inset 0 -1px rgba(0, 0, 0, 0.6),
    0 1px 3px #000;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
  text-shadow: 0 1px 1px #000;
  image-rendering: auto;
}
#panel button {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
#panel kbd {
  margin-left: 3px;
  padding: 1px 4px;
  color: var(--paper);
  background: #000;
  border: 1px solid var(--plate-edge);
  border-radius: 2px;
  font:
    600 0.6875rem ui-monospace,
    monospace;
}
#panel select:hover:not(:disabled),
#panel button:hover:not(:disabled) {
  color: #fff;
  border-color: var(--blood);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.1),
    inset 0 0 8px rgba(163, 35, 27, 0.55),
    0 1px 3px #000;
}
#panel button:active:not(:disabled) {
  background-color: #000;
  box-shadow: inset 0 2px 4px #000;
  transform: translateY(1px);
}
#panel select:focus-visible,
#panel button:focus-visible,
#volume:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 1px;
}
#panel select:disabled,
#panel button:disabled {
  color: var(--plate-dim);
  opacity: 1;
  text-shadow: none;
}
#volume-control {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 1 160px;
}
#volume {
  flex: 1;
  min-width: 0;
  height: 100%;
  margin: 0;
  background: transparent;
  cursor: pointer;
  appearance: none;
}
#volume::-webkit-slider-runnable-track {
  height: 4px;
  background: #000;
  border: 1px solid var(--plate-edge);
  border-radius: 1px;
}
#volume::-moz-range-track {
  height: 2px;
  background: #000;
  border: 1px solid var(--plate-edge);
  border-radius: 1px;
}
#volume::-webkit-slider-thumb {
  width: 8px;
  height: 14px;
  margin-top: -6px;
  background: linear-gradient(var(--paper), var(--rust));
  border: 1px solid #000;
  border-radius: 1px;
  appearance: none;
}
#volume::-moz-range-thumb {
  width: 6px;
  height: 12px;
  background: linear-gradient(var(--paper), var(--rust));
  border: 1px solid #000;
  border-radius: 1px;
}
@media (pointer: coarse) {
  :root {
    --plate-height: 36px;
  }
}
/* Too narrow for tall soft keys at the sides, so they get a row of their own. */
@container panel (max-width: 420px) {
  #actions {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: var(--plate-height) auto;
  }
  #soft-left {
    grid-area: 1 / 1;
  }
  #soft-right {
    grid-area: 1 / 2;
  }
  #controls {
    grid-area: 2 / 1 / 3 / -1;
  }
}
/* Too narrow for the volume and the soundfont menu side by side, so the menu and its buttons
   get a row of their own, leaving room to slide the volume. */
@container panel (max-width: 680px) {
  .plate-row:has(#soundfont-control) {
    flex-wrap: wrap;
    grid-row: span 2;
  }
  #soundfont-control {
    flex: 1 0 100%;
  }
  #volume-control {
    flex: 1 1 0;
  }
  #panel #soundfont {
    flex: 1 1 0;
  }
}
body.playing #title,
body.playing #drop,
body.playing #credits {
  display: none;
}
body.playing #game {
  display: block;
}
body.playing #actions {
  display: grid;
}
body.in-menu .in-game {
  visibility: hidden;
}
