:root {
  color-scheme: light;
  --bg: #f7f1eb;
  --ink: #241d1a;
  --muted: #756963;
  --panel: #fffaf5;
  --line: #ded2c7;
  --accent: #2d6a6a;
  --accent-strong: #184f4f;
  --rose: #b85d68;
  --gold: #c99a42;
  --leaf: #4f8064;
  --petal: #d9a7aa;
  --shadow: 0 18px 50px rgba(49, 38, 31, 0.13);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}
button, input, select { font: inherit; }
button {
  min-height: 44px;
  border: 0;
  border-radius: 7px;
  padding: 0 18px;
  background: var(--accent);
  color: white;
  font-weight: 750;
  cursor: pointer;
}
button:hover { background: var(--accent-strong); }
button:disabled,
button:disabled:hover {
  border: 1px solid #d8d0c8;
  background: #e8e1da;
  color: #9a8f86;
  cursor: not-allowed;
  opacity: 1;
  box-shadow: none;
}
button.ghost { border: 1px solid var(--line); background: transparent; color: var(--ink); }
button.ghost:hover { background: rgba(45, 106, 106, 0.08); }
button.danger { background: var(--rose); }
input, select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  background: white;
  color: var(--ink);
}
label { display: grid; gap: 7px; color: var(--muted); font-size: 0.92rem; font-weight: 700; }
.hidden { display: none !important; }
.broadcaster-portal #usernameField,
.broadcaster-portal #roleField {
  display: none !important;
}
.app { min-height: 100vh; }

.wedding-motif {
  display: none;
  pointer-events: none;
}

