* { box-sizing: border-box; margin: 0; padding: 0; }

/* ============================================================
   Темы Veda Call — по макетам:
   light — «Уютный сад»: кремовая телефонная будка, зелень, тепло
   dark  — «Ночной автомат»: ночь, латунь, золото, заклёпки
   ============================================================ */

:root, :root[data-theme="light"] {
  --bg: #ece5d3;
  --bg-image:
    radial-gradient(ellipse 90% 60% at 50% -10%, rgba(255, 250, 235, .9), transparent 60%),
    radial-gradient(ellipse 70% 50% at 15% 100%, rgba(178, 190, 150, .25), transparent 60%),
    radial-gradient(ellipse 70% 50% at 85% 100%, rgba(224, 129, 99, .12), transparent 60%),
    linear-gradient(180deg, #f0ead9 0%, #e9e1cc 55%, #e2d8bf 100%);
  --card: #faf7ee;
  --card-border: #d9cfb4;
  --card-shadow: 0 24px 70px rgba(110, 98, 70, .28), inset 0 0 0 1px rgba(255,255,255,.6);
  --plaque-bg: linear-gradient(180deg, #f6f1e2, #e7dfc8);
  --plaque-border: #c9bd9c;
  --plaque-text: #5a6b4a;
  --heading: #5a6b4a;
  --text: #4a4636;
  --muted: #8a8574;
  --accent: #96a577;
  --accent-hover: #a3b284;
  --accent-text: #ffffff;
  --secondary: #eae3d1;
  --secondary-hover: #e0d7c0;
  --secondary-text: #5a6b4a;
  --danger: #e08163;
  --danger-hover: #ea937b;
  --input-bg: #f3eee1;
  --input-border: #d9cfb6;
  --tile-bg: #e5ddc9;
  --tile-frame: #d3c7a6;
  --tile-glow: 0 10px 30px rgba(110, 98, 70, .22);
  --ring: #b6c295;
  --ring-glow: 0 0 0 4px rgba(150, 165, 119, .25);
  --avatar-bg: #dfd7c2;
  --avatar-text: #7a8a5f;
  --label-bg: rgba(90, 80, 55, .72);
  --label-text: #f6f1e5;
  --ctrl-bg: #faf7ef;
  --ctrl-border: #d9cfb4;
  --ctrl-text: #5a6b4a;
  --ctrl-hover: #eee7d5;
  --ctrl-label: #8a8574;
  --toast-bg: rgba(74, 70, 54, .92);
  --toast-text: #f6f1e5;
  --ornament: "❦";
  --booth-img: url('/static/img/booth-light.jpg');
}

:root[data-theme="dark"] {
  --bg: #0b0f16;
  --bg-image:
    radial-gradient(ellipse 80% 55% at 50% -15%, rgba(212, 175, 106, .16), transparent 60%),
    radial-gradient(ellipse 60% 45% at 12% 108%, rgba(64, 96, 128, .18), transparent 65%),
    radial-gradient(ellipse 120% 90% at 50% 50%, transparent 55%, rgba(0, 0, 0, .5) 100%),
    linear-gradient(180deg, #101722 0%, #0b0f16 60%, #080b10 100%);
  --card: #151b26;
  --card-border: #3d3626;
  --card-shadow: 0 24px 80px rgba(0, 0, 0, .65), inset 0 0 0 1px rgba(212, 175, 106, .08);
  --plaque-bg: linear-gradient(180deg, #453a22 0%, #2b2314 55%, #1e180d 100%);
  --plaque-border: #6b5a33;
  --plaque-text: #ecd18f;
  --heading: #d4af6a;
  --text: #e8e2d4;
  --muted: #8e97a8;
  --accent: #b08d4f;
  --accent-hover: #c29d5c;
  --accent-text: #14100a;
  --secondary: #232b38;
  --secondary-hover: #2c3646;
  --secondary-text: #d8d2c2;
  --danger: #b4494e;
  --danger-hover: #c85a5f;
  --input-bg: #10151d;
  --input-border: #33404f;
  --tile-bg: #10151d;
  --tile-frame: #4a3f26;
  --tile-glow: 0 10px 36px rgba(0, 0, 0, .6), 0 0 24px rgba(212, 175, 106, .08);
  --ring: #d4af6a;
  --ring-glow: 0 0 18px rgba(212, 175, 106, .35);
  --avatar-bg: #1d2530;
  --avatar-text: #d4af6a;
  --label-bg: rgba(8, 10, 14, .78);
  --label-text: #e8e2d4;
  --ctrl-bg: #1c232e;
  --ctrl-border: #3d3626;
  --ctrl-text: #d4af6a;
  --ctrl-hover: #273040;
  --ctrl-label: #8e97a8;
  --toast-bg: rgba(23, 29, 38, .95);
  --toast-text: #e8e2d4;
  --ornament: "✦";
  --booth-img: url('/static/img/booth-dark.jpg');
}

html, body { height: 100%; }

body {
  background-color: var(--bg);
  background-image: var(--bg-image);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  transition: background-color .3s, color .3s;
}

.hidden { display: none !important; }

/* ---------- Латунная табличка VEDA CALL ---------- */

.plaque {
  display: inline-block;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: .35em;
  text-indent: .35em;
  text-transform: uppercase;
  color: var(--plaque-text);
  background: var(--plaque-bg);
  border: 1px solid var(--plaque-border);
  border-radius: 10px;
  padding: 10px 22px;
  position: relative;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, .25),
    inset 0 -2px 6px rgba(0, 0, 0, .25),
    0 4px 14px rgba(0, 0, 0, .25);
  text-shadow: 0 1px 1px rgba(0, 0, 0, .45), 0 0 10px rgba(236, 209, 143, .25);
}

/* заклёпки по углам таблички */
.plaque::before, .plaque::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 7px;
  height: 7px;
  margin-top: -3.5px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff8e0, var(--plaque-border) 55%, #00000055);
  box-shadow: inset 0 -1px 2px rgba(0,0,0,.5);
}
.plaque::before { left: 7px; }
.plaque::after { right: 7px; }

:root[data-theme="light"] .plaque {
  text-shadow: 0 1px 0 rgba(255,255,255,.7);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.8), inset 0 -2px 5px rgba(140,125,90,.2), 0 4px 12px rgba(110,98,70,.18);
}

/* ---------- Переключатель темы ---------- */

.theme-toggle {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 20;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--ctrl-border);
  background: var(--ctrl-bg);
  color: var(--heading);
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  transition: transform .15s, background .3s;
}
.theme-toggle:hover { transform: scale(1.08); }

