/* ── Fonts ───────────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Atkinson+Hyperlegible+Mono:ital,wght@0,200..800;1,200..800&display=swap');

:root {
  --body-font: "Atkinson Hyperlegible Mono", monospace;

  /* Surface colors */
  --bg-base:       #2d2b22;
  --bg-surface:    #3a3830;
  --bg-overlay:    #504d40;
  --bg-muted:      #5c5a4d;
  --bg-highlight:  #6b6858;

  /* Text colors */
  --text-primary:  #d4be98;
  --text-secondary:#a89b84;
  --text-muted:    #7c7160;

  /* Accent colors */
  --accent:        #d8a657;
  --accent-teal:   #6ba3a0;
  --accent-olive:  #8b9a5e;
  --accent-brown:  #a67c53;

  /* Semantic colors */
  --error:         #ea6962;
  --success:       #a9b665;
  --warning:       #d8a657;

  /* Border colors */
  --border-default:#504d40;
  --border-focus:  #d8a657;

  /* Aliases */
  --off-white:     var(--text-primary);
  --bad:           var(--error);

  /* UI tokens (dark) */
  --btn-bg:         rgba(212, 190, 152, 0.12);
  --btn-bg-hover:   rgba(212, 190, 152, 0.22);
  --input-bg:       rgba(212, 190, 152, 0.08);
  --border-subtle:  var(--border-default);
  --spinner-track:  rgba(212, 190, 152, 0.15);
  --spinner-head:   rgba(212, 190, 152, 0.70);
  --card-bg:        rgba(212, 190, 152, 0.04);
}

/* ── Light theme ────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg-base:       #e8e0cc;
  --bg-surface:    #ddd5c0;
  --bg-overlay:    #cfc7b0;
  --bg-muted:      #bfb7a0;
  --bg-highlight:  #b0a890;
  --text-primary:  #3a3830;
  --text-secondary:#5c5a4d;
  --text-muted:    #7c7160;
  --accent:        #b8862f;
  --accent-teal:   #4a7a77;
  --accent-olive:  #5a6a3e;
  --accent-brown:  #7a5c33;
  --error:         #c62828;
  --success:       #5a7a2e;
  --warning:       #b8862f;
  --border-default:#b0a890;
  --border-focus:  #b8862f;
  --btn-bg:         rgba(58, 56, 48, 0.08);
  --btn-bg-hover:   rgba(58, 56, 48, 0.16);
  --input-bg:       rgba(58, 56, 48, 0.06);
  --border-subtle:  var(--border-default);
  --spinner-track:  rgba(58, 56, 48, 0.15);
  --spinner-head:   rgba(58, 56, 48, 0.70);
  --card-bg:        rgba(58, 56, 48, 0.04);
}

/* ── Reset ──────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--body-font);
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: unset;
  font-smooth: never;
  image-rendering: pixelated;
  background-color: var(--bg-base);
  color: var(--off-white);
  overflow: hidden;
  transition: background-color 0.15s, color 0.15s;
}

button { font-family: var(--body-font); }
select { font-family: var(--body-font); }
input  { font-family: var(--body-font); }

/* ── Layout shell ───────────────────────────────────────────────────────── */
.main-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

.main-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.hidden { display: none !important; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.header, .header * { cursor: default; }

.header {
  font-family: var(--body-font);
  color: var(--off-white);
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-subtle);
}

.header-left { display: flex; align-items: center; }
.header img#logo { height: 32px; }
.header-right { display: flex; align-items: center; gap: 10px; }

.header-theme-btn {
  background: none;
  border: 1px solid var(--border-subtle);
  color: var(--off-white);
  cursor: pointer;
  opacity: 0.7;
  line-height: 1;
  padding: 5px 8px;
  border-radius: 0;
  transition: opacity 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-theme-btn:hover { opacity: 1; background: var(--btn-bg); }

.conn-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  opacity: 0.75;
  letter-spacing: 0.03em;
  color: var(--off-white);
}

.conn-dot {
  width: 7px; height: 7px;
  border-radius: 0;
  display: inline-block;
  flex-shrink: 0;
}
.conn-dot--ok   { background: var(--success); box-shadow: 0 0 5px rgba(169,182,101,0.5); }
.conn-dot--idle { background: var(--accent);  box-shadow: 0 0 5px rgba(216,166,87,0.5); }
.conn-dot--off  { background: var(--error);   box-shadow: 0 0 5px rgba(234,105,98,0.5); }

