:root {
  --bg: #0b0f14;
  --bg-panel: #131a22;
  --bg-elevated: #1c2530;
  --accent: #4da3ff;
  --accent-2: #33d17a;
  --danger: #ff4d4f;
  --text: #f2f5f8;
  --text-dim: #a9b7c6;
  --focus-ring: #ffd23f;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
}

/* ===== Screens ===== */
.screen {
  display: none;
  height: 100vh;
  width: 100vw;
}
.screen.screen-active {
  display: flex;
  align-items: center;
  justify-content: center;
}

.wrap {
  width: min(1000px, 92vw);
  padding: 2.5rem;
  text-align: center;
}

.logo {
  font-size: clamp(2rem, 5vw, 3.4rem);
  margin: 0 0 0.5rem;
}
.subtitle {
  color: var(--text-dim);
  font-size: clamp(1rem, 1.6vw, 1.3rem);
  margin-bottom: 2rem;
}
.title {
  font-size: clamp(1.6rem, 3.5vw, 2.4rem);
  margin-bottom: 1.5rem;
}

/* ===== Text field (real <input>: native PC keyboard + on-screen keyboard for TV) ===== */
.field-block { margin: 0 auto 1.2rem; max-width: 640px; }
.field-label {
  display: block;
  text-align: left;
  color: var(--text-dim);
  font-size: 1rem;
  margin-bottom: 0.4rem;
}
.text-display {
  display: block;
  width: 100%;
  background: var(--bg-panel);
  border: 3px solid transparent;
  border-radius: 14px;
  padding: 1rem 1.4rem;
  font-size: clamp(1.4rem, 2.6vw, 2rem);
  letter-spacing: 0.05em;
  text-align: left;
  outline: none;
  color: var(--text);
  font-family: inherit;
  caret-color: var(--accent);
}

