/* The play screen: a slim glass bar at the top, the direction pad and the action keys in the two lower corners, and the whole middle left
   to the chamber. The sizes below are mirrored by src/stage.js (HUD), which fits the board around them; tests/latticewake-layout.test.mjs
   reads both and fails when they differ. */
:root {
  --lw-ui: 1;
  --lw-bar-top: 8px;
  --lw-bar-h: 44px;
  --lw-bar-gap: 6px;
  --lw-stats-row: 38px;
  --lw-pad: 40px;
  --lw-pad-gap: 4px;
  --lw-pad-margin: 12px;
  --lw-action: 40px;
  --lw-action-wide: 64px;
  /* plain translucent glass, no blur of what is behind it: the chamber moves under it every frame and a blur there costs frame rate */
  --lw-glass: linear-gradient(150deg, rgba(9, 27, 40, .78), rgba(4, 11, 20, .72));
}
@media (pointer: coarse), (max-width: 760px) {
  :root {
    --lw-bar-top: 4px;
    --lw-bar-h: 44px;
    --lw-pad: 48px;
    --lw-pad-gap: 4px;
    --lw-pad-margin: 8px;
    --lw-action: 48px;
    --lw-action-wide: 72px;
  }
}
/* A large window with a mouse: the bar, the cards and the keys grow with it in two steps, so the text is comfortable at 1080p. 1280x720 stays as it is. */
@media (min-width: 1600px) and (min-height: 900px) and (pointer: fine) { :root { --lw-ui: 1.25; } }
@media (min-width: 1900px) and (min-height: 1000px) and (pointer: fine) { :root { --lw-ui: 1.4; } }
.hud-bar, .hud-brief, .hud-rules, .pad-cross, .pad-actions, #toast { zoom: var(--lw-ui); }

#game { background: #040a11; }