.conn-label { text-transform: uppercase; font-size: 0.65rem; opacity: 0.8; }
.conn-sep   { opacity: 0.4; margin: 0 2px; }

.conn-state {
  text-transform: uppercase;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  padding: 1px 6px;
  border-radius: 0;
}
.conn-state--idle       { color: var(--off-white); opacity: 0.5; }
.conn-state--ready      { color: var(--success); }
.conn-state--waiting    { color: var(--accent); }
.conn-state--in-session { color: var(--success); background: rgba(169,182,101,0.12); }

/* ── Toast ──────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(234,105,98,0.92);
  border: 1px solid rgba(234,105,98,0.4);
  border-radius: 0;
  color: var(--text-primary);
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
  opacity: 0;
  pointer-events: none;
}
.toast--visible { transform: translateX(-50%) translateY(0); opacity: 1; pointer-events: auto; }
.toast--hidden  { transform: translateX(-50%) translateY(-100px); opacity: 0; pointer-events: none; }
.toast-message { flex: 1; }
.toast-dismiss { font-size: 1.2rem; opacity: 0.7; transition: opacity 0.15s; }
.toast-dismiss:hover { opacity: 1; }

/* ── Lobby ──────────────────────────────────────────────────────────────── */
.lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100%;
  width: 100%;
  padding: 24px;
  max-width: 480px;
  margin: 0 auto;
}

.lobby-preview {
  position: relative;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--bg-base);
  border: 1px solid var(--border-subtle);
}
.lobby-preview-canvas {
  width: 100%; height: 100%;
  display: block;
  background: #1a1810;
}
.lobby-preview-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--off-white);
  opacity: 0.15;
}
.lobby-preview .noise-canvas-wrapper { position: absolute; inset: 0; }

.lobby-title {
  font-size: 1.4rem;
  font-weight: 400;
  color: var(--off-white);
  margin: 0;
  letter-spacing: 0.04em;
  opacity: 0.9;
}

.lobby-form { display: flex; align-items: center; gap: 8px; width: 100%; }

.lobby-label {
  font-size: 0.8rem;
  color: var(--off-white);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.6;
  min-width: 50px;
  flex-shrink: 0;
}

.lobby-server-inputs { display: flex; align-items: center; gap: 4px; flex: 1; }

.lobby-input {
  height: 36px;
  background: var(--input-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 0;
  color: var(--off-white);
  font-size: 0.85rem;
  padding: 0 10px;
  outline: none;
  transition: border-color 0.15s;
}
.lobby-input:focus    { border-color: var(--border-focus); }
.lobby-input:disabled { opacity: 0.4; }
.lobby-input--host { flex: 1; }
.lobby-input--port { width: 72px; }
.lobby-input--room { flex: 1; text-transform: uppercase; }

.lobby-colon { color: var(--off-white); opacity: 0.4; font-size: 1rem; }
.lobby-divider { width: 60%; height: 1px; background: var(--border-subtle); }

.lobby-btn {
  height: 36px;
  padding: 0 16px;
  font-size: 0.85rem;
  border-radius: 0;
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  background: var(--btn-bg);
  color: var(--off-white);
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.lobby-btn:hover:not(:disabled) { background: var(--btn-bg-hover); }
.lobby-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.lobby-connect-btn--connecting { opacity: 0.5; cursor: default; }
.lobby-connect-btn--connected {
  background: rgba(169,182,101,0.25);
  color: var(--success);
  border-color: rgba(169,182,101,0.3);
  cursor: default;
}

.lobby-start-btn {
  width: 100%;
  height: 42px;
  font-size: 0.9rem;
  justify-content: center;
  background: rgba(216,166,87,0.15);
  border-color: rgba(216,166,87,0.3);
  color: var(--accent);
}
.lobby-start-btn:hover:not(:disabled) { background: rgba(216,166,87,0.25); }

.lobby-error { color: var(--bad); font-size: 0.8rem; text-align: center; }

.lobby-waiting {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--accent);
}

.lobby-waiting-spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 1px solid rgba(216,166,87,0.3);
  border-top-color: var(--accent);
  border-radius: 0;
  animation: spin 0.8s linear infinite;
}

.lobby-user-id { opacity: 0.7; font-size: 0.8rem; color: var(--off-white); }

.lobby-media { display: flex; gap: 12px; margin-top: 4px; }

