/* The room around the TV (spec.md > Decisions; approved mockup: devpost/room-mockup.html).
   Only active with html.has-room, which js/app.js sets once the 3D room has started. Without it
   (no WebGL, a phone, or the room failed to load) none of this applies and the app is the flat TV. */

/* ── Layers: the 3D room fills the window ────────────────────── */

.room-stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #05070c;
}

.has-room body {
  display: block;
  padding: 0;
  overflow: hidden;
}

/* The flat TV frame is not used with the room: the 3D TV is the frame. */
.has-room main.tv {
  display: none;
}

/* The HTML layer (the app screen) sits under the WebGL canvas. The canvas is see-through at the
   TV glass, so the app shows there, and it takes no clicks, so the app's buttons get them. */
.room-css {
  position: absolute !important;
  inset: 0;
}

.room-gl {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

/* The app screen on the glass: a fixed 880 x 660 CSS-pixel screen (4:3) that the 3D layer scales.
   Its own look (rounded glass, inner glow, sections, VHS layer) comes from css/base.css. */
.room-screen {
  width: 880px;
  height: 660px;
}

.room-screen > .tv__screen {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  border-radius: 18px / 22px;
}

/* In the room the app is a picture: no hover effects or text cursor until the camera is in. */
.room-screen [inert] {
  user-select: none;
}

/* ── CRT curve on the live app screen (learner choice: "1 dan 2") ─ */

/* 1. Laptops and desktops: a thin barrel bend from an SVG displacement filter. The form is still
      the real form: it takes clicks and typing; near the edges the picture sits a few pixels
      inward from where the click lands, so the bend is kept small. */
.crt-bend .room-screen > .tv__screen {
  filter: url(#crt-bend);
}

/* 2. Everywhere else (and on top of 1): the tube's look without moving any pixels: darker,
      rounded corners and a curved glass glare. */
.room-screen > .tv__screen::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 12;
  pointer-events: none;
  border-radius: inherit;
  background:
    radial-gradient(ellipse 120% 95% at 30% 12%, rgba(255, 255, 255, 0.07) 0%, transparent 42%),
    radial-gradient(ellipse at 50% 50%, transparent 62%, rgba(0, 0, 0, 0.55) 100%);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.7);
}

/* ── Room controls: the time panel (top right) and the hint (bottom) ── */

.room-ui {
  font-family: var(--font-osd);
}

.room-panel {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 5;
  width: min(280px, calc(100vw - 28px));
  padding: 8px 12px;
  border: 1px solid rgba(217, 222, 232, 0.18);
  border-radius: 8px;
  background: rgba(5, 7, 12, 0.78);
  backdrop-filter: blur(6px);
  font-size: 18px;
  line-height: 1.2;
  transition: opacity 0.3s;
}

.room-panel h2 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: normal;
  letter-spacing: 0.08em;
}

.room-panel .times {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.room-panel button,
.photo-panel button {
  padding: 1px 9px;
  border: 1px solid rgba(217, 222, 232, 0.3);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  letter-spacing: 0.06em;
  cursor: pointer;
}

.room-panel .toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  float: right;
  min-height: 34px;
  padding: 2px 10px;
}

.room-panel h2 {
  margin: 10px 0 2px;
  clear: both;
  color: rgba(217, 222, 232, 0.65);
  font-size: 16px;
}

/* A small "sliders" icon drawn in CSS (VT323 has no symbol for it). */
.toggle__icon {
  position: relative;
  width: 14px;
  height: 12px;
  border-top: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}

.toggle__icon::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 3px;
  border-top: 2px solid currentColor;
}

.room-panel button[aria-pressed='true'] {
  border-color: var(--ready);
  color: var(--ready);
}

.room-panel.is-hidden {
  width: auto;
  padding: 4px;
}

.room-panel.is-hidden > :not(.toggle) {
  display: none;
}

/* With the camera in the TV the panel fades out, so it never covers the app. */
.zoomed .room-panel {
  opacity: 0;
}

.zoomed .room-panel:hover,
.zoomed .room-panel:focus-within {
  opacity: 1;
}

/* Bottom-left, where the floor is empty (not over the coffee table), on a darker plate. */
.hint {
  position: fixed;
  bottom: 14px;
  left: 14px;
  z-index: 5;
  padding: 4px 14px;
  border: 1px solid rgba(217, 222, 232, 0.28);
  border-radius: 6px;
  background: rgba(5, 7, 12, 0.88);
  backdrop-filter: blur(6px);
  color: #e8ecf3;
  font: inherit;
  font-size: 20px;
  letter-spacing: 0.06em;
  white-space: nowrap; /* one line, also on a small window */
  pointer-events: none;
}

.hint.is-button {
  border: 1px solid rgba(98, 255, 143, 0.6);
  color: var(--ready);
  pointer-events: auto;
  cursor: pointer;
}

/* With the camera in the TV, BACK TO THE ROOM sits centred in the dark band under the glass. */
.zoomed .hint {
  left: 50%;
  bottom: 6px;
  transform: translateX(-50%);
  font-size: 18px;
}

/* HOW IT WORKS: the AI models and prompts behind the pictures. */
/* Top left, so it never covers the room controls it was opened from (top right). */
.how-panel {
  position: fixed;
  top: 68px; /* under the SOUND button */
  left: 14px;
  z-index: 7;
  width: min(420px, calc(100vw - 28px));
  max-height: calc(100dvh - 80px);
  overflow-y: auto;
  padding: 12px 16px 14px;
  border: 1px solid rgba(217, 222, 232, 0.22);
  border-radius: 8px;
  background: rgba(5, 7, 12, 0.92);
  backdrop-filter: blur(8px);
  font-size: 18px;
  line-height: 1.3;
}

