:root {
  color-scheme: light;
  --face: #c0c0c0;
  --light: #ffffff;
  --mid: #dfdfdf;
  --shadow: #808080;
  --deep: #404040;
  --ink: #111111;
  --blue: #000080;
  --selected: #000080;
  --mono: 'Courier New', monospace;
  --sans: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: #fff; color: var(--ink); font-family: var(--sans); }
button, select { font: inherit; }

#film-canvas {
  position: fixed;
  z-index: 0;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: #fff;
  cursor: crosshair;
  touch-action: none;
}

.paint-window {
  position: fixed;
  z-index: 2;
  top: 10px;
  left: 10px;
  width: 278px;
  max-height: calc(100vh - 20px);
  overflow: auto;
  padding: 2px;
  border: 2px solid;
  border-color: var(--light) var(--deep) var(--deep) var(--light);
  background: var(--face);
  box-shadow: 2px 3px 0 rgba(0,0,0,.18);
  font-family: var(--sans);
  font-size: 12px;
}

.titlebar {
  height: 25px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 3px 2px 5px;
  background: linear-gradient(90deg, #000080, #1084d0);
  color: #fff;
}
.window-icon { position: relative; width: 15px; height: 15px; display: block; border: 1px solid #fff; background: #c0c0c0; }
.window-icon::before, .window-icon::after { position: absolute; content: ''; background: #000080; }
.window-icon::before { left: 2px; right: 2px; top: 3px; height: 2px; }
.window-icon::after { left: 3px; right: 3px; top: 7px; height: 5px; }
.titlebar h1 { overflow: hidden; flex: 1; margin: 0; font-size: 12px; font-weight: 700; white-space: nowrap; }
.play-button, .play-button:active {
  min-width: 46px;
  height: 19px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 1px 5px;
  border: 1px solid;
  border-color: var(--light) var(--shadow) var(--shadow) var(--light);
  border-radius: 0;
  background: var(--face);
  color: var(--ink);
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
}
.about-button {
  min-width: 34px;
  height: 19px;
  padding: 1px 4px;
  border: 1px solid;
  border-color: var(--light) var(--shadow) var(--shadow) var(--light);
  border-radius: 0;
  background: var(--face);
  color: var(--ink);
  cursor: pointer;
  font-size: 10px;
  line-height: 1;
}
.play-button:active, .play-button.paused { border-color: var(--shadow) var(--light) var(--light) var(--shadow); padding: 2px 4px 0 6px; }
.play-icon { width: 8px; font-size: 9px; }
.palette-body { display: grid; grid-template-columns: 110px 1fr; gap: 6px; padding: 7px 4px 5px; }
.toolbox { min-width: 0; display: flex; flex-direction: column; gap: 7px; }
.brush-group, .paint-mode-group, .clear-group { min-width: 0; }
.brush-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 3px; padding: 2px 0 3px; }
.shape-button, .mode-button, .utility-button {
  width: 27px;
  height: 27px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border: 1px solid;
  border-color: var(--light) var(--shadow) var(--shadow) var(--light);
  border-radius: 0;
  background: var(--face);
  color: var(--ink);
  cursor: pointer;
}
.shape-button.selected, .mode-button.selected { border-color: var(--shadow) var(--light) var(--light) var(--shadow); background: #d0d0d0; }
.shape-button.selected { outline: 2px solid var(--blue); outline-offset: 1px; }
.brush-grid .shape-button { width: 100%; height: 25px; }
.paint-mode-options { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.mode-button { width: auto; height: 24px; padding: 2px 3px; font-size: 10px; text-transform: lowercase; }
.mode-button.selected { background: #a9c5e8; outline: 1px solid var(--blue); }
.clear-group { border-top: 1px solid var(--shadow); padding-top: 5px; }
.clear-action { width: 100%; height: 25px; gap: 4px; justify-content: flex-start; padding: 2px 5px; border-color: #a05050 #653333 #653333 #a05050; background: #f1dddd; color: #602020; font-size: 10px; }
.shape-symbol { display: block; background: #111; }
.circle-symbol { width: 16px; height: 16px; border-radius: 50%; }
.bar-symbol { width: 18px; height: 8px; }
.spray-symbol { width: 19px; height: 19px; background: radial-gradient(circle, #111 1px, transparent 1.7px) 0 0 / 6px 6px, radial-gradient(circle, #111 1px, transparent 1.7px) 3px 3px / 6px 6px; }
.cloud-symbol { position: relative; width: 19px; height: 12px; border-radius: 9px; background: #333; filter: blur(1.5px); }
.cloud-symbol::before, .cloud-symbol::after { position: absolute; content: ''; border-radius: 50%; background: #333; }
.cloud-symbol::before { width: 11px; height: 11px; left: 2px; top: -4px; }
.cloud-symbol::after { width: 10px; height: 10px; right: 1px; top: -3px; }
.line-symbol { width: 20px; height: 18px; background: transparent; }
.line-symbol svg { display: block; width: 100%; height: 100%; overflow: visible; }
.line-symbol path { fill: none; stroke: #111; stroke-width: 2; stroke-linecap: square; stroke-linejoin: miter; }
.eraser-symbol { width: 16px; height: 10px; transform: rotate(-43deg); border: 1px solid #555; border-radius: 1px; background: linear-gradient(90deg, #f6a6c7 0 45%, #fff 45% 100%); }
.clear-symbol { font-size: 22px; font-weight: 400; line-height: 14px; }
.group-caption { display: flex; align-items: center; justify-content: space-between; margin: 0 0 5px; color: #222; font-size: 10px; }
.palette-options { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.palette-group { padding: 5px; border: 1px solid; border-color: var(--shadow) var(--light) var(--light) var(--shadow); background: var(--face); }
.envelope-group { }
.projector-toggle { min-width: 38px; height: 19px; padding: 1px 5px; border: 1px solid; border-color: var(--light) var(--shadow) var(--shadow) var(--light); border-radius: 0; background: var(--face); color: var(--ink); cursor: pointer; font-size: 10px; }
.projector-toggle[aria-pressed="false"] { border-color: var(--shadow) var(--light) var(--light) var(--shadow); background: #d0d0d0; }
.asset-credit { margin: 4px 0 0; color: #444; font-size: 9px; line-height: 1.25; }
.asset-credit a { color: #000080; }
.range-row { display: grid; grid-template-columns: 33px 1fr; align-items: center; gap: 4px; height: 17px; color: #222; font-size: 10px; }
.range-row input, #loop-length { width: 100%; height: 14px; margin: 0; accent-color: var(--blue); cursor: pointer; }
.colour-group { margin-top: 0; }
.toolbox .colour-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3px; }
.colour-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; }
.colour-button { width: 100%; aspect-ratio: 1; min-width: 14px; padding: 1px; border: 1px solid; border-color: var(--shadow) var(--light) var(--light) var(--shadow); border-radius: 0; background: var(--face); cursor: pointer; }
.colour-button i { display: block; width: 100%; height: 100%; background: var(--swatch); }
.colour-button.selected { outline: 1px dotted #111; outline-offset: -3px; border-color: #111; }
.colour-button[data-colour="0"] { --swatch: #000000; }
.colour-button[data-colour="1"] { --swatch: #808080; }
.colour-button[data-colour="2"] { --swatch: #c0c0c0; }
.colour-button[data-colour="3"] { --swatch: #ffffff; }
.colour-button[data-colour="4"] { --swatch: #800000; }
.colour-button[data-colour="5"] { --swatch: #ff0000; }
.colour-button[data-colour="6"] { --swatch: #808000; }
.colour-button[data-colour="7"] { --swatch: #ffff00; }
.colour-button[data-colour="8"] { --swatch: #008000; }
.colour-button[data-colour="9"] { --swatch: #00ff00; }
.colour-button[data-colour="10"] { --swatch: #008080; }
.colour-button[data-colour="11"] { --swatch: #00ffff; }
.colour-button[data-colour="12"] { --swatch: #000080; }
.colour-button[data-colour="13"] { --swatch: #0000ff; }
.colour-button[data-colour="14"] { --swatch: #800080; }
.colour-button[data-colour="15"] { --swatch: #ff00ff; }
.note-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; }
.note-button { height: 21px; padding: 0; border: 1px solid; border-color: var(--light) var(--shadow) var(--shadow) var(--light); border-radius: 0; background: var(--face); color: #111; cursor: pointer; font: 11px var(--sans); }
.note-button:hover { background: #ddd; }
.note-button.selected { border-color: var(--shadow) var(--light) var(--light) var(--shadow); background: #a9c5e8; }
.octave-control { display: inline-flex; align-items: center; gap: 3px; }
.octave-control button { width: 18px; height: 17px; padding: 0; border: 1px solid; border-color: var(--light) var(--shadow) var(--shadow) var(--light); border-radius: 0; background: var(--face); color: #111; cursor: pointer; line-height: 14px; }
.octave-control output { min-width: 12px; text-align: center; font-size: 10px; }
.loop-group .group-caption output { font-size: 10px; }
#loop-length { display: block; margin: 3px 0 0; }
.gear-group { margin-top: auto; }
.save-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.save-actions button { min-width: 0; height: 22px; padding: 2px 3px; border: 1px solid; border-color: var(--light) var(--shadow) var(--shadow) var(--light); border-radius: 0; background: var(--face); color: var(--ink); cursor: pointer; font-size: 10px; }
.save-actions button:active { border-color: var(--shadow) var(--light) var(--light) var(--shadow); }
.save-group { margin-top: 4px; }
.ratio-gears { display: flex; align-items: center; justify-content: space-between; gap: 2px; }
.gear-control { position: relative; width: 32px; height: 42px; display: flex; align-items: center; justify-content: center; border: 1px solid transparent; }
.gear-control.active { border-color: #7b91ad; background: #e5edf6; }
.gear-button { width: 30px; height: 38px; display: flex; align-items: center; justify-content: center; padding: 0; border: 0; background: transparent; cursor: pointer; }
.gear-button svg { display: block; max-width: 30px; max-height: 30px; filter: drop-shadow(1px 1px 0 rgba(0,0,0,.25)); }
.ratio-popover { position: absolute; z-index: 5; bottom: calc(100% + 5px); left: 50%; width: 58px; display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 6px 4px; border: 2px solid; border-color: var(--light) var(--deep) var(--deep) var(--light); background: var(--face); box-shadow: 2px 2px 3px rgba(0,0,0,.2); transform: translateX(-50%); }
.ratio-popover[hidden] { display: none; }
.ratio-popover output { font: 10px var(--mono); }
.ratio-popover input { width: 18px; height: 94px; margin: 0; accent-color: var(--blue); cursor: pointer; writing-mode: vertical-lr; direction: rtl; }

.about-dialog {
  width: min(330px, calc(100vw - 24px));
  padding: 2px;
  border: 2px solid;
  border-color: var(--light) var(--deep) var(--deep) var(--light);
  background: var(--face);
  color: var(--ink);
  box-shadow: 3px 4px 0 rgba(0,0,0,.25);
  font: 12px var(--sans);
}
.about-dialog::backdrop { background: rgba(20, 20, 30, .2); }
.about-titlebar { height: 23px; display: flex; align-items: center; justify-content: space-between; padding: 2px 3px 2px 6px; background: linear-gradient(90deg, #000080, #1084d0); color: white; font-size: 11px; font-weight: 700; text-transform: lowercase; }
.about-titlebar button { width: 18px; height: 17px; padding: 0; border: 1px solid; border-color: var(--light) var(--shadow) var(--shadow) var(--light); border-radius: 0; background: var(--face); color: var(--ink); cursor: pointer; line-height: 13px; }
.about-content { display: flex; align-items: center; gap: 12px; padding: 17px 13px 13px; }
.about-icon { width: 42px; height: 42px; display: grid; place-items: center; border: 1px solid; border-color: var(--shadow) var(--light) var(--light) var(--shadow); background: white; color: #000080; font: bold 15px Georgia, serif; }
.about-content h2 { margin: 0 0 5px; font: bold 15px Georgia, serif; }
.about-content p { margin: 0; color: #444; font-size: 10px; }
.about-provider { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 13px; border-top: 1px solid var(--shadow); font-size: 10px; }
.about-provider strong { font-size: 11px; }
.about-actions { display: flex; justify-content: flex-end; padding: 7px 8px 5px; }
.about-actions button { min-width: 58px; height: 22px; border: 1px solid; border-color: var(--light) var(--shadow) var(--shadow) var(--light); border-radius: 0; background: var(--face); cursor: pointer; font-size: 11px; }

@media (max-width: 700px) {
  .paint-window { top: auto; bottom: 8px; left: 8px; width: min(390px, calc(100vw - 16px)); max-height: 48vh; }
  .palette-body { grid-template-columns: 100px 1fr; gap: 4px; padding: 5px 3px 3px; }
  .brush-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; padding-bottom: 3px; }
  .shape-button, .mode-button, .utility-button { width: 25px; height: 25px; }
  .brush-grid .shape-button { width: 100%; height: 23px; }
  .palette-group { padding: 4px; }
  .colour-group { margin-top: 0; }
  .note-button { height: 19px; }
  .range-row { height: 15px; }
}