.lobby-media-btn {
  width: 44px; height: 44px;
  border-radius: 0;
  border: 1px solid var(--border-subtle);
  background: var(--btn-bg);
  color: var(--off-white);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
}
.lobby-media-btn:hover { background: var(--btn-bg-hover); }
.lobby-media-btn--off {
  background: rgba(234,105,98,0.15);
  border-color: rgba(234,105,98,0.35);
  color: var(--error);
}
.lobby-media-btn--off:hover { background: rgba(234,105,98,0.25); }

.lobby-device-row { display: flex; align-items: center; gap: 8px; width: 100%; }

.lobby-select {
  flex: 1;
  height: 36px;
  background: var(--input-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 0;
  color: var(--off-white);
  font-size: 0.85rem;
  padding: 0 10px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a89b84' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}
.lobby-select:focus  { border-color: var(--border-focus); }
.lobby-select option { background: var(--bg-surface); color: var(--off-white); }

/* ── InCall ─────────────────────────────────────────────────────────────── */
.incall {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: var(--bg-base);
}

.incall-video-area {
  flex: 1;
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #1a1810;
}

.incall-peer-canvas {
  width: 100%; height: 100%;
  display: block;
  object-fit: contain;
  position: relative;
  z-index: 2;
}
.incall-peer-noise { position: absolute; inset: 0; z-index: 1; }

.incall-pip {
  position: absolute;
  bottom: 16px; right: 16px;
  width: 180px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border: 1px solid var(--border-default);
  background: #1a1810;
  z-index: 10;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}
.incall-pip-canvas { width: 100%; height: 100%; display: block; }
.incall-pip-off {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  color: var(--text-muted);
}

.incall-info {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  padding: 6px 16px;
  background: var(--card-bg);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.incall-room { font-size: 0.8rem; color: var(--text-muted); letter-spacing: 0.05em; }
.incall-room strong { color: var(--text-primary); letter-spacing: 0.08em; }
.incall-timer { font-size: 0.8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

.incall-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 24px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
  position: relative;
}
.incall-toolbar-center { display: flex; align-items: center; gap: 8px; }

.incall-tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 16px;
  background: var(--btn-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 0;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
}
.incall-tool-btn:hover { background: var(--btn-bg-hover); }
.incall-tool-btn--off {
  background: rgba(234,105,98,0.15);
  color: var(--error);
  border-color: rgba(234,105,98,0.3);
}
.incall-tool-btn--off:hover { background: rgba(234,105,98,0.25); }

.incall-tool-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.incall-leave-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 20px;
  background: rgba(234,105,98,0.7);
  border: 1px solid rgba(234,105,98,0.5);
  border-radius: 0;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s;
  position: absolute;
  right: 24px;
}
.incall-leave-btn:hover { background: rgba(234,105,98,0.9); }

/* ── Noise canvas ───────────────────────────────────────────────────────── */
.noise-canvas-wrapper {
  position: relative;
  width: 100%; height: 100%;
  background-color: #1a1810;
  display: flex;
  align-items: center;
  justify-content: center;
}
.noise-canvas {
  width: 100%; height: 100%;
  object-fit: cover;
  image-rendering: pixelated;
  opacity: 0.75;
}
.noise-label {
  position: absolute;
  color: var(--text-primary);
  font-size: clamp(10px, 2vw, 18px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  pointer-events: none;
  text-shadow: 0 0 8px rgba(0,0,0,0.9);
  background: rgba(0,0,0,0.35);
  padding: 4px 10px;
}

/* ── Status popup ───────────────────────────────────────────────────────── */
.status-popup {
  position: fixed;
  z-index: 1000;
  transform: translate(-50%,-50%);
  top: 50%; left: 50%;
  padding: 7px;
  background-color: var(--bad);
  border: 1px solid var(--border-default);
  font-size: min(7vh,4vw);
  color: var(--bg-base);
  text-align: center;
}

/* ── Light theme overrides ──────────────────────────────────────────────── */
[data-theme="light"] .incall-video-area { background: var(--bg-overlay); }
[data-theme="light"] .incall-pip { border-color: var(--border-default); }
[data-theme="light"] .incall-pip-off { background: var(--bg-surface); color: var(--text-muted); }
[data-theme="light"] .incall-tool-btn--off { background: rgba(198,40,40,0.12); color: var(--error); }

/* ── Shared keyframes ───────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
