/* Page around the game canvas. External (not inline): ignants.com's CSP has no style-src 'unsafe-inline'. */
html, body { margin: 0; height: 100%; background: #000; overflow: hidden; }
body { touch-action: none; overscroll-behavior: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#game, #touch, #touch button, #overlay { touch-action: none; }
canvas { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; outline: none; }
@supports (height: 100dvh) { canvas { height: 100dvh; } }
#overlay {
  position: fixed; inset: 0; box-sizing: border-box; padding: 16px; z-index: 4;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: #07040d; color: #e8e4f0; text-align: center;
  font: 600 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
#overlay[hidden] { display: none; }
#overlay.ready { cursor: pointer; }
.logo {
  font: 900 clamp(28px, 7vw, 64px)/1 system-ui, sans-serif; letter-spacing: 0.04em;
  background: linear-gradient(90deg, #ff1a8c, #ffeb0d, #0dd9ff, #73ff1a, #b340ff, #ff800d);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.sub { font-size: clamp(16px, 3vw, 24px); letter-spacing: 0.2em; color: #fff; }
#status { margin-top: 18px; font-size: 18px; letter-spacing: 0.08em; color: #ffd919; min-height: 1.5em; }
#overlay.ready #status { animation: blink 1s steps(2, start) infinite; }
#overlay.error #status { color: #ff6b6b; animation: none; max-width: 40em; }
.keys { max-width: 46em; font-weight: 400; font-size: 13px; color: #a9a3b8; }
.keys b { color: #e8e4f0; }
.mobile-keys { display: none; }
@media (pointer: coarse) {
  .desktop-keys { display: none; }
  .mobile-keys { display: block; }
  #overlay { padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom)); gap: 8px; }
  #status { margin-top: 8px; }
  .keys { margin: 4px 0; }
}
.legal { position: absolute; bottom: 12px; left: 16px; right: 16px; font-weight: 400; font-size: 11px; color: #7d778c; }
@media (pointer: coarse) { #overlay .legal { position: static; margin: 0; } }
@keyframes blink { to { visibility: hidden; } }
.noscript { color: #fff; font-family: sans-serif; padding: 16px; }

/* Touch controls: shown while the screen is being played by touch. */
#touch { --button-size: clamp(44px, 12vh, 56px); position: fixed; inset: 0; z-index: 2; pointer-events: none; font: 700 14px/1 system-ui, sans-serif; color: #fff; }
#touch[hidden] { display: none; }
#stickzone { position: absolute; left: 0; top: 30%; bottom: 0; width: 46%; pointer-events: auto; }
#stick {
  /* A moving visual must not change WebKit's touch target during a gesture. */
  pointer-events: none;
  position: absolute; left: calc(max(16px, env(safe-area-inset-left)) + 64px); top: calc(100% - 84px);
  width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; box-sizing: border-box;
  border: 2px solid rgba(255, 255, 255, 0.3); background: rgba(255, 255, 255, 0.06); opacity: 0.6;
}
#stick.on { opacity: 1; }
#stick span { position: absolute; pointer-events: none; font-size: 19px; line-height: 20px; }
#stick .up { top: 4px; left: 44px; } #stick .down { bottom: 4px; left: 44px; }
#stick .left { left: 6px; top: 44px; } #stick .right { right: 6px; top: 44px; }
#knob {
  position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.35); border: 2px solid rgba(255, 255, 255, 0.6); box-sizing: border-box;
}
#pad {
  position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom));
  display: grid; grid-template-columns: repeat(3, var(--button-size)); gap: 6px; pointer-events: auto;
}
.tb {
  appearance: none; -webkit-appearance: none; color: inherit; font: inherit; padding: 0;
  width: var(--button-size); height: var(--button-size); border-radius: 50%; box-sizing: border-box; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 10, 30, 0.22); border: 2px solid rgba(255, 255, 255, 0.45); text-shadow: 0 1px 2px #000;
}
.tb.p { border-color: rgba(255, 90, 90, 0.8); }
.tb.k { border-color: rgba(90, 200, 255, 0.8); }
.tb.s { border-color: rgba(255, 220, 60, 0.85); }
.tb.a { border-color: rgba(200, 120, 255, 0.85); }
.tb.wide { width: auto; grid-column: span 2; border-radius: 26px; font-size: 13px; }
.tb.on { background: rgba(255, 255, 255, 0.4); }
.tb:focus-visible { outline: 2px solid #ffd919; outline-offset: 2px; }
.tb .confirm { display: block; font-size: 10px; margin-top: 2px; }
.tb[data-b="LP"] { flex-direction: column; }
#touch-menu {
  position: absolute; bottom: max(6px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  display: flex; gap: 8px; pointer-events: auto;
}
#tstart, #tback { width: 68px; height: 44px; border-radius: 22px; font-size: 12px; }
#fullscreen {
  position: fixed; z-index: 6; top: max(6px, env(safe-area-inset-top)); right: max(6px, env(safe-area-inset-right));
  width: 52px; height: 44px; padding: 2px; border: 1px solid #c9bdde; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; background: #160e23e6; font: 700 10px/1.2 system-ui, sans-serif; touch-action: manipulation;
}
#fullscreen svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; }
#fullscreen:focus-visible { outline: 2px solid #ffd919; outline-offset: 2px; }
#fullscreen[aria-pressed="true"] { border-color: #ffd919; color: #ffd919; }
body.touch.playing #touch-menu { left: calc(50% - 30px); }
body.touch.playing #fullscreen { top: auto; right: auto; left: calc(50% + 50px); bottom: max(6px, env(safe-area-inset-bottom)); }
#touch-help { display: none; }
#rotate {
  position: fixed; left: 16px; right: 16px; top: max(16px, env(safe-area-inset-top)); z-index: 3;
  display: none; pointer-events: none; color: #ffd919; text-align: center; font: 600 13px/1.4 system-ui, sans-serif;
}
@media (orientation: landscape) {
  body.touch canvas { height: calc(100vh - max(56px, calc(env(safe-area-inset-bottom) + 50px))); }
  @supports (height: 100dvh) { body.touch canvas { height: calc(100dvh - max(56px, calc(env(safe-area-inset-bottom) + 50px))); } }
}
@media (orientation: portrait) {
  body.touch #rotate { display: block; }
  body.touch canvas {
    inset: auto; left: max(8px, env(safe-area-inset-left));
    top: max(calc(env(safe-area-inset-top) + 56px), calc((100vh - 56.25vw - 260px) / 2));
    width: calc(100% - max(8px, env(safe-area-inset-left)) - max(8px, env(safe-area-inset-right)));
    height: auto; aspect-ratio: 16 / 9;
  }
  #touch { --button-size: clamp(44px, 12vw, 56px); }
  #pad { bottom: calc(max(8px, env(safe-area-inset-bottom)) + 54px); }
  #stickzone { top: auto; height: 190px; bottom: calc(max(8px, env(safe-area-inset-bottom)) + 54px); width: 45%; }
  #stick { left: 50%; top: 50%; }
  #touch-help { display: block; position: absolute; bottom: calc(max(8px, env(safe-area-inset-bottom)) + 248px); left: 10px; right: 10px; text-align: center; font-size: 10px; line-height: 1.5; color: #bfb7cf; }
  @supports (height: 100dvh) { body.touch canvas { top: max(calc(env(safe-area-inset-top) + 56px), calc((100dvh - 56.25vw - 260px) / 2)); } }
}

/* Replay link and room code dialogs */
.dialog {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 8; width: min(92vw, 560px);
  box-sizing: border-box; padding: 16px; border-radius: 12px; background: #120b1c; border: 2px solid #ffd919;
  color: #e8e4f0; font: 500 14px/1.4 system-ui, sans-serif; -webkit-user-select: text; user-select: text; touch-action: auto;
}
.dialog[hidden] { display: none; }
.dialog p { margin: 0 0 10px; }
.dialog input { width: 100%; box-sizing: border-box; padding: 8px; font: 16px/1.3 ui-monospace, monospace; background: #000; color: #fff;
                border: 1px solid #555; border-radius: 6px; }
#codeinput { font: 700 32px/1.2 ui-monospace, monospace; letter-spacing: 0.4em; text-align: center; text-transform: uppercase; }
.dialog .row { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; }
.dialog button { min-height: 44px; font: 700 14px system-ui, sans-serif; padding: 8px 14px; border-radius: 8px; border: 0; background: #ffd919; color: #120b1c; }
.dialog button#shareclose, .dialog button#codecancel { background: #3a3346; color: #fff; }
#fullscreen-help { max-height: calc(100vh - 24px); overflow: hidden; }
#fullscreen-help:not([hidden]) { display: flex; flex-direction: column; }
#fullscreen-help .fullscreen-instructions { min-height: 0; overflow: auto; touch-action: pan-y; }
#fullscreen-help .row { flex-shrink: 0; }
#fullscreen-help ol { padding-left: 22px; }
#fullscreen-help li { margin-bottom: 8px; }