/* ---- the top bar ------------------------------------------------------------------------------------------------------------------------ */
.hud, .hud:not(.hidden) { position: fixed; inset: 0; display: block; padding: 0; pointer-events: none; z-index: 10; }
.hud.hidden { display: none; }
.hud-bar { position: absolute; top: calc(var(--lw-bar-top) + env(safe-area-inset-top, 0px)); left: calc(10px + env(safe-area-inset-left, 0px)); right: calc(10px + env(safe-area-inset-right, 0px)); height: var(--lw-bar-h); display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: stretch; column-gap: 8px; }
.hud .glass.compact { pointer-events: auto; border-width: 5px; border-image: url('./assets/art/ui-panel-frame.webp') 40 / 5px stretch; border-radius: 0; background: var(--lw-glass); background-clip: border-box; box-shadow: 0 6px 22px rgba(0, 0, 0, .34); -webkit-backdrop-filter: none; backdrop-filter: none; }
.hud .hud-left { grid-column: 1; grid-row: 1; position: static; justify-self: start; max-width: 100%; min-width: 0; padding: 0 .7rem; display: flex; flex-direction: column; justify-content: center; cursor: pointer; }
.hud-left .eyebrow { flex: 0 0 auto; margin: 0 0 1px; font-size: .56rem; letter-spacing: .2em; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-left h1 { flex: 0 0 auto; margin: 0; font-size: .95rem; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-left:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.hud .hud-center { grid-column: 2; grid-row: 1; position: static; justify-self: center; max-width: none; padding: 0 .5rem; display: flex; align-items: center; gap: .2rem; }
.hud-center div { min-width: 78px; text-align: center; padding: 0 .35rem; }
.hud-center div + div { border-inline-start: 1px solid rgba(164, 230, 238, .16); }
.hud-center span { font-size: .52rem; letter-spacing: .12em; line-height: 1.2; white-space: nowrap; }
.hud-center strong { display: block; font-size: .92rem; line-height: 1.2; white-space: nowrap; }
#integrity { min-height: 17px; }
#integrity .pip { width: 12px; height: 17px; }
.hud-right { grid-column: 3; grid-row: 1; position: static; justify-self: end; display: flex; align-items: center; gap: .3rem; pointer-events: auto; }
.hud-right button { min-height: 32px; height: 32px; padding: 0 .35rem; font-size: .72rem; opacity: .86; }
.hud-right button:hover, .hud-right button:focus-visible { opacity: 1; }

/* The brief: a card under the chamber name that folds away by itself and comes back on hover, focus, a click or the I key. */
.hud-brief { position: absolute; top: calc(var(--lw-bar-top) + var(--lw-bar-h) + var(--lw-bar-gap) + env(safe-area-inset-top, 0px)); left: calc(10px + env(safe-area-inset-left, 0px)); max-width: min(380px, calc(100vw - 20px)); padding: .4rem .7rem !important; transition: opacity .28s ease, transform .28s ease, visibility 0s linear 0s; }
.hud-brief p { margin: 0; color: #cfe0ea; font-size: .78rem; line-height: 1.45; }
.hud.brief-closed .hud-brief { opacity: 0; transform: translateY(-6px); visibility: hidden; pointer-events: none; transition: opacity .28s ease, transform .28s ease, visibility 0s linear .28s; }
.hud.brief-closed:has(.hud-left:focus-visible) .hud-brief { opacity: 1; transform: none; visibility: visible; transition-delay: 0s; }
/* hover brings it back only where there is a real pointer: on a touch screen a tap leaves a hover behind that would never let it fold */
@media (hover: hover) { .hud.brief-closed:has(.hud-left:hover) .hud-brief { opacity: 1; transform: none; visibility: visible; transition-delay: 0s; } }

/* The rule line of the special chambers, under the buttons on the right. */
.hud-rules { position: absolute; top: calc(var(--lw-bar-top) + var(--lw-bar-h) + var(--lw-bar-gap) + env(safe-area-inset-top, 0px)); right: calc(10px + env(safe-area-inset-right, 0px)); max-width: min(440px, calc(100vw - 20px)); display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 6px; pointer-events: none; }
.hud-rules p { margin: 0 !important; padding: .22rem .6rem; border-radius: 999px; font-size: .7rem; line-height: 1.3; font-weight: 700; letter-spacing: .03em; background-color: rgba(4, 12, 21, .8) !important; }
.hud-rules .finale-rule { border: 1px solid rgba(115, 231, 237, .5); }

/* ---- the controls in the lower corners --------------------------------------------------------------------------------------------------- */
.touch, .touch:not(.hidden) { position: fixed; inset: 0; left: 0; bottom: 0; transform: none; display: block; z-index: 12; pointer-events: none; }
.touch.hidden { display: none; }
.pad-cross { position: absolute; left: calc(var(--lw-pad-margin) + env(safe-area-inset-left, 0px)); bottom: calc(var(--lw-pad-margin) + env(safe-area-inset-bottom, 0px)); display: grid; grid-template-columns: repeat(3, var(--lw-pad)); grid-template-rows: repeat(3, var(--lw-pad)); gap: var(--lw-pad-gap); pointer-events: none; }
.pad-cross button { pointer-events: auto; }
.pad-cross [data-action="up"] { grid-area: 1 / 2; }
.pad-cross [data-action="left"] { grid-area: 2 / 1; }
.pad-cross [data-action="pulse"] { grid-area: 2 / 2; }
.pad-cross [data-action="right"] { grid-area: 2 / 3; }
.pad-cross [data-action="down"] { grid-area: 3 / 2; }
.pad-actions { position: absolute; right: calc(var(--lw-pad-margin) + env(safe-area-inset-right, 0px)); bottom: calc(var(--lw-pad-margin) + env(safe-area-inset-bottom, 0px)); display: flex; gap: var(--lw-pad-gap); pointer-events: auto; }
.touch button, .touch button.wide { width: var(--lw-pad); height: var(--lw-pad); min-height: 0; padding: 0; border-width: 7px 9px; border-image-width: 7px 9px; font-size: .8rem; line-height: 1; touch-action: manipulation; }
.pad-actions button { width: var(--lw-action); height: var(--lw-action); }
.pad-actions button.wide { width: var(--lw-action-wide); font-size: .68rem; }
/* With a mouse and a keyboard the keys on screen stay out of the way until the pointer or the focus reaches them. */
@media (hover: hover) and (pointer: fine) {
  .pad-cross, .pad-actions { opacity: .42; transition: opacity .2s ease; }
  .pad-cross:hover, .pad-cross:focus-within, .pad-actions:hover, .pad-actions:focus-within { opacity: 1; }
}

/* ---- messages ---------------------------------------------------------------------------------------------------------------------------- */
/* A message appears under the top bar, in the air above the top row of the chamber: it covers no counter, no button and not the tile you are walking to. */
#toast, #toast.show { top: calc(var(--lw-bar-top) + var(--lw-bar-h) + 10px + env(safe-area-inset-top, 0px)); bottom: auto; max-width: min(460px, 34vw); font-size: .86rem; }
#toast { transform: translate(-50%, -14px); }
#toast.show { transform: translate(-50%, 0); }

/* ---- touch and narrow windows ------------------------------------------------------------------------------------------------------------ */
@media (pointer: coarse), (max-width: 760px) {
  .hud-bar { left: calc(6px + env(safe-area-inset-left, 0px)); right: calc(6px + env(safe-area-inset-right, 0px)); column-gap: 6px; }
  .hud .hud-left { padding: 0 .55rem; max-width: 100%; }
  .hud-left h1 { font-size: .9rem; }
  .hud .hud-center { padding: 0 .2rem; max-width: none; top: auto; right: auto; gap: 0; }
  .hud-center div { min-width: 62px; padding: 0 .3rem; flex: 0 0 auto; }
  .hud-center strong { font-size: .88rem; }
  .hud-right { top: auto; right: auto; gap: .25rem; }
  .hud-right button { height: 44px; min-height: 44px; min-width: 56px; opacity: 1; font-size: .76rem; }
  .hud-brief { left: calc(6px + env(safe-area-inset-left, 0px)); }
  .hud-brief p { font-size: .74rem; }
  .hud-left #level-brief, .hud-brief #level-brief { display: block; }
  .hud-rules { right: calc(6px + env(safe-area-inset-right, 0px)); }
  #toast, #toast.show { max-width: min(460px, 88vw); font-size: .8rem; }
  .title-panel { margin-bottom: 0; }
}
/* An upright phone: the name and the two buttons on the first row, the three counters on a second one. */
@media (max-width: 599px) {
  .hud-bar { height: auto; grid-template-columns: minmax(0, 1fr) auto; grid-template-rows: var(--lw-bar-h) calc(var(--lw-stats-row) - 4px); row-gap: 4px; }
  .hud .hud-left { grid-column: 1; grid-row: 1; }
  .hud-right { grid-column: 2; grid-row: 1; }
  .hud .hud-center { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; justify-content: space-around; }
  .hud-center div { flex: 1 1 0; min-width: 0; }
  .hud-center span { font-size: .46rem; line-height: 1.1; }
  .hud-center strong { font-size: .8rem; line-height: 1.15; }
  #integrity { min-height: 13px; }
  #integrity .pip { width: 9px; height: 13px; }
  /* a rule line and the brief share the narrow column: the brief steps down under it */
  .hud:has(.hud-rules p:not(.hidden)) .hud-brief { margin-top: 30px; }
  .hud-brief, .hud-rules { top: calc(var(--lw-bar-top) + var(--lw-bar-h) + var(--lw-stats-row) + var(--lw-bar-gap) + env(safe-area-inset-top, 0px)); }
  /* an upright phone has free room between the chamber and the keys: a message goes there, clear of the bar, the counters and the brief */
  #toast, #toast.show { top: auto; bottom: calc(var(--lw-pad) * 3 + var(--lw-pad-gap) * 2 + var(--lw-pad-margin) * 2 + 10px + env(safe-area-inset-bottom, 0px)); }
}

/* A phone on its side: a slimmer message, still under the bar, so the counters stay in sight. */
@media (max-height: 520px) {
  #toast, #toast.show { max-width: min(400px, 48vw); padding: .1rem .8rem; }
  .hud-brief { max-width: min(330px, 42vw); }
}

/* While a window is open (pause, settings, a result) a message lies at the bottom edge, off its buttons; the next key or tap puts it away. */
body:has(.screen.active) #toast, body:has(.screen.active) #toast.show { top: auto; bottom: calc(8px + env(safe-area-inset-bottom, 0px)); }

/* Touch: every control of the windows is 44 CSS px or more. The mouse layout is untouched. */
@media (pointer: coarse) {
  .settings input[type=checkbox] { width: 44px; height: 44px; margin: 0; accent-color: var(--cyan); }
  .settings label { padding: .35rem 0; min-height: 52px; }
  .modal button, .story-panel button, .ending-panel button, .tabs button { min-height: 44px; }
  .modal.result > button { min-height: 44px; }
  .settings input[type=range] { height: 44px; background-size: 100% 26px; background-position: center; }
}
/* a phone on its side: the window fills the height, so the message lies over its heading, not over a button */
@media (max-height: 520px) { body:has(.screen.active) #toast, body:has(.screen.active) #toast.show { top: calc(4px + env(safe-area-inset-top, 0px)); bottom: auto; } }

/* ---- the windows over the chamber --------------------------------------------------------------------------------------------------------- */
/* The painted chamber stays behind every window, out of focus, as the archive does behind the title. */
.screen { background: radial-gradient(ellipse at 50% 44%, rgba(4, 12, 20, .30), rgba(2, 5, 9, .74)); -webkit-backdrop-filter: blur(10px) saturate(1.1); backdrop-filter: blur(10px) saturate(1.1); }
.story-screen { background: radial-gradient(circle at 50% 42%, rgba(89, 42, 103, .26), rgba(2, 5, 9, .84)); }

.high-contrast .hud .glass.compact, .high-contrast .hud-rules p { background: rgba(2, 6, 11, .92) !important; }
@media (prefers-reduced-motion: reduce) { .hud-brief, .pad-cross, .pad-actions, #toast { transition: none !important; } }
