/* SPDX-License-Identifier: GPL-3.0-or-later */
:root { color-scheme: dark; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; background: #0d1012; color: #a0b4c4; --green: #62b28d; }
* { box-sizing: border-box; }
body { margin: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
[hidden] { display: none !important; }
#app { max-width: 820px; margin: 24px auto; padding: 26px; border: 1px solid #35413f; border-radius: 16px; background: #14181c; min-height: calc(100dvh - 48px); }
header { display: flex; justify-content: space-between; gap: 14px; padding-bottom: 18px; border-bottom: 1px solid #29322f; }
h1 { margin: 0 0 12px; color: #eeeee3; font-size: clamp(16px, 4vw, 28px); font-weight: 500; letter-spacing: 1px; }
h2 { font-size: 17px; font-weight: 400; margin-top: 28px; }
#screen-title { margin: 0; font-size: 19px; }
.identity { text-align: right; font-size: 11px; color: #80908c; overflow-wrap: anywhere; max-width: 35%; }
.identity span { display: block; margin-bottom: 8px; }
#status { font-family: system-ui, sans-serif; font-size: 14px; min-height: 24px; overflow-wrap: anywhere; line-height: 1.6; }
#status.error { color: #f2ab98; }
.screen { padding-top: 12px; }
button, input, select { font: inherit; }
button { color: #b8c7d0; background: #1b2327; border: 1px solid #3b4d49; border-radius: 4px; padding: 14px 16px; min-height: 48px; cursor: pointer; text-align: left; }
button:hover, button:focus-visible { background: #26483e; color: var(--green); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--green); outline-offset: 3px; }
button:disabled { opacity: .38; cursor: default; }
button small { display: block; font-size: 11px; margin-top: 8px; color: #8c9c96; }
.menu button { width: 100%; display: block; margin-bottom: 10px; border-color: transparent; padding: 18px; font-size: 20px; }
.primary { color: var(--green); background: #24453b; }
.quiet { background: transparent; border-color: transparent; color: #879891; }
.screen > button { margin: 6px 6px 6px 0; }
label { display: block; margin: 0 0 22px; font-size: 13px; }
input:not([type=range]):not([type=checkbox]), select { width: 100%; margin-top: 9px; padding: 12px; min-height: 48px; border: 1px solid #3e4b49; border-radius: 4px; color: #e5ece6; background: #0f1418; }
input[type=range] { display: block; width: 100%; margin-top: 16px; accent-color: var(--green); }
.help { font: 13px/1.7 system-ui, sans-serif; color: #899b94; }
.settings-update-row { display: flex; align-items: center; gap: 12px; margin: 14px 0; }
.settings-update-row button { flex: 1; min-width: 0; font-size: 14px; }
#pwa-version { flex-shrink: 0; white-space: nowrap; font-size: 13px; color: #899b94; }
.rom-row { margin-bottom: 12px; padding: 14px; background: #1a2225; border: 1px solid #2b3936; border-radius: 6px; }
.rom-row p { overflow-wrap: anywhere; font-size: 13px; line-height: 1.5; }
.rom-row button { padding: 10px; margin-right: 8px; font-size: 12px; }
.key-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.key-row button { width: 180px; }
button, canvas { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
button { touch-action: manipulation; }
input, textarea { -webkit-user-select: text; user-select: text; }
html.playing, html.playing body, html.editing-layout, html.editing-layout body { overflow: hidden; overscroll-behavior: none; height: 100%; }
html.playing body { padding: 0; }
html.playing #app { margin: 0; padding: 0; border: 0; border-radius: 0; max-width: none; min-height: 0; height: var(--game-height, 100dvh); }
html.playing #app > header, html.playing #status { display: none; }
.game-frame {
  position: fixed; top: var(--game-top, 0px); left: var(--game-left, 0px);
  width: var(--game-width, 100%); height: var(--game-height, 100dvh);
  display: grid; grid-template-rows: 44px minmax(0, 1fr) 216px; gap: 6px;
  padding: max(4px, env(safe-area-inset-top)) env(safe-area-inset-right) max(10px, env(safe-area-inset-bottom)) env(safe-area-inset-left);
  background: #e2e3e5; color: #3c4247; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
.game-header { padding: 0 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; letter-spacing: 1px; }
.game-header button { width: 44px; height: 44px; min-height: 44px; padding: 0; text-align: center; border: 0; color: #3c4247; background: transparent; font-size: 25px; }
.game-header button:hover { background: #cdd1d4; }
.game-display { margin: 0 12px; min-width: 0; min-height: 0; display: flex; align-items: start; justify-content: center; padding: 4px 0; position: relative; }
canvas { display: block; background: #000; max-width: 100%; max-height: 100%; image-rendering: pixelated; -webkit-user-drag: none; }
.game-display.booting::after { content: ""; position: absolute; top: 40%; width: 24px; height: 24px; border: 3px solid #555; border-top-color: #ddd; border-radius: 50%; animation: boot-spin 1s linear infinite; }
@keyframes boot-spin { to { transform: rotate(360deg); } }
#game-menu, #room-game-menu { width: min(360px, calc(100vw - 24px)); max-height: calc(var(--game-height, 100dvh) - 32px); padding: 18px; border: 1px solid #455b52; border-radius: 14px; background: #14181c; color: #b8c7d0; overflow-y: auto; overscroll-behavior: contain; }
#game-menu::backdrop, #room-game-menu::backdrop { background: #0009; }
.game-menu-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.game-menu-header h2 { margin: 0; font-size: 16px; }
.game-menu-header button { min-height: 40px; width: 40px; text-align: center; padding: 0; border: 0; background: transparent; font-size: 25px; }
#game-menu > button, #room-game-menu > button { display: block; width: 100%; margin-top: 8px; }
#game-message, #room-game-status, #room-status, #room-create-status, #room-join-status { font: 13px/1.6 system-ui, sans-serif; overflow-wrap: anywhere; }
#game-message:empty { display: none; }
#game-message.error, #room-game-status.error, #room-status.error, #room-create-status.error, #room-join-status.error { color: #f2ab98; }
.room-save-notice { margin: 24px 0; font: 13px/1.7 system-ui,sans-serif; color: #899b94; }
.room-save-notice h2 { font: 13px ui-monospace,monospace; color: #a0b4c4; }
#room-code { background: #26483e; font-size: 30px; letter-spacing: .25em; text-align: center; }
#room-heading { margin: 4px 0 18px; color: #eeeee3; font-size: 21px; overflow-wrap: anywhere; }
#room-members { margin-bottom: 20px; color: #eeeee3; overflow-wrap: anywhere; }
#room-members p { margin: 10px 0; }
.room-slot-row { display: grid; grid-template-columns: 135px minmax(0,1fr); gap: 10px; align-items: center; margin-bottom: 10px; }
.room-slot-row label { margin: 0; font-size: 12px; }
.room-slot-row select { margin: 0; font-size: 13px; }
.room-slot-row span { font-size: 13px; color: #899b94; overflow-wrap: anywhere; }
.room-setting-row { display: grid; grid-template-columns: 135px minmax(0,1fr); gap: 0 10px; align-items: center; margin: 16px 0; }
.room-setting-row label { margin: 0; }.room-setting-row select { margin: 0; }
.room-setting-row .help { grid-column: 2; margin: 8px 0 0; font-size: 11px; }
.room-ready-row { display: flex; gap: 18px; align-items: center; margin-bottom: 20px; }
.room-ready-row button { min-width: 135px; }.room-ready-row p { font-size: 12px; }
#room-chat-log { height: 110px; overflow-y: auto; border: 1px solid #374046; padding: 8px 12px; margin-bottom: 16px; font: 13px/1.5 system-ui,sans-serif; overflow-wrap: anywhere; }
#room-chat-log p { margin: 0 0 5px; }
#room-chat-form label, #room-screen > label { margin-bottom: 8px; }
.room-chat-input-row { display: flex; gap: 8px; }.room-chat-input-row input { margin: 0 !important; min-width: 0; }
.room-chat-input-row button { flex-shrink: 0; }
#connection { display: block; margin-top: 16px; font-size: 10px; color: #7f9188; }
aside { margin-top: 20px; border: 1px solid #997452; border-radius: 6px; padding: 16px; color: #e8c4a6; }
aside p { font: 13px/1.6 system-ui, sans-serif; }
aside button { margin: 4px; font-size: 11px; }
#screenshots { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
#screenshots img { width: 100%; image-rendering: pixelated; border-radius: 4px; }
#screenshots a { color: var(--green); font-size: 12px; }
#screenshots button { margin-top: 8px; font-size: 11px; }
@media (max-width: 600px) {
  #app { margin: 0; padding: 18px 14px; border: 0; border-radius: 0; min-height: 100dvh; }
  .identity { font-size: 9px; }.menu button { font-size: 18px; }
}
@media (orientation: landscape) {
  .game-header { grid-column: 1 / -1; }
  .game-display { grid-area: 2 / 2; align-items: center; }
}
/* Individually editable control surfaces. */
.game-frame { grid-template-rows: 44px minmax(0, 1fr) 250px; }
.touch-controls { touch-action: none; display: block; width: 100%; height: 250px; position: absolute; padding: 0; pointer-events: none; }
.touch-controls .main-controls, .touch-controls .action-buttons, .touch-controls .system-buttons, .touch-controls .speed-buttons { display: contents; }
.touch-controls .dpad { position: absolute; pointer-events: none; }
.touch-controls .dpad::before { content: ""; position: absolute; top: 33.333%; left: 33.333%; width: 33.334%; height: 33.334%; background: #45484b; }
.touch-controls button { pointer-events: auto; }
.touch-controls button[data-key] { color: white; background: #45484b; border: 0; text-align: center; padding: 0; touch-action: none; position: absolute; min-height: 0; border-radius: 6px; font-size: 15px; }
.touch-controls button[data-key="4"], .touch-controls button[data-key="5"] { border-radius: 50%; font-size: 24px; font-weight: 600; background: #a31429; }
.touch-controls button[data-key="6"], .touch-controls button[data-key="7"] { border-radius: 99px; font-size: 11px; }
.touch-controls button[data-key="8"], .touch-controls button[data-key="9"] { background: #666c70; }
.touch-controls button.active { background: #267453; }
html.playing *, #layout-editor, #layout-editor * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-user-drag: none; }
#game-menu, #game-menu * { touch-action: pan-y; }
#layout-editor { position: fixed; top: var(--game-top,0px); left: var(--game-left,0px); width: var(--game-width,100vw); height: var(--game-height,100dvh); max-width: none; max-height: none; margin: 0; border: 0; padding: 0; overflow: hidden; background: #e2e3e5; color: #3c4247; }
#layout-editor::backdrop { background: #e2e3e5; }
#layout-stage { z-index: 0; }
#layout-editor .game-header h2 { margin: 0; font-size: 14px; }
#layout-header-actions { display: flex; gap: 4px; }
#layout-editor .game-header button { width: 44px; font-size: 13px; }
#layout-save { font-weight: bold; }
#layout-tools { position: absolute; z-index: 2; top: calc(54px + env(safe-area-inset-top)); right: max(8px,env(safe-area-inset-right)); width: min(320px,calc(100% - 16px)); max-height: calc(var(--game-height,100dvh) - 80px - env(safe-area-inset-top)); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; border: 1px solid #455b52; border-radius: 10px; padding: 14px; color: #b8c7d0; background: #14181cf5; box-shadow: 0 4px 20px #0004; }
#layout-tools .help:first-child { margin-top: 0; }
#layout-tools label { margin-bottom: 12px; }
#layout-message:empty { display: none; }
#layout-message { font: 13px/1.6 system-ui,sans-serif; color: #f2ab98; }
#layout-preview [data-object] { touch-action: none; cursor: grab; }
#layout-preview [data-object].selected { outline: 3px solid #19a779; outline-offset: -3px; }
#layout-preview .dpad { pointer-events: auto; }
html.editing-layout *, #layout-editor * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-user-drag: none; }
@media (orientation: landscape) {
  .game-frame { grid-template-columns: 26% minmax(0,1fr) 26%; grid-template-rows: 44px minmax(0,1fr); }
  .game-display { padding-bottom: 46px; }
  .touch-controls button { pointer-events: auto; }
}

.remember-login { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font: 14px system-ui, sans-serif; }
.remember-login input { flex: 0 0 22px; width: 22px; height: 22px; margin: 0; accent-color: var(--green); }

.touch-controls button.player-selected { color: #fff; background: #267453; box-shadow: inset 0 0 0 2px #125c3d; }

/* Focused editable fields must not use the label's smaller text on iOS. */
#app input:not([type=range]):not([type=checkbox]), #app textarea, #app select, #app [contenteditable=true] { font-size: max(16px, 1em); }
/* Cover the complete drag path, including the gaps/centre of the D-pad. */
.game-frame *, .touch-controls *, .touch-controls *::before, .touch-controls *::after { -webkit-user-select: none !important; user-select: none !important; -webkit-touch-callout: none; -webkit-user-drag: none; }
.touch-controls .dpad { pointer-events: auto; touch-action: none; }
.touch-controls button[data-key]::after { content: attr(data-label); display: grid; place-items: center; width: 100%; height: 100%; pointer-events: none; }
.resume-overlay { position: absolute; z-index: 3; min-height: 0; margin: 0; padding: 8px; border: 0; border-radius: 0; background: #0009; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; touch-action: manipulation; }
.resume-overlay:hover, .resume-overlay:focus-visible { background: #000a; color: #fff; }
.resume-overlay span { font-size: clamp(36px, 10vw, 64px); line-height: 1; }
.resume-overlay small { font: 16px/1.5 system-ui,sans-serif; color: #fff; margin: 0; }
.resume-overlay:disabled { opacity: 1; cursor: wait; }

#app #room-code { font-size: 30px; }
