: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; }
@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; }

.touch-controls {
  --unit: clamp(100px, min(33vw, 34dvh), 154px);
  --edge: max(9px, env(safe-area-inset-left));
  --right-edge: max(9px, env(safe-area-inset-right));
  position: relative; display: none; width: min(100%, 680px); justify-self: center;
  height: calc(48px + 1.64 * var(--unit)); user-select: none; -webkit-user-select: none;
  pointer-events: none;
}
@media (any-pointer: coarse), (max-width: 760px) { .touch-controls { display: block; } }
.play-mode.show-play-controls .touch-controls {
  display: block; position: absolute; z-index: 3; bottom: max(8px, env(safe-area-inset-bottom));
  width: 100%; max-width: none; left: 0;
}
.touch-controls button, .gc-stick {
  pointer-events: auto; touch-action: none; -webkit-tap-highlight-color: transparent;
}
.touch-controls button {
  --top: #c7c5ccd4; --bottom: #72717eb8;
  min-width: 0; min-height: 0; padding: 0; border: 1px solid #f4f1ff73;
  color: #fff; text-shadow: 0 1px 2px #24212f; font-weight: 750;
  background: linear-gradient(150deg,var(--top),var(--bottom));
  box-shadow: inset 0 1px 1px #ffffff75, inset 0 -3px 3px #15132256, 0 2px 3px #12101c60;
}
.play-mode .touch-controls { opacity: .75; }
.touch-controls button.held, .gc-stick.held .gc-cap { filter: brightness(1.3); }
.gc-stick {
  position: absolute; display: grid; place-items: center; border-radius: 50%; width: var(--unit);
  aspect-ratio: 1; background: radial-gradient(circle,#211e2c6b 42%,#4641529c 69%,#c8c2d585 70%,#4640519c 74%);
}
.gc-stick::before {
  content: ""; position: absolute; inset: 8%; clip-path: polygon(29% 0,71% 0,100% 29%,100% 71%,71% 100%,29% 100%,0 71%,0 29%);
  background: linear-gradient(145deg,#15121d99,#6b657983);
}
.gc-cap {
  position: absolute; left: 50%; top: 50%; width: 54%; aspect-ratio: 1; border-radius: 50%;
  transform: translate(-50%,-50%); display: grid; place-items: center; pointer-events: none;
  background: repeating-radial-gradient(circle at 49% 45%,transparent 0 4px,#65616e80 5px,transparent 6px),
    linear-gradient(145deg,#e1dfe4,#928f9c);
  border: 1px solid #eeebf2b8; box-shadow: 1px 3px 5px #15121b99,inset 0 -3px 4px #49465494;
}
.gc-main-stick { left: var(--edge); top: 45px; width: calc(.84 * var(--unit)); }
.gc-c-stick { right: calc(var(--right-edge) + .49 * var(--unit)); bottom: 0; width: calc(.65 * var(--unit)); }
.gc-c-stick .gc-cap {
  color: #79550e; width: 54%; font-size: clamp(13px,2.7vw,20px); font-weight: 850;
  background: radial-gradient(circle at 40% 34%,#fff198,#eec133 68%,#a47c1b);
}
.gc-face { position: absolute; top: 42px; right: var(--right-edge); width: var(--unit); aspect-ratio: 1; }
.gc-face button { position: absolute; font-size: clamp(15px,2.7vw,21px); line-height: 1; }
.gc-face [data-touch-button=A] { --top:#55caaa; --bottom:#087555; left: 27%; top: 33%; width: 45%; height: 45%; border-radius: 50%; }
.gc-face [data-touch-button=B] { --top:#f57367; --bottom:#a92d38; left: 0; top: 63%; width: 29%; height: 29%; border-radius: 50%; }
.gc-face [data-touch-button=Y] { left: 23%; top: 3%; width: 46%; height: 25%; border-radius: 62% 62% 38% 40%; rotate: -12deg; }
.gc-face [data-touch-button=X] { right: 1%; top: 30%; width: 24%; height: 46%; border-radius: 45% 65% 62% 40%; rotate: -16deg; }
.gc-dpad {
  position: absolute; bottom: 0; left: calc(var(--edge) + .45 * var(--unit)); width: calc(.68 * var(--unit)); aspect-ratio: 1;
  display: grid; grid-template: repeat(3,1fr)/repeat(3,1fr);
}
.gc-dpad button,.gc-dpad span { --top:#85858fdf; --bottom:#464551d9; border-radius: 3px; color: #dad7e0; font-size: 13px; }
.gc-dpad .up {grid-area:1/2;} .gc-dpad .down {grid-area:3/2;} .gc-dpad .left {grid-area:2/1;} .gc-dpad .right {grid-area:2/3;}
.gc-dpad span { grid-area:2/2; background:#64636fdb; }
.touch-shoulders button { position: absolute; height: 34px; width: clamp(48px,11vw,78px); }
.touch-shoulders [data-touch-button=L] { top:0; left:var(--edge); border-radius: 65% 25% 35% 25%; }
.touch-shoulders [data-touch-button=R] { top:0; right:var(--right-edge); border-radius: 25% 65% 25% 35%; }
.touch-shoulders [data-touch-button=Z] { --top:#ab8ee2d9; --bottom:#68459bba; top:5px; right:calc(var(--right-edge) + clamp(48px,11vw,78px) + 6px); width:44px; height:28px; border-radius: 45% 30% 40% 30%; }
.touch-shoulders [data-touch-button=START] { top:44%; left:50%; translate:-50% 0; width:44px; height:29px; border-radius:50%; font-size:11px; }
@media (orientation: landscape) {
  .play-mode .touch-shoulders [data-touch-button=START] {
    top: auto;
    bottom: 0;
    left: var(--edge);
    translate: none;
  }
}
