:root {
  --bg: #11101d;
  --surface: #1b192d;
  --surface-2: #232039;
  --line: #3a3451;
  --text: #f4f1ff;
  --muted: #bab2d4;
  --button: #26213b;
  --button-hover: #332951;
  --focus: #c2aaff;
  --green: #87e8c7;
  --amber: #c2aaff;
  --cabinet-dark: #1a162b;
}

body { background: radial-gradient(ellipse at 35% 0%, #211a36, #11101d 60%); }
.topbar {
  background: #151223;
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
}
.brand h1 { letter-spacing: -.035em; }
.brand .mark {
  flex: 0 0 auto;
  background: url("/icon-180.png") center / contain no-repeat;
  border: 1px solid #4a3b73;
}
.gregle-options { width: min(100%, 880px); justify-self: center; }
.gregle-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.gregle-tools button { min-height: 42px; }
.gregle-tools [hidden] { display: none; }
#offlineStatus, #gregleSupport { color: var(--muted); margin: 8px 0; font-size: .875rem; }
#gregleSupport:empty { display: none; }
.gregle-help { margin-top: 12px; color: var(--muted); font-size: .875rem; line-height: 1.5; }
.gregle-help p { margin: 5px 0; }
.gregle-help a { color: #d9caff; }
.drop-badge { background: #241a3c; color: #fff; border-color: #735eac; }
.crt-footer .transport { background: #19162b; }
.crt-footer .transport .file-button:first-child { background: #6047a6; color: #fff; }
.crt-footer .transport .file-button:first-child:hover { background: #7459c4; }
.crt-footer .transport .btn-text { display: inline; }
.touch-controls { display: none; width: min(100%, 880px); justify-self: center; user-select: none; }
.touch-controls button { touch-action: none; min-width: 0; min-height: 40px; padding: 3px; }
.touch-shoulders { grid-area: shoulders; display: flex; justify-content: space-between; gap: 8px; }
.touch-shoulders button { flex: 1; }
.touch-stick, .touch-c-stick, .touch-dpad, .touch-face {
  display: grid;
  grid-template: repeat(3, minmax(36px, 48px)) / repeat(3, minmax(34px, 46px));
  gap: 4px;
  justify-content: center;
  grid-auto-flow: row;
}
.touch-stick { grid-area: stick; }
.touch-c-stick { grid-area: cstick; }
.touch-dpad { grid-area: dpad; }
.touch-face { grid-area: face; }
.touch-controls .up { grid-area: 1 / 2; }
.touch-controls .left { grid-area: 2 / 1; }
.touch-controls .right { grid-area: 2 / 3; }
.touch-controls .down { grid-area: 3 / 2; }
.touch-controls .touch-label { grid-area: 2 / 2; align-self: center; text-align: center; color: var(--muted); font-size: .72rem; }
.touch-face button { width: auto; height: auto; }
.touch-face [data-touch-button="A"] { background: #345b55; color: #dcfff2; }
.touch-face [data-touch-button="B"] { background: #58334e; color: #ffe4f2; }
.touch-c-stick button { background: #493751; }

@media (pointer: coarse), (max-width: 760px) {
  .touch-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-areas: "shoulders shoulders" "stick face" "dpad cstick";
    gap: 10px;
    max-width: 490px;
  }
  .touch-controls .touch-face { gap: 4px; }
}
@media (max-width: 530px) {
  .topbar { flex-wrap: wrap; align-items: center; gap: 10px; }
  .topbar-actions { gap: 5px; }
  .topbar-actions .icon-button { min-width: 36px; padding-inline: 5px; }
  .crt-footer .transport .btn-text { display: inline; }
  .crt-footer .transport { padding: 7px; gap: 5px; }
}

.topbar { border-bottom-color: #393050; min-height: 76px; }
.brand h1 { font-size: clamp(1.15rem, 2vw, 1.57rem); font-weight: 750; }
.brand .mark { width: 46px; height: 46px; border-radius: 11px; box-shadow: 0 3px 16px #060410a0; }
.brand p { font-size: .81rem; }
.crt-set { border-color: #4a3a6b; background: linear-gradient(154deg, #372853 0%, #211831 58%, #191326 100%); }
.crt-bezel { background: #120e20; border-color: #53436b; }
.crt-footer .transport button, .crt-footer .transport .file-button:not(:first-child) {
  background: linear-gradient(#3a2e50, #2a213c); border-color: #554467; box-shadow: 0 2px #120d1e;
}
.crt-footer .transport button:hover, .crt-footer .transport .file-button:not(:first-child):hover {
  background: #51416b;
}
.control-panel { background: #171324; }
.gregle-options { padding: 14px 0 12px; }
#gregleInstall { background: #6047a6; border-color: #8a71ce; color: white; }
.source-page { max-width: 48rem; padding: 0 1.25rem; margin: 3rem auto; color: var(--text); font: 1rem/1.65 system-ui, sans-serif; }
.source-page a { color: #d9caff; }
.source-page li { margin-bottom: .4rem; }
#controllerSettingsButton { width: 100%; min-height: 40px; margin: 8px 0; }
.controller-settings {
  width: min(36rem, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  padding: 16px;
  overflow: auto;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.controller-settings::backdrop { background: #0a0814c2; }
.controller-settings-header, .controller-settings-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.controller-settings-header { justify-content: space-between; }
.controller-settings-header h2 { margin: 0; font-size: 1.15rem; }
.controller-settings button { min-height: 40px; }
.controller-settings button[data-listening] { border-color: var(--focus); color: var(--focus); }
.controller-settings [hidden] { display: none; }
.controller-settings p { font-size: .875rem; overflow-wrap: anywhere; }
.controller-settings-actions { margin-top: 12px; }
.controller-settings-actions p { margin: 0; color: var(--green); }
.controller-bindings {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr));
  gap: 10px;
}
.controller-bindings fieldset {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.controller-bindings legend { padding: 0 4px; color: var(--muted); font-size: .875rem; }
.controller-bindings fieldset div {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr);
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: .8rem;
}
.controller-bindings button { padding-inline: 4px; font-size: inherit; }
@media (max-width: 530px) {
  .brand .mark { width: 39px; height: 39px; }
  .gregle-options { padding-inline: 3px; }
}

.play-toolbar { display: none; }
html.playing-fullscreen, html.playing-fullscreen body { overflow: hidden; overscroll-behavior: none; }
.crt-set.play-mode {
  position: fixed; inset: 0; z-index: 1000; display: grid; place-items: center;
  width: 100%; max-width: none; min-width: 0; height: 100vh; height: 100dvh;
  padding: 0; margin: 0; border: 0; border-radius: 0; background: #000; touch-action: none;
}
.play-mode .crt-bezel { display: grid; place-items: center; width: 100%; height: 100%; padding: 0; border: 0; background: #000; }
.play-mode .screen-viewport {
  width: min(100vw, calc(100dvh * var(--aspect-w, 4) / var(--aspect-h, 3)));
  height: auto; border: 0; border-radius: 0;
}
.play-mode .lcd-strip, .play-mode .crt-footer, .play-mode .touch-controls { display: none; }
.play-mode .play-toolbar {
  display: flex; position: absolute; z-index: 4; gap: 6px;
  top: max(6px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right));
}
.play-toolbar button { min-height: 36px; border-radius: 12px; background: #191624b8; color: white; }
.play-toolbar button[aria-pressed=true] { border-color: #b7a4e4; }
.play-mode.show-play-controls .touch-controls {
  --key-size: clamp(28px, min(9vw, 10dvh), 48px);
  display: flex; position: absolute; inset: 0; z-index: 3; max-width: none; width: 100%;
  pointer-events: none; touch-action: none;
}
.play-mode .touch-controls button {
  pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none;
  color: #fff; min-width: 0; min-height: 0; border: 1px solid #ddd4f398; border-radius: 35%;
  background: #30274099; text-shadow: 0 1px 2px #000; box-shadow: none; font-size: .92rem;
}
.play-mode .touch-controls button:active { background: #735aaacc; }
.play-mode .touch-label { color: #eee; font-size: .63rem; text-shadow: 0 1px 2px #000; }
.play-mode .touch-stick, .play-mode .touch-face, .play-mode .touch-dpad, .play-mode .touch-c-stick {
  position: absolute; grid-template: repeat(3, var(--key-size)) / repeat(3, var(--key-size)); gap: 2px;
}
.play-mode .touch-stick, .play-mode .touch-dpad { left: max(10px, env(safe-area-inset-left)); }
.play-mode .touch-face, .play-mode .touch-c-stick { right: max(10px, env(safe-area-inset-right)); }
.play-mode .touch-dpad, .play-mode .touch-c-stick { bottom: max(8px, env(safe-area-inset-bottom)); }
.play-mode .touch-stick, .play-mode .touch-face { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 3 * var(--key-size) + 12px); }
.play-mode .touch-shoulders {
  position: absolute; left: max(10px, env(safe-area-inset-left)); right: max(10px, env(safe-area-inset-right));
  top: calc(max(6px, env(safe-area-inset-top)) + 42px); gap: 7px;
}
.play-mode .touch-shoulders button { flex: 0 0 auto; min-width: 44px; height: 36px; border-radius: 12px; }
.play-mode .touch-shoulders button:nth-child(3) { margin-left: auto; }
.play-mode .touch-face [data-touch-button=A] { background: #276554ad; }
.play-mode .touch-face [data-touch-button=B] { background: #6b304fad; }