/* ---------- Главная и экран входа ---------- */

.home, .join-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.home-layout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  flex-wrap: wrap;
}

/* будка из макета — арочная рама, картинка меняется вместе с темой */
.booth {
  width: min(280px, 72vw);
  aspect-ratio: 423 / 664;
  border-radius: 150px 150px 26px 26px;
  border: 4px solid var(--tile-frame);
  box-shadow: var(--tile-glow), inset 0 0 0 2px rgba(255, 255, 255, .12);
  background-image: var(--booth-img);
  background-size: cover;
  background-position: center;
  transition: border-color .3s;
}

@media (max-width: 760px) {
  .home-layout { gap: 22px; }
  .booth { width: min(200px, 60vw); }
}

.home-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 26px;
  padding: 34px 38px 40px;
  max-width: 460px;
  width: 100%;
  text-align: center;
  box-shadow: var(--card-shadow);
  transition: background .3s, border-color .3s;
}

.home-card .plaque { font-size: 15px; margin-bottom: 24px; }

/* портрет-медальон, как в макетах — круг с золотым кольцом */
.portrait {
  width: 130px;
  height: 130px;
  margin: 0 auto 20px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,.25), transparent 55%),
    var(--avatar-bg);
  border: 3px solid var(--ring);
  box-shadow: var(--ring-glow), inset 0 0 24px rgba(0,0,0,.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
  user-select: none;
}

h1 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 600;
  font-size: 32px;
  letter-spacing: .5px;
  color: var(--heading);
  margin-bottom: 10px;
}

.subtitle { color: var(--muted); line-height: 1.55; margin-bottom: 26px; }

.subtitle::after {
  content: var(--ornament);
  display: block;
  margin-top: 12px;
  color: var(--heading);
  opacity: .55;
  font-size: 16px;
}

.hint { color: var(--muted); font-size: 13px; margin-top: 18px; line-height: 1.5; }

.btn {
  border: none;
  border-radius: 14px;
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  transition: background .15s, transform .05s;
}
.btn:active { transform: scale(.97); }

