/* Basic page centering */
:root {
  --scene-w: 1628; /* px - intrinsic */
  --scene-h: 1222; /* px - intrinsic */
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: #111;
  color: #fff;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  display: grid;
  place-items: center;
}

.page-center {
  width: min(95vw, 95vh * calc(var(--scene-w) / var(--scene-h)));
  /* Maintain the scene aspect ratio so coordinates map proportionally */
  aspect-ratio: calc(var(--scene-w) / var(--scene-h));
}

/* Top controls */
.top-controls {
  width: min(95vw, 95vh * calc(var(--scene-w) / var(--scene-h)));
  margin: 12px auto 6px;
  display: flex;
  justify-content: flex-start;
}

.top-controls #toggleGameBtn {
  font: inherit;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #2a2a2a;
  color: #fff;
  cursor: pointer;
}

.top-controls #toggleGameBtn.active {
  background: #0f5132;
  border-color: #0b3d25;
}

.stage {
  position: relative;
  width: 100%;
  height: 100%;
}

/* Fill sits behind and gets transformed to the screen area */
.fill-frame {
  position: absolute;
  z-index: 0;
  overflow: hidden; /* crop fill to the frame */
}

.fill-frame::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  /* Scanlines */
  background: repeating-linear-gradient(
    to bottom,
    rgba(255,255,255,0.04) 0px,
    rgba(255,255,255,0.04) 1px,
    rgba(0,0,0,0.12) 2px,
    rgba(0,0,0,0.12) 3px
  );
  mix-blend-mode: overlay;
  opacity: .55;
  animation: crtScan 8s linear infinite;
}

.fill-frame::after {
  content: "";
  position: absolute;
  left: -1px;
  top: -1px;
  right: -1px;
  bottom: -1px;
  pointer-events: none;
  /* Slight vignette and subtle RGB shadow mask */
  background:
    radial-gradient(ellipse at center,
      rgba(0,0,0,0) 60%,
      rgba(0,0,0,0.15) 85%,
      rgba(0,0,0,0.35) 100%),
    repeating-linear-gradient(90deg,
      rgba(255,0,0,0.05) 0px,
      rgba(255,0,0,0.05) 1px,
      rgba(0,255,0,0.05) 1px,
      rgba(0,255,0,0.05) 2px,
      rgba(0,0,255,0.05) 2px,
      rgba(0,0,255,0.05) 3px
    );
  mix-blend-mode: multiply;
  opacity: .45;
}

.fill {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover; /* best-fit for any replacement image */
  /* Slightly punch up color and apply tiny warp */
  filter: url(#crt-warp) contrast(1.06) saturate(1.08) brightness(1.02);
}

@keyframes crtScan {
  0% { transform: translateY(0); }
  100% { transform: translateY(3px); }
}


/* Scene on top */
.scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  z-index: 1;
  pointer-events: none;
}


/* Command input below the scene */
.command-bar {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  width: min(95vw, 95vh * calc(var(--scene-w) / var(--scene-h)));
  align-items: center;
}

.command-bar input[type="text"] {
  font: inherit;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #333;
  background: #1a1a1a;
  color: #fff;
}

.command-bar button {
  font: inherit;
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #2a2a2a;
  color: #fff;
  cursor: pointer;
}

.command-bar button:disabled {
  opacity: .6;
  cursor: default;
}

.command-bar #sendStatus {
  font-size: .9em;
  opacity: .8;
}

/* Surrogate page layout */
.surrogate-wrap {
  width: min(95vw, 95vh * calc(var(--scene-w) / var(--scene-h)));
}

.surrogate-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 16px 0 8px;
}

.surrogate-header h1 {
  font-size: 1.25rem;
  margin: 0;
}

.since-info {
  opacity: .85;
  font-size: .95em;
}

.voice-cta {
  margin-left: auto;
  font: inherit;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #2a2a2a;
  color: #fff;
  cursor: pointer;
}

.message-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 8px;
}

.message-item {
  background: #1a1a1a;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  padding: 10px 12px;
}

.message-item time {
  color: #c7c7c7;
  font-size: .9em;
}

.message-text {
  color: #fff;
}

/* Overlay chat bubbles in main scene */
.message-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 48px; /* leave room for clock */
  z-index: 2; /* above .scene */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  pointer-events: none; /* don't block clicks */
}

/* LED Clock - bottom right of center image */
.led-clock {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  font-family: 'Courier New', monospace;
  font-size: clamp(10px, 2vw, 16px);
  font-weight: bold;
  color: #ff3333;
  text-shadow:
    0 0 2px #ff0000,
    0 0 4px #ff0000,
    0 0 8px #ff3333,
    0 0 12px #ff6666;
  background: rgba(0, 0, 0, 0.75);
  padding: 4px 10px;
  border-radius: 4px;
  border: 1px solid #333;
  letter-spacing: 1px;
  pointer-events: none;
  opacity: 0.9;
}

.message-bubble {
  max-width: 80%;
  background: rgba(20,20,20,.92);
  color: #fff;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 18px;
  padding: 10px 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,.35);
  backdrop-filter: blur(2px);
  word-break: break-word;
  line-height: 1.25;
  font-size: 1rem;
  opacity: 0;
  transform: translateY(8px) scale(.98);
  animation: bubbleLife 10s ease-in-out forwards;
}

@keyframes bubbleLife {
  0%   { opacity: 0; transform: translateY(8px) scale(.98); }
  5%   { opacity: 1; transform: translateY(0) scale(1); }
  85%  { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(10px) scale(.98); }
}