.login-shell {
  position: relative;
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(310px, 430px);
  gap: clamp(28px, 6vw, 80px);
  align-items: center;
  padding: clamp(22px, 6vw, 80px);
  background:
    linear-gradient(rgba(36, 29, 26, 0.62), rgba(36, 29, 26, 0.32)),
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.2), transparent 30%),
    linear-gradient(135deg, #7b6154, #d5b7a1 42%, #2d6a6a);
  overflow: hidden;
}
.brand { color: white; max-width: 680px; text-shadow: 0 2px 18px rgba(0, 0, 0, 0.35); }
.brand p, .eyebrow { margin: 0 0 10px; text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.78rem; font-weight: 800; }
.brand h1 { margin: 0; font-size: clamp(2.7rem, 8vw, 6.5rem); line-height: 0.96; letter-spacing: 0; max-width: 760px; }
.invite-names,
.invite-subline {
  display: block;
}
.login-panel {
  display: grid;
  gap: 18px;
  padding: 24px;
  border: 1px solid rgba(255, 255, 255, 0.32);
  border-radius: 8px;
  background: rgba(255, 250, 245, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.error { min-height: 1.2em; margin: 0; color: #9d2330; font-weight: 700; }

.stream-shell { min-height: 100vh; padding: clamp(14px, 3vw, 28px); }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 0 auto 18px;
  max-width: min(1880px, calc(100vw - 48px));
}
.topbar h1 { margin: 0; font-size: clamp(1.45rem, 3vw, 2.4rem); }
.top-actions { display: flex; align-items: center; gap: 12px; }
.viewer-count {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: var(--panel);
  font-weight: 800;
  white-space: nowrap;
}
.content-grid {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(390px, 520px);
  gap: 24px;
  max-width: min(1880px, calc(100vw - 48px));
  margin: 0 auto;
  align-items: start;
  justify-content: center;
}
.stage, .chat-panel, .broadcaster-panel, .controls {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.stage {
  overflow: hidden;
  width: min(100%, calc((100vh - 235px) * 1.7778 + 28px));
  min-width: min(760px, 100%);
}
.video-frame {
  position: relative;
  aspect-ratio: var(--video-aspect, 16 / 9);
  height: min(clamp(280px, calc((100vw - 640px) * 0.5625), 860px), calc(100vh - 235px));
  min-height: 280px;
  max-width: 100%;
  background: #191514;
  overflow: hidden;
}
.video-frame.video-frame-portrait {
  height: min(calc(100vh - 235px), 860px);
  width: min(100%, calc((100vh - 235px) * 0.5625));
  min-width: min(420px, 100%);
  margin-inline: auto;
}
.viewer-video, .placeholder { width: 100%; height: 100%; object-fit: contain; background: #111; }
.viewer-video.video-rotate-90,
.viewer-video.video-rotate-270 {
  position: static;
  width: 100%;
  height: 100%;
  transform: none;
}

.local-preview {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: min(260px, 34%);
  aspect-ratio: 16 / 9;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 7px;
  object-fit: cover;
  background: #111;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.3);
}

.local-preview.video-rotate-90 {
  transform: none;
}

.local-preview.video-rotate-270 {
  transform: none;
}

.empty-state { position: absolute; inset: 0; display: grid; place-content: center; gap: 8px; padding: 26px; text-align: center; color: #fff5ed; }
.empty-state h2 { margin: 0; font-size: clamp(1.5rem, 4vw, 3rem); }
.empty-state p { margin: 0; color: rgba(255, 245, 237, 0.78); }
.live-badge {
  position: absolute;
  top: 14px;
  left: 14px;
  border-radius: 7px;
  padding: 8px 12px;
  background: #d92336;
  color: white;
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.pause-notice {
  position: absolute;
  left: 50%;
  bottom: clamp(18px, 4vw, 34px);
  transform: translateX(-50%);
  width: min(420px, calc(100% - 36px));
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 8px;
  padding: 14px 16px;
  background: rgba(38, 31, 26, 0.72);
  color: #fff7ee;
  text-align: center;
  backdrop-filter: blur(10px);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.22);
}
.pause-notice strong {
  display: block;
  margin-bottom: 4px;
  font-size: 1rem;
}
.pause-notice span {
  display: block;
  color: rgba(255, 247, 238, 0.82);
  font-size: 0.92rem;
}
.controls, .broadcaster-panel { margin: 14px; padding: 14px; }
.controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
#viewerControls {
  display: grid;
  grid-template-columns: auto minmax(220px, 1fr) minmax(190px, 250px) auto;
  align-items: end;
}
.range-label { flex: 1; min-width: 210px; }
.quality-label {
  min-width: 190px;
}
.video-frame:fullscreen {
  width: 100vw;
  height: 100vh;
  max-height: none;
  min-height: 0;
  aspect-ratio: auto;
  background: #111;
}
.video-frame:fullscreen .viewer-video,
.video-frame:fullscreen .placeholder {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.control-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.control-row:last-child { grid-template-columns: minmax(0, 1fr) auto auto auto; align-items: end; margin-bottom: 0; }
.file-picker input { padding: 9px; }
.orientation-status {
  margin: -2px 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}
.orientation-status.status-error {
  border-color: rgba(157, 35, 48, 0.35);
  background: rgba(157, 35, 48, 0.08);
  color: #9d2330;
}

.chat-panel {
  min-height: min(860px, calc(100vh - 118px));
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto;
  overflow: hidden;
}
.chat-head { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.chat-head h2 { margin: 0; font-size: 1.15rem; }
.chat-messages { overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.message { border: 1px solid var(--line); border-radius: 8px; padding: 10px 11px; background: white; }
.message strong { display: block; margin-bottom: 3px; color: var(--accent-strong); font-size: 0.9rem; }
.message p { margin: 0; overflow-wrap: anywhere; line-height: 1.42; }
.chat-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; padding: 12px; border-top: 1px solid var(--line); }

.viewer-portal {
  --bg: #eee6d8;
  --ink: #332820;
  --muted: #817468;
  --panel: rgba(253, 250, 243, 0.94);
  --line: rgba(151, 133, 108, 0.34);
  --accent: #6f5f4e;
  --accent-strong: #4d4034;
  --rose: #9f6d63;
  background:
    linear-gradient(120deg, rgba(238, 230, 216, 0.92), rgba(215, 201, 182, 0.88)),
    repeating-linear-gradient(8deg, rgba(72, 55, 40, 0.04) 0 1px, transparent 1px 10px),
    repeating-linear-gradient(92deg, rgba(255, 255, 255, 0.08) 0 1px, transparent 1px 13px);
}

.viewer-portal .wedding-motif {
  display: block;
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

.viewer-portal .login-shell > :not(.wedding-motif),
.viewer-portal .stream-shell > :not(.wedding-motif) {
  position: relative;
  z-index: 1;
}

.viewer-portal .login-shell {
  background:
    radial-gradient(circle at 28% 23%, rgba(253, 250, 243, 0.78), transparent 20%),
    linear-gradient(100deg, rgba(58, 48, 40, 0.2), rgba(255, 255, 255, 0.12)),
    repeating-linear-gradient(4deg, rgba(73, 58, 42, 0.08) 0 1px, transparent 1px 14px),
    linear-gradient(145deg, #c7b9a5 0%, #f4efe5 48%, #d9cbb9 100%);
}

.viewer-portal .brand {
  max-width: 720px;
  color: #3b3028;
  text-align: center;
  text-shadow: none;
}

.viewer-portal .brand p {
  color: #6f5f4e;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(0.78rem, 1.3vw, 0.98rem);
  font-weight: 500;
  letter-spacing: 0.18em;
}

.viewer-portal .brand h1 {
  font-weight: 400;
}

.viewer-portal .invite-names {
  font-family: "Brush Script MT", "Segoe Script", "Snell Roundhand", cursive;
  font-size: clamp(4.1rem, 11vw, 8rem);
  line-height: 0.86;
  color: #332820;
  transform: rotate(-4deg);
}

.viewer-portal .invite-subline {
  margin-top: clamp(20px, 3vw, 34px);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1rem, 2.4vw, 1.55rem);
  font-weight: 400;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #6f5f4e;
}

.viewer-portal .login-panel,
.viewer-portal .stage,
.viewer-portal .chat-panel,
.viewer-portal .controls {
  border-color: rgba(201, 154, 66, 0.34);
  background:
    repeating-linear-gradient(110deg, rgba(104, 84, 61, 0.035) 0 1px, transparent 1px 12px),
    linear-gradient(180deg, rgba(255, 253, 247, 0.96), rgba(247, 240, 229, 0.94));
  box-shadow: 0 24px 70px rgba(58, 42, 34, 0.16);
}

.viewer-portal .login-panel {
  position: relative;
  overflow: hidden;
}

.viewer-portal .login-panel::before {
  content: "";
  position: absolute;
  width: 210px;
  height: 210px;
  top: -76px;
  right: -74px;
  border: 1px solid rgba(74, 64, 54, 0.3);
  border-radius: 50%;
  transform: none;
  opacity: 0.72;
}

.viewer-portal .login-panel::after {
  content: "";
  position: absolute;
  width: 128px;
  height: 96px;
  right: -8px;
  top: -2px;
  background:
    radial-gradient(ellipse at 30% 70%, rgba(239, 234, 219, 0.92) 0 15px, transparent 16px),
    radial-gradient(ellipse at 48% 52%, rgba(232, 225, 209, 0.9) 0 19px, transparent 20px),
    radial-gradient(ellipse at 72% 58%, rgba(241, 237, 224, 0.88) 0 16px, transparent 17px),
    linear-gradient(64deg, transparent 0 43%, rgba(146, 116, 74, 0.58) 44% 47%, transparent 48%),
    linear-gradient(110deg, transparent 0 46%, rgba(146, 116, 74, 0.48) 47% 50%, transparent 51%);
  opacity: 0.82;
}

.viewer-portal .stream-shell {
  position: relative;
  background:
    repeating-linear-gradient(7deg, rgba(73, 58, 42, 0.045) 0 1px, transparent 1px 14px),
    linear-gradient(160deg, rgba(250, 246, 238, 0.98), rgba(226, 215, 199, 0.94));
  overflow: hidden;
}

.viewer-portal .topbar {
  border-bottom: 1px solid rgba(201, 154, 66, 0.28);
  padding-bottom: 14px;
}

.viewer-portal .topbar h1 {
  color: #3b3028;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.viewer-portal .eyebrow {
  color: #7a6858;
}

.viewer-portal .video-frame {
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.1), transparent 38%),
    linear-gradient(135deg, #3b3028, #6f5f4e);
}

.viewer-portal .empty-state::before {
  content: "";
  width: 96px;
  height: 62px;
  margin: 0 auto 14px;
  display: block;
  background:
    radial-gradient(circle at 38% 50%, transparent 18px, rgba(175, 145, 94, 0.95) 19px 21px, transparent 22px),
    radial-gradient(circle at 62% 50%, transparent 18px, rgba(175, 145, 94, 0.95) 19px 21px, transparent 22px);
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.2));
}

.viewer-portal .message {
  border-color: rgba(196, 164, 124, 0.36);
  background: rgba(255, 255, 255, 0.74);
}

.viewer-portal .message strong {
  color: #6f5f4e;
}

.viewer-portal button {
  background: linear-gradient(135deg, #7d6b58, #4d4034);
}

.viewer-portal button:hover {
  background: linear-gradient(135deg, #6d5d4c, #3f352c);
}

.viewer-portal button.ghost {
  background: rgba(255, 252, 248, 0.68);
  color: #3b3028;
}

.viewer-portal .ring {
  position: absolute;
  width: clamp(300px, 45vw, 640px);
  aspect-ratio: 1;
  border: 1px solid rgba(54, 45, 38, 0.36);
  border-radius: 50%;
  filter: none;
}

.viewer-portal .ring::after {
  content: none;
}

.viewer-portal .ring-one {
  left: clamp(58px, 15vw, 260px);
  top: clamp(70px, 12vh, 150px);
}

.viewer-portal .ring-two {
  display: none;
}

.viewer-portal .stem {
  position: absolute;
  width: clamp(190px, 25vw, 360px);
  height: clamp(190px, 25vw, 360px);
  border: 0;
  border-radius: 0;
  opacity: 0.72;
  background: url("/assets/floral-corner.svg") center/contain no-repeat;
}

.viewer-portal .stem::before,
.viewer-portal .stem::after {
  content: none;
}

.viewer-portal .stem-left {
  left: clamp(-42px, 3vw, 80px);
  top: clamp(28px, 7vh, 110px);
  transform: rotate(-10deg);
}

.viewer-portal .stem-right {
  right: clamp(-54px, 3vw, 110px);
  bottom: clamp(28px, 8vh, 110px);
  transform: scaleX(-1) rotate(-8deg);
}

.viewer-portal .motif-stream .ring {
  opacity: 0.15;
}

.viewer-portal .motif-stream .ring-one {
  left: auto;
  right: clamp(20px, 8vw, 140px);
  top: 52px;
}

.viewer-portal .motif-stream .ring-two {
  display: none;
}

@media (max-width: 1280px) {
  .topbar,
  .content-grid {
    max-width: min(1420px, calc(100vw - 36px));
  }

  .content-grid {
    grid-template-columns: minmax(0, 1fr) minmax(320px, 430px);
    gap: 18px;
  }

  .stage {
    width: 100%;
    min-width: 0;
  }

  .video-frame {
    height: min(clamp(260px, calc((100vw - 500px) * 0.5625), 760px), calc(100vh - 230px));
    min-height: 260px;
  }

  .chat-panel {
    min-height: min(760px, calc(100vh - 118px));
  }
}

@media (max-width: 940px) {
  .login-shell { grid-template-columns: 1fr; align-content: center; }
  .content-grid { grid-template-columns: 1fr; }
  .stage { width: 100%; min-width: 0; }
  .chat-panel { min-height: 480px; }
}
@media (max-width: 640px) {
  .stream-shell { padding: 10px; }
  .topbar, .top-actions { display: grid; width: 100%; align-items: stretch; }
  .controls { align-items: stretch; flex-direction: column; }
  #viewerControls { grid-template-columns: 1fr; }
  .chat-form { grid-template-columns: 1fr; }
  .video-frame {
    height: auto;
    min-height: 190px;
    max-height: 70vh;
    aspect-ratio: var(--video-aspect, 16 / 9);
  }
  .video-frame.video-frame-portrait {
    width: min(100%, calc(70vh * 0.5625));
    min-width: 0;
  }
  .viewer-video.video-rotate-90,
  .viewer-video.video-rotate-270 {
    width: 100%;
    height: 100%;
  }
  .control-row, .control-row:last-child { grid-template-columns: 1fr; }
  .local-preview { width: 42%; }
  .viewer-portal .ring-one { right: -40px; top: 20px; }
  .viewer-portal .ring-two { right: 36px; top: 92px; }
  .viewer-portal .stem { opacity: 0.68; }
}
