/* Controls editor (ui/controls.js). Colours follow the page: space, limb, cloud, haze, sun. */
#controls { display: grid; grid-template-rows: auto 1fr; gap: 14px; overflow: auto;
	--u: clamp(38px, 2.7vw, 52px);
	--g-move: #6db4f2; --g-attack: #ff7a5c; --g-weapon: #ffb347; --g-view: #5fd4c4; --g-talk: #b99cff; --g-team: #7fd67f; --g-client: #9fb2cc; --g-misc: #f08fc0; --g-custom: #eaf2fb; }
#controls .kc-hint { margin: 0; color: var(--haze); flex: 1 1 14em; }
#controls .kc-tools, #controls .kc-row2 { display: flex; flex-wrap: wrap; gap: 8px; }

.kc-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 300px); gap: 22px; min-height: 0; }
.kc-board { min-width: 0; overflow-x: auto; padding-bottom: 6px; }
.kc-keys { display: flex; gap: calc(var(--u) * .45); width: max-content; }
.kc-block { display: grid; gap: 4px; align-content: start; }
.kc-row { display: flex; gap: 4px; height: var(--u); }
.kc-block.kc-main .kc-row:first-child, .kc-block.kc-nav .kc-row:first-child, .kc-block.kc-pad .kc-row:first-child { margin-bottom: calc(var(--u) * .3); }
.kc-gap { width: calc(var(--u) * var(--w) + 4px * (var(--w) - 1)); flex: none; }
.kc-key { --c: rgb(147 166 192 / .35); position: relative; flex: none; width: calc(var(--u) * var(--w) + 4px * (var(--w) - 1)); height: var(--u); padding: 0; overflow: hidden; cursor: pointer;
	color: var(--cloud); background: var(--well); border: 1px solid var(--line-soft); border-top: 2px solid var(--c); border-radius: 4px; text-align: left; }