/* ===== On-screen keyboard ===== */
.keyboard {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
  margin: 1.2rem auto;
  max-width: 720px;
}
.keyboard-row {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
  flex-wrap: wrap;
}
.key {
  background: var(--bg-elevated);
  color: var(--text);
  border: 3px solid transparent;
  border-radius: 10px;
  min-width: 3rem;
  height: 3rem;
  font-size: 1.2rem;
  font-weight: 600;
}
.key-wide {
  min-width: 7rem;
}
.key-accent { background: var(--accent); color: #06202f; }
.key-danger { background: var(--danger); color: #2a0000; }
.keyboard-compact .key { min-width: 2.2rem; height: 2.2rem; font-size: 1rem; }

/* ===== Buttons ===== */
.button-row {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}
.btn {
  padding: 1rem 2rem;
  font-size: 1.3rem;
  font-weight: 700;
  border-radius: 14px;
  border: 3px solid transparent;
  color: var(--text);
}
.btn-primary { background: var(--accent-2); color: #06301a; }
.btn-secondary { background: var(--bg-elevated); color: var(--text); }
.btn-small { padding: 0.6rem 1.2rem; font-size: 1rem; }

/* ===== Focus (TV remote friendly) ===== */
[data-focusable] {
  transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
[data-focusable]:focus {
  outline: none;
  border-color: var(--focus-ring) !important;
  box-shadow: 0 0 0 4px rgba(255, 210, 63, 0.35);
  transform: scale(1.04);
  z-index: 2;
  position: relative;
}

/* ===== Call screen ===== */
.call-layout {
  position: relative;
  width: 100vw;
  height: 100vh;
  background: #000;
}

.video-grid {
  display: grid;
  gap: 6px;
  width: 100%;
  height: 100%;
  padding: 6px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  grid-auto-rows: 1fr;
}
.video-tile {
  position: relative;
  background: #111;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111;
}
.video-tile.mirrored video { transform: scaleX(-1); }
.video-tile .tile-name {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(0,0,0,0.55);
  padding: 0.3rem 0.7rem;
  border-radius: 8px;
  font-size: 1rem;
}
.video-tile .tile-muted {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: rgba(255,77,79,0.85);
  padding: 0.3rem 0.5rem;
  border-radius: 8px;
  font-size: 1rem;
  display: none;
}
.video-tile.is-muted .tile-muted { display: block; }

/* Speaking indicator */
.tile-speaking-badge {
  display: none;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  background: var(--accent-2);
  color: #06301a;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  animation: speak-pulse 0.9s ease-in-out infinite;
}
.video-tile.speaking { box-shadow: 0 0 0 4px var(--accent-2) inset, 0 0 26px 6px rgba(51, 209, 122, 0.55); }
.video-tile.speaking .tile-speaking-badge { display: flex; }
@keyframes speak-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}

/* Tiles without camera (chat-only participants) */
.video-tile.no-media {
  background: linear-gradient(160deg, #1c2530, #0f151c);
}
.tile-placeholder {
  font-size: 4rem;
  opacity: 0.5;
}

/* Controls bar */
.controls {
  position: absolute;
  left: 50%;
  bottom: 2rem;
  transform: translateX(-50%);
  display: flex;
  gap: 1rem;
  background: rgba(15, 20, 26, 0.85);
  backdrop-filter: blur(6px);
  padding: 0.8rem 1.2rem;
  border-radius: 999px;
  transition: opacity 0.3s ease, transform 0.3s ease;
}
.controls.hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(120%);
  pointer-events: none;
}
.ctrl-btn {
  width: 3.6rem;
  height: 3.6rem;
  border-radius: 50%;
  border: 3px solid transparent;
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
}
.ctrl-btn.active-off {
  background: var(--danger);
}
.ctrl-btn-danger { background: var(--danger); }
.ctrl-btn:disabled { opacity: 0.3; }

/* Room info overlay */
.room-info {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.room-info.visible { display: flex; }
.room-info-inner {
  background: var(--bg-panel);
  border-radius: 20px;
  padding: 2rem 2.5rem;
  text-align: center;
  max-width: 90vw;
}
.room-info-label { color: var(--text-dim); margin: 0 0 1rem; font-size: 1.2rem; font-weight: 700; }
.qr-image { background: #fff; border-radius: 10px; padding: 8px; }
.room-info-hint { color: var(--text-dim); max-width: 420px; margin: 1rem auto; }

/* Settings panel */
.settings-inner { min-width: min(440px, 88vw); text-align: left; }
.settings-row { display: flex; flex-direction: column; gap: 0.4rem; margin-bottom: 1.2rem; }
.settings-row label { color: var(--text-dim); font-size: 0.95rem; }
.settings-row select {
  background: var(--bg-elevated);
  color: var(--text);
  border: 3px solid transparent;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font-size: 1.05rem;
  font-family: inherit;
  outline: none;
}

/* Chat panel */
.chat-panel {
  position: absolute;
  top: 0;
  right: 0;
  width: min(420px, 92vw);
  height: 100%;
  background: rgba(15, 20, 26, 0.97);
  display: none;
  flex-direction: column;
  z-index: 9;
  border-left: 2px solid var(--bg-elevated);
}
.chat-panel.visible { display: flex; }
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--bg-elevated);
}
.chat-header h3 { margin: 0; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.chat-msg {
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 0.6rem 0.9rem;
  max-width: 90%;
}
.chat-msg.mine { align-self: flex-end; background: var(--accent); color: #06202f; }
.chat-msg .chat-msg-name { display: block; font-size: 0.75rem; color: var(--text-dim); margin-bottom: 0.2rem; }
.chat-msg.mine .chat-msg-name { color: #06202f; opacity: 0.7; }
.chat-input-block {
  padding: 0.8rem;
  border-top: 1px solid var(--bg-elevated);
}
.chat-display { min-height: 1.4em; font-size: 1.1rem; margin-bottom: 0.6rem; }

/* Status bar */
.status-bar {
  position: absolute;
  top: 1rem;
  left: 1rem;
  background: rgba(0,0,0,0.5);
  padding: 0.4rem 0.9rem;
  border-radius: 10px;
  font-size: 0.95rem;
  color: var(--text-dim);
}

/* Larger baseline on big TV screens */
@media (min-width: 1600px) {
  :root { font-size: 20px; }
}
