/* Home page layout and components (stream + commentary) */

/* 1. Reset & basic typography */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { min-height: 100dvh; height: auto; }
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; color: #fff; background: #000; }
a { color: #0ff; text-decoration: none; }
a:hover { text-decoration: underline; }

/* Optional helper when fixed nav is present (home uses inline nav so keep disabled) */
body.home.fd-has-fixed-nav { padding-top: 0; }
/* No fixed nav on home; ensure any fixed styles don't apply */
body.home .fd-nav { top: auto; }

/* 2. Layout */
#cfstream { position: relative; z-index: 10; }

/* 3. Canvas grid background */
.canvas-wrapper {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
}
.canvas-wrapper canvas { width: 100%; height: 100%; }

/* Ensure stream content is above background and visible */
#stream-content-wrapper {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  gap: 2rem;
  padding: 2rem;
  min-height: 60vh;
}

/* 4. Components */
.stream-aspect-ratio-box {
  position: relative;
  padding-top: 56.25%; /* 16:9 */
  width: 100%;
  overflow: hidden;
}
.stream-aspect-ratio-box iframe {
  width: 100%;
  height: 100%;
  display: block;
  position: absolute;
  top: 0; left: 0;
}

.player-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0 0;
}
.player-controls #play-button,
.player-controls #play-stream-button,
.player-controls #skip-button {
  padding: 0.5rem 1rem;
  background: #222;
  color: #fff;
  border: 1px solid #555;
  /* Enforce rectangular buttons on iOS/Safari */
  -webkit-appearance: none;
  appearance: none;
  border-radius: 4px;
  cursor: pointer;
}
.player-controls #play-button:hover,
.player-controls #play-stream-button:hover,
.player-controls #skip-button:hover {
  background: #2e2e2e;
}


/* Ensure touch-sized controls on small devices */
@media (max-width: 480px) {
}

#stream-embed-wrapper {
  width: calc(100% - 400px - 2rem);
  flex-grow: 1;
  flex-shrink: 0;
}

#commentary-wrapper {
  flex-shrink: 0;
  position: relative;
  z-index: 5;
  opacity: 1 !important;
}

#channel-selector {
  margin-bottom: 1rem;
  background-color: #2a2a2a !important;
  color: #fff !important;
  border: 1px solid #555 !important;
  padding: 0.5rem;
  font-family: monospace;
  opacity: 1 !important;
  position: relative;
  z-index: 5;

  /* Enforce rectangular select on iOS/Safari */
  -webkit-appearance: none;
  appearance: none;
  border-radius: 4px;

  /* Add a simple custom arrow to replace native one when appearance is none */
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath fill='%23c8c8c8' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 10px 6px;
}

#commentary-container {
  width: 400px;
  height: 600px;
  padding: 1rem;
  border: 1px solid #333;
  background-color: #111 !important;
  opacity: 1 !important;
  overflow-y: scroll;
  font-family: monospace;
  position: relative;
  z-index: 5;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.5);
}

.commentary-line { margin-bottom: 0.5rem; padding: 0.375rem 0.5rem; border-radius: 4px; }
/* Subtle zebra striping for conversational rhythm */
.commentary-line:nth-child(odd) { background: rgba(255,255,255,0.035); }
.speaker { font-weight: 700; }
/* Quick visual identity: colored dot follows currentColor */
.speaker::before { content: none; }

/* Speaker identity colors */
.speaker.gemma { color: #ff8a80; }         /* coral red */
.speaker.llama { color: #80d8ff; }         /* sky blue */
.speaker.plato { color: #ffd54f; }         /* amber */
.speaker.anaxagoras { color: #a5d6a7; }    /* soft green */
.speaker.susan-sontag { color: #ce93d8; }  /* violet */
.speaker.pauline-kael { color: #ffb74d; }  /* orange */
.speaker.franz { color: #4db6ac; }         /* teal */
.speaker.zwei  { color: #f06292; }         /* pink */

/* Legacy mappings (backward compatible) */
.speaker.walter { color: #ff8a80; }
.speaker.sunny { color: #80d8ff; }

/* --- Mobile layout & readability improvements --- */

/* Stack layout on narrow screens; prioritize video, keep commentary readable */
@media (max-width: 900px) {
  #stream-content-wrapper {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    padding: 1rem;
    min-height: unset;
  }
  #stream-embed-wrapper {
    width: 100% !important;
    flex: 1 1 auto;
    order: 1;
  }
  #commentary-wrapper {
    width: 100%;
    order: 2;
  }
  #channel-selector {
    width: 100%;
  }
  #commentary-container {
    width: 100%;
    height: clamp(280px, 50vh, 420px);
    -webkit-overflow-scrolling: touch;
    overflow-wrap: anywhere;
  }
}

/* Coarser, softer background visualizer on mobile */
@media (max-width: 600px) {
  .canvas-wrapper {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
    opacity: 0.3;
  }
}
@media (max-width: 360px) {
  .canvas-wrapper { opacity: 0.2; }
}

/* Controls, typography, and video sizing on small devices */
@media (max-width: 480px) {
  .player-controls { gap: 0.5rem; }
  .player-controls #play-button,
  .player-controls #play-stream-button,
  .player-controls #skip-button {
    min-height: 44px;
    padding: 0.75rem 1rem;
    font-size: 1rem; /* ~16px */
  }
  #track-info { font-size: 12px; line-height: 1.3; }
  #commentary-container { font-size: 14px; line-height: 1.5; }
  #channel-selector { font-size: 16px; }

  /* Prefer aspect-ratio when available to avoid padding-top hack */
  .stream-aspect-ratio-box {
    aspect-ratio: 16 / 9;
    padding-top: 0;
    height: auto;
  }
}

/* Commentary timestamps */
.commentary-line .timestamp {
  color: #9aa0a6;         /* muted gray-blue on dark */
  font-size: 0.85em;      /* smaller than body */
  margin-left: 0.5rem;    /* space from text */
  opacity: 0.9;           /* keep legible but subtle */
  white-space: nowrap;    /* stay on one line */
  transition: opacity 160ms ease; /* gentle reveal when appended after typing */
}

/* Typing indicator (iMessage-style ellipsis) */
.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0 10px 0;
  padding: 6px 8px;
  background: rgba(255,255,255,0.06);
  border: 1px solid #2a2a2a;
  border-radius: 12px;
  color: #9aa0a6;
}

.typing-indicator .dot {
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
  opacity: 0.35;
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40%          { transform: translateY(-3px); opacity: 0.95; }
}