.how-panel h2 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: normal;
  letter-spacing: 0.08em;
}

.how-panel p {
  margin: 6px 0;
  color: rgba(217, 222, 232, 0.85);
}

.how-panel details p,
.how-panel code {
  font-family: var(--font-answer);
  font-size: 13px;
  line-height: 1.45;
}

.how-panel summary {
  margin-top: 6px;
  color: var(--ready);
  cursor: pointer;
}

.how-panel__note {
  font-size: 15px;
  opacity: 0.7;
}

.how-panel__close {
  float: right;
  min-width: 34px;
  min-height: 34px;
  border: 1px solid rgba(217, 222, 232, 0.3);
  border-radius: 4px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 22px;
  cursor: pointer;
}

/* The name of the thing under the pointer, above it (js/room.js moves and fades it). */
.hover-label {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 4;
  padding: 1px 8px;
  border: 1px solid rgba(98, 255, 143, 0.55);
  border-radius: 4px;
  background: rgba(5, 7, 12, 0.82);
  color: var(--ready);
  font-size: 17px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  will-change: transform, opacity;
}

/* ── PHOTO panel: the player zooms and moves their own picture in the frame ── */

.photo-panel {
  position: fixed;
  left: 14px;
  bottom: 56px;
  z-index: 6;
  width: 230px;
  padding: 10px 12px 12px;
  border: 1px solid rgba(217, 222, 232, 0.2);
  border-radius: 8px;
  background: rgba(5, 7, 12, 0.86);
  backdrop-filter: blur(6px);
  font-size: 18px;
}

.photo-panel h2 {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: normal;
  letter-spacing: 0.08em;
}

.photo-panel canvas {
  display: block;
  width: 153px; /* the frame's shape: 0.13 x 0.17 m */
  height: 200px;
  margin: 0 auto 8px;
  border: 6px solid #2b2018;
  border-radius: 2px;
  cursor: grab;
  touch-action: none;
}

.photo-panel canvas:active {
  cursor: grabbing;
}

.photo-panel label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: rgba(217, 222, 232, 0.8);
}

.photo-panel input[type='range'] {
  flex: 1;
  accent-color: var(--ready);
}

.photo-panel p {
  margin: 4px 0 6px;
  color: rgba(217, 222, 232, 0.6);
  font-size: 16px;
}

.photo-panel .row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.photo-panel button[data-photo-done] {
  border-color: var(--ready);
  color: var(--ready);
}

/* Used by the automated checks so the overlay doesn't tint brightness numbers. */
.clean .room-panel,
.clean .photo-panel,
.clean .hint {
  visibility: hidden;
}

/* High contrast: the room's own controls get solid plates and white text. */
.high-contrast .room-panel,
.high-contrast .photo-panel,
.high-contrast .how-panel,
.high-contrast .hint {
  border-color: #ffffff;
  background: #000000;
  color: #ffffff;
}

.high-contrast .room-panel button,
.high-contrast .photo-panel button {
  border-color: #ffffff;
}

/* ── Loading screen (while the room's code and pictures arrive) ── */

.room-loading {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--vcr-blue);
  color: #ffffff;
  font-family: var(--font-osd);
  transition: opacity 0.5s;
}

/* Fading out: it no longer takes clicks, so the room underneath works at once. */
.room-loading.is-done {
  opacity: 0;
  pointer-events: none;
}

.room-loading__title {
  display: flex;
  align-items: center;
  gap: 0.4em;
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  letter-spacing: 0.08em;
}

.room-loading__bar {
  display: grid;
  grid-template-columns: repeat(20, 1fr);
  gap: 3px;
  width: min(360px, 70vw);
  height: 24px;
  padding: 3px;
  border: 2px solid #ffffff;
}

.room-loading__cell {
  background: #ffffff;
  opacity: 0;
}

.room-loading__cell.is-on {
  opacity: 1;
}

.room-loading__meta {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.06em;
}

.no-webgl {
  position: fixed;
  left: 50%;
  bottom: 12px;
  z-index: 20;
  margin: 0;
  padding: 4px 12px;
  transform: translateX(-50%);
  border: 1px solid rgba(217, 222, 232, 0.3);
  border-radius: 6px;
  background: rgba(5, 7, 12, 0.9);
  font-size: 18px;
  letter-spacing: 0.04em;
  text-align: center;
}

/* ── Touch screens and small windows: buttons at least 44 px ── */

@media (pointer: coarse), (max-width: 900px) {
  .room-panel button,
  .photo-panel button,
  .how-panel__close,
  .hint.is-button {
    min-width: 44px;
    min-height: 44px;
  }
}

/* A short landscape window (a phone on its side): smaller panels so the TV stays in view. */
@media (max-height: 520px) {
  .room-panel {
    max-height: calc(100dvh - 28px);
    overflow-y: auto;
  }

  .hint {
    font-size: 16px;
  }
}

/* Touch screens with the room: the app on the TV glass is scaled down, so buttons get a minimum size
   in the app's own pixels that comes out at 44 px on screen (--tap is set by js/room.js). */
@media (pointer: coarse) {
  .room-screen button { min-height: var(--tap, 44px); }
  .room-screen .tape__eject { min-width: var(--tap, 44px); }
}

/* Phones and tablets (js/room.js LITE): no frosted-glass blur behind the plates and panels. The blur
   re-renders the 3D room behind every plate each frame, which costs a phone GPU more than the room
   itself; the plates are made a little more opaque instead. */
.room-lite .room-panel,
.room-lite .hint,
.room-lite .how-panel,
.room-lite .photo-panel,
.room-lite .sound-quick,
.room-lite .room-toggle {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.room-lite .room-panel,
.room-lite .hint,
.room-lite .photo-panel { background: rgba(5, 7, 12, 0.94); }