.kc-key:hover { border-color: var(--limb); }
.kc-key.is-selected { outline: 2px solid var(--edge); outline-offset: 1px; z-index: 1; background: color-mix(in srgb, var(--edge) 30%, #0a1220) !important; }
.kc-key.is-pending::after { content: ''; position: absolute; top: 3px; right: 3px; width: 5px; height: 5px; border-radius: 50%; background: var(--sun); }
.kc-legend { position: absolute; top: 2px; left: 4px; font-size: max(9px, calc(var(--u) * .2)); color: var(--haze); }
/* a narrow face: the page's display type is too wide for a word on a key */
.kc-what { position: absolute; left: 2px; right: 1px; bottom: 3px; font: 400 max(8.5px, calc(var(--u) * .2))/1.12 'Arial Narrow', 'Roboto Condensed', 'Helvetica Neue', Arial, sans-serif; font-stretch: condensed; letter-spacing: -.035em; max-height: 2.16em; overflow: hidden; overflow-wrap: break-word; hyphens: auto; }
:is(.kc-key, .kc-now, .kc-groups li, .kc-actions h4).g-move { --c: var(--g-move); }
:is(.kc-key, .kc-now, .kc-groups li, .kc-actions h4).g-attack { --c: var(--g-attack); }
:is(.kc-key, .kc-now, .kc-groups li, .kc-actions h4).g-weapon { --c: var(--g-weapon); }
:is(.kc-key, .kc-now, .kc-groups li, .kc-actions h4).g-view { --c: var(--g-view); }
:is(.kc-key, .kc-now, .kc-groups li, .kc-actions h4).g-talk { --c: var(--g-talk); }
:is(.kc-key, .kc-now, .kc-groups li, .kc-actions h4).g-team { --c: var(--g-team); }
:is(.kc-key, .kc-now, .kc-groups li, .kc-actions h4).g-client { --c: var(--g-client); }
:is(.kc-key, .kc-now, .kc-groups li, .kc-actions h4).g-misc { --c: var(--g-misc); }
:is(.kc-key, .kc-now, .kc-groups li, .kc-actions h4).g-custom { --c: var(--g-custom); }
/* what a key belongs to is the line along its top and a breath of that colour; the page stays blue */
.kc-key[class*=' g-'] { background: color-mix(in srgb, var(--c) 9%, #0a1220); }

.kc-mouse { margin-top: 18px; }
.kc-mouse h3 { margin-bottom: 6px; }
.kc-mouse-box { position: relative; width: 600px; height: 250px; }
.kc-mouse-art { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.kc-mouse-box .kc-key { position: absolute; width: 150px; height: 44px; }
.kc-mouse-box .kc-what { font-size: 12px; }
.kc-mouse-box .kc-legend { font-size: 10px; }
.kc-lead { fill: none; stroke: rgb(147 166 192 / .4); stroke-width: 1; }
.kc-mouse-body { fill: var(--card); stroke: rgb(147 166 192 / .55); stroke-width: 1.5; }
.kc-mouse-well { fill: #050a14; stroke: rgb(147 166 192 / .4); }
.kc-mouse-mark { fill: none; stroke: #050a14; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
.kc-part { --c: rgb(147 166 192 / .55); fill: color-mix(in srgb, var(--c) 22%, #0a1220); stroke: var(--c); stroke-width: 1; cursor: pointer; }
.kc-part:not([class*=' g-']) { fill: #111b2c; }
.kc-part:hover { stroke: var(--cloud); }
.kc-part.is-selected { stroke: var(--edge); stroke-width: 2.5; }
:is(.kc-part).g-move { --c: var(--g-move); } .kc-part.g-attack { --c: var(--g-attack); } .kc-part.g-weapon { --c: var(--g-weapon); } .kc-part.g-view { --c: var(--g-view); }
.kc-part.g-talk { --c: var(--g-talk); } .kc-part.g-team { --c: var(--g-team); } .kc-part.g-client { --c: var(--g-client); } .kc-part.g-misc { --c: var(--g-misc); } .kc-part.g-custom { --c: var(--g-custom); }
.kc-groups { display: flex; flex-wrap: wrap; gap: 4px 18px; list-style: none; margin: 18px 0 0; padding: 0; color: var(--haze); font-size: 12px; }
.kc-groups li::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border-radius: 2px; background: var(--c); }
.kc-status { margin: 12px 0 0; min-height: 1.4em; color: var(--haze); font-size: 13px; max-width: 60em; }

.kc-edit { display: flex; flex-direction: column; gap: 8px; min-height: 0; padding: 16px; border: 1px solid var(--line); border-radius: 4px; background: var(--well); }
.kc-edit p { margin: 0; }
.kc-now { padding: 7px 10px; border: 1px solid color-mix(in srgb, var(--c, var(--line)) 60%, transparent); border-radius: 3px; background: color-mix(in srgb, var(--c, transparent) 10%, transparent); font-weight: 600; overflow-wrap: anywhere; }
.kc-also, .kc-empty { color: var(--haze); font-size: 13px; }
#controls input:is([type=search], [type=text]), #controls textarea { width: 100%; }
.kc-actions { flex: 1 1 200px; min-height: 120px; overflow-y: auto; border: 1px solid rgb(147 166 192 / .2); border-radius: 3px; padding: 4px 6px 8px; }
.kc-actions h4 { margin: 10px 0 4px; font-size: 12px; font-weight: 400; color: var(--haze); position: sticky; top: -4px; background: #050a14; padding: 3px 0; } .kc-actions h4::before { content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 6px; border-radius: 2px; background: var(--c); }
.kc-actions button { width: 100%; text-align: left; color: var(--cloud); background: none; border: 0; border-radius: 3px; padding: 4px 8px; cursor: pointer; }
.kc-actions button:hover { background: rgb(147 166 192 / .18); }
.kc-actions button.is-current { background: var(--now); box-shadow: inset 0 0 0 1px var(--now-line); font-weight: 600; }
.kc-ownlabel { display: grid; gap: 4px; color: var(--haze); font-size: 12px; }
.kc-own { font-family: ui-monospace, Menlo, Consolas, monospace !important; font-size: 13px !important; }

.kc-sheet { position: fixed; inset: 0; z-index: 21; display: grid; grid-template-rows: auto auto auto 1fr auto; gap: 10px; align-content: start; margin: auto; width: min(680px, calc(100vw - 32px)); height: min(560px, calc(100vh - 32px));
	padding: 18px; box-sizing: border-box; background: #0b1320; border: 1px solid var(--line); border-radius: 5px; box-shadow: 0 0 0 100vmax var(--well); }
.kc-sheet[hidden] { display: none; }
.kc-sheet p { margin: 0; color: var(--haze); }
.kc-sheet textarea { min-height: 140px; height: 100%; resize: none; font: 13px/1.45 ui-monospace, Menlo, Consolas, monospace !important; white-space: pre; }
.kc-sheet:has(input[type=file]) { grid-template-rows: auto auto auto 1fr auto; }
.kc-sheet:not(:has(input[type=file])) { grid-template-rows: auto auto 1fr auto; }

@media (max-width: 900px) { .kc-body { grid-template-columns: minmax(0, 1fr); } .kc-actions { max-height: 40vh; } }
.kc-key.is-dead { opacity: .4; cursor: default; border-style: dashed; }
.kc-devices { display: flex; flex-wrap: wrap; gap: 6px 40px; align-items: start; }
.kc-pad-keys { margin-top: 18px; flex: none; max-width: 100%; }
.kc-pad-keys h3 { margin-bottom: 6px; }
.kc-pad-note { margin: 0 0 10px; color: var(--haze); font-size: 13px; max-width: 46em; }
.kc-pad-box { width: 720px; height: 380px; }
.kc-warn { margin: 14px 0 0; color: var(--sun); font-size: 13px; }
.kc-warn:empty { display: none; }
.kc-actions button { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.kc-on { flex: none; color: var(--haze); font-size: 11px; }
#controls .kc-only { color: var(--limb); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; font-size: inherit; }
/* touch screens: the page is two parts, picked here */
.kc-device { width: 100%; }
#controls.is-touch :is(.kc-hint, .kc-shape, .kc-layout, .kc-tools button:not(.kc-done), .kc-body) { display: none; }
@media (pointer: coarse) { #controls :is(.kc-device, .kc-tools) :is(button, select) { min-height: 40px; } }
.kc-edit-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.kc-edit-head h3 { margin: 0; }
.kc-edit-close, .kc-keys-title { display: none; }
/* A small screen (a phone either way up) with the keyboard and gamepad part open: the page scrolls as one, the
   gamepad comes first (a phone with a controller is the likely case), the mouse is left out, and what a key does
   is chosen in a sheet that opens when a key is tapped and is closed again, so the keys keep the screen. */
@media (max-width: 700px), (max-height: 520px) {
	/* no blur behind the page here: a blurred box would hold the sheet inside itself, and it would scroll away with the keys */
	html.pre #controls, #controls { --u: 34px; display: block; overflow-x: hidden; backdrop-filter: none; background: rgb(3 6 13 / .94); }
	#controls > header { margin-bottom: 14px; }
	.kc-body { display: block; }
	.kc-board { display: flex; flex-direction: column; overflow: visible; }
	.kc-devices { order: -1; margin-bottom: 18px; }
	.kc-pad-keys { margin-top: 0; width: 100%; }
	.kc-mouse { display: none; }
	.kc-pad-box { width: auto; height: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 4px; }
	.kc-pad-box .kc-mouse-art { position: static; grid-column: 1 / -1; justify-self: center; width: min(100%, 420px, 74vh); height: auto; aspect-ratio: 380 / 268; margin-bottom: 6px; }
	.kc-pad-box .kc-lead { display: none; }
	.kc-pad-box .kc-key { position: relative; left: auto !important; top: auto !important; width: auto; }
	.kc-keys-title { display: block; margin: 0 0 6px; }
	.kc-keys-title::after { content: 'Swipe sideways for the rest of it.'; display: block; margin-top: 4px; color: var(--haze); font-size: 13px; font-weight: 400; }
	/* only the keyboard scrolls sideways, never the page */
	.kc-keys { flex: none; overflow-x: auto; overscroll-behavior-x: contain; width: auto; max-width: 100%; padding: 2px 0 10px; }
	.kc-block { flex: none; }
	.kc-groups { display: none; }
	.kc-edit.is-empty { display: none; }
	.kc-edit { position: fixed; z-index: 40; left: 0; right: 0; bottom: 0; max-height: 64vh; padding: 14px 16px max(14px, env(safe-area-inset-bottom)); border-width: 1px 0 0; border-radius: 10px 10px 0 0; background: #0b1320; box-shadow: 0 0 0 100vmax rgb(3 6 13 / .4); }
	.kc-edit-close { display: block; min-height: 40px; }
	.kc-key { scroll-margin: 130px 12px calc(64vh + 12px); }
	#controls:has(.kc-edit:not(.is-empty)) .kc-board { padding-bottom: 64vh; } /* room to scroll the last rows clear of the sheet */
	.kc-actions { min-height: 90px; max-height: none; }
	.kc-actions button { min-height: 40px; }
	.kc-status:empty { display: none; }
}
@media (max-width: 700px) {
	#controls .kc-tools { display: grid; grid-template-columns: 1fr 1fr; }
	#controls .kc-tools select { width: 100%; min-width: 0; }
}
/* a phone held sideways: the sheet is a column on the right, the full height */
@media (max-height: 520px) and (min-width: 600px) {
	.kc-key { scroll-margin: 60px calc(min(340px, 46vw) + 12px) 12px 12px; }
	#controls:has(.kc-edit:not(.is-empty)) .kc-board { padding-bottom: 0; }
	#controls:has(.kc-edit:not(.is-empty)) .kc-keys { padding-right: min(340px, 46vw); }
	.kc-edit { left: auto; top: 0; width: min(340px, 46vw); max-height: none; border-width: 0 0 0 1px; border-radius: 0; padding: 12px 14px; overflow-y: auto; }
}

/* A desktop window: the keyboard takes the whole width (beside the side panel its number pad was cut off), its
   keys as large as fit; what the chosen key does is picked in a panel beside the mouse and gamepad, which stays in
   view while the page scrolls. */
@media (min-width: 901px) and (min-height: 521px) {
	#controls { --u: clamp(34px, calc((100vw - 2 * var(--pad) - 120px) / 23.2), 58px); }
	.kc-body { grid-template-columns: minmax(0, 1fr) minmax(260px, 330px); grid-auto-rows: max-content; align-content: start; align-items: start; gap: 0 28px; min-height: max-content; } /* as tall as it is: the page scrolls, not this box (squeezed, its rows fell on top of each other) */
	.kc-keys { flex: none; }
	.kc-board { display: contents; }
	.kc-keys { grid-column: 1 / -1; grid-row: 1; width: auto; max-width: 100%; overflow-x: auto; padding-bottom: 6px; }
	.kc-groups { grid-column: 1 / -1; grid-row: 2; margin: 10px 0 22px; }
	.kc-devices { grid-column: 1; grid-row: 3; } .kc-devices > :first-child { margin-top: 0; }
	.kc-warn { grid-column: 1; grid-row: 4; } .kc-status { grid-column: 1; grid-row: 5; }
	.kc-edit { grid-column: 2; grid-row: 3 / span 3; position: sticky; top: 0; max-height: calc(100vh - 150px); box-sizing: border-box; }
}
#controls:focus { outline: none; }