.btn-big { width: 100%; padding: 15px 20px; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.25), 0 4px 14px rgba(0,0,0,.15);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary { background: var(--secondary); color: var(--secondary-text); }
.btn-secondary:hover { background: var(--secondary-hover); }

.btn-ghost {
  background: none;
  color: var(--muted);
  font-size: 14px;
  padding: 10px;
  margin-top: 14px;
}
.btn-ghost:hover { color: var(--heading); }

.home-link {
  display: inline-block;
  text-decoration: none;
  margin-top: 4px;
}

.name-input {
  width: 100%;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  margin-bottom: 16px;
  outline: none;
  text-align: center;
  transition: border-color .15s, background .3s;
}
.name-input::placeholder { color: var(--muted); }
.name-input:focus { border-color: var(--accent); }

.join-buttons { display: flex; flex-direction: column; gap: 10px; }

.error { color: var(--danger); margin-top: 16px; font-size: 14px; line-height: 1.4; }

/* ---------- Экран звонка ---------- */

.call-screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.call-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 10px 4px;
}

.call-header .plaque { font-size: 13px; }

.timer {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  letter-spacing: .15em;
  color: var(--muted);
}

.grid {
  flex: 1;
  display: grid;
  gap: 14px;
  padding: 14px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  align-content: center;
  overflow: hidden;
}

/* плитка-портал: рамка с латунным кантом, как экран автомата */
.tile {
  position: relative;
  background: var(--tile-bg);
  border: 3px solid var(--tile-frame);
  border-radius: 22px;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  box-shadow: var(--tile-glow), inset 0 0 0 1px rgba(0,0,0,.15);
  transition: background .3s, border-color .3s;
}

.tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  visibility: hidden;
}

.tile.has-video video { visibility: visible; }

.tile.mirror video { transform: scaleX(-1); }

.tile .avatar {
  font-size: clamp(36px, 7vw, 72px);
  width: 1.75em;
  height: 1.75em;
  border-radius: 50%;
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,.18), transparent 55%),
    var(--avatar-bg);
  border: 3px solid var(--ring);
  box-shadow: var(--ring-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  color: var(--avatar-text);
  user-select: none;
  transition: background .3s;
}

.tile.has-video .avatar { display: none; }

.tile .label {
  position: absolute;
  left: 12px;
  bottom: 12px;
  background: var(--label-bg);
  color: var(--label-text);
  padding: 5px 12px;
  border-radius: 10px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 1;
}

.tile .muted-icon { filter: saturate(2); }

.debug-info {
  position: absolute;
  top: 8px;
  left: 8px;
  right: 8px;
  z-index: 2;
  background: rgba(0, 0, 0, .7);
  color: #9fe89f;
  font: 11px/1.5 monospace;
  padding: 4px 8px;
  border-radius: 8px;
  pointer-events: none;
}

/* ---------- Кнопки управления с подписями, как в макете ---------- */

.controls {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 22px;
  padding: 10px 10px calc(16px + env(safe-area-inset-bottom));
}

@media (max-width: 480px) {
  .controls { gap: 8px; }
  .ctrl-wrap { width: 62px; }
  .ctrl { width: 52px; height: 52px; font-size: 20px; }
}

.ctrl-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  width: 72px;
}

.ctrl-wrap > span {
  font-size: 12px;
  color: var(--ctrl-label);
  white-space: nowrap;
}

@media (max-width: 480px) {
  .controls { gap: 8px; }
  .ctrl-wrap { width: 60px; }
  .ctrl-wrap > span { font-size: 10px; }
  .ctrl { width: 52px; height: 52px; font-size: 20px; }
}

.ctrl {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 1px solid var(--ctrl-border);
  background: var(--ctrl-bg);
  color: var(--ctrl-text);
  font-size: 23px;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12), 0 6px 18px rgba(0,0,0,.22);
  transition: background .15s, transform .05s;
}
.ctrl:hover { background: var(--ctrl-hover); }
.ctrl:active { transform: scale(.94); }
.ctrl:disabled { opacity: .45; cursor: default; }
.ctrl.off { background: var(--danger); border-color: transparent; color: #fff; }
.ctrl-danger { background: var(--danger); border-color: transparent; color: #fff; }
.ctrl-danger:hover { background: var(--danger-hover); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 118px;
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: var(--toast-text);
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 14px;
  z-index: 10;
  max-width: min(90vw, 480px);
  text-align: center;
}
