:root {
  color-scheme: light dark;
  --bg: #fff;
  --text: #222;
  --muted: #696969;
  --line: #e7e7e7;
  --control-line: #d4d4d4;
  --hover: #f3f3f3;
  --primary: #222;
  --on-primary: #fff;
  --focus: #737373;
  --danger: #a13935;
  --screen-bg: #181818;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Microsoft YaHei UI', sans-serif;
  font-synthesis: none;
  background: var(--bg);
  color: var(--text);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #212121;
    --text: #eee;
    --muted: #b4b4b4;
    --line: #3b3b3b;
    --control-line: #626262;
    --hover: #2f2f2f;
    --primary: #eee;
    --on-primary: #212121;
    --focus: #b7b7b7;
    --danger: #ffb1a9;
  }
}

* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
body {
  margin: 0;
}
h1,
p {
  margin: 0;
}
button,
input {
  font: inherit;
}
button {
  min-height: 44px;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  padding: 0 14px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
}
button:disabled {
  opacity: 0.55;
  cursor: default;
}
button:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}
@media (hover: hover) {
  button:not(:disabled):hover {
    background: var(--hover);
  }
}
.primary,
.primary:not(:disabled):hover {
  color: var(--on-primary);
  background: var(--primary);
  border-color: var(--primary);
}
.quiet {
  border-color: transparent;
}
input {
  min-width: 0;
  width: 100%;
  min-height: 46px;
  padding: 8px 11px;
  border: 1px solid var(--control-line);
  border-radius: 8px;
  color: var(--text);
  background: var(--bg);
}

.entry {
  width: min(calc(100% - 40px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)), 350px);
  margin: clamp(72px, 17vh, 158px) auto 40px;
  margin: clamp(72px, 17svh, 158px) auto 40px;
}
.wordmark {
  font-size: 0.8rem;
  font-weight: 750;
  letter-spacing: 0.075em;
}
.entry-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.language-toggle {
  min-height: 32px;
  padding: 0 9px;
  border-color: transparent;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.04em;
}
.entry h1 {
  margin: 18px 0 24px;
  font-size: 1.75rem;
  line-height: 1.3;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}
.entry form {
  display: grid;
  gap: 8px;
}
.entry label,
.unlock-form label {
  font-size: 0.875rem;
  font-weight: 600;
}
.entry button {
  margin-top: 8px;
}
.entry p {
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.5;
}
.trust-note {
  margin-top: 14px;
  font-size: 0.78rem !important;
}
.site-links {
  width: min(calc(100% - 36px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)), 780px);
  margin: 0 auto;
  padding: 0 0 max(22px, env(safe-area-inset-bottom));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  color: var(--muted);
  font-size: 0.75rem;
}
.site-links .wordmark {
  margin-right: auto;
  font-size: 0.72rem;
}
.site-links a {
  color: var(--muted);
  text-decoration: none;
}
.site-links a:hover {
  color: var(--text);
  text-decoration: underline;
}
body:has(#viewer:not([hidden])) .site-links {
  display: none;
}
.entry .error {
  color: var(--danger);
}

.viewer {
  width: min(calc(100% - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)), 900px);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 0
    calc(max(10px, env(safe-area-inset-bottom)) + var(--keyboard-room, 0px));
  display: flex;
  flex-direction: column;
}
.viewer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.viewer-identity {
  flex: 1;
  min-width: 0;
}
.viewer-head h1 {
  min-width: 0;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.025em;
  overflow-wrap: anywhere;
}
.viewer-actions {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 0;
  flex-shrink: 0;
}
.viewer-menu {
  position: relative;
  margin: 0;
  border: 0;
}
.viewer-menu > summary {
  min-height: 44px;
  padding: 0;
  list-style: none;
  color: var(--text);
  border-radius: 8px;
}
.viewer-menu > summary::-webkit-details-marker {
  display: none;
}
.viewer-menu[open] > summary {
  background: var(--hover);
}
.viewer-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 8;
  width: min(240px, calc(100vw - 32px));
  max-height: 60dvh;
  overflow: auto;
  padding: 8px;
  border-radius: 12px;
  background: var(--bg);
  box-shadow: 0 12px 36px #0000001f;
}
@media (prefers-color-scheme: dark) {
  .viewer-menu-panel {
    box-shadow: 0 12px 36px #00000055;
  }
}
.menu-action {
  display: block;
  width: 100%;
  border-color: transparent;
  text-align: left;
  font-weight: 400;
}
.menu-note {
  padding: 8px 14px;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--muted);
}
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  padding: 0;
  border-color: transparent;
}
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#fullscreen .collapse-icon,
#fullscreen[aria-pressed='true'] .expand-icon {
  display: none;
}
#fullscreen[aria-pressed='true'] .collapse-icon {
  display: block;
}
#connection {
  margin-top: 2px;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--muted);
  overflow-wrap: anywhere;
}
#connection[data-error='true'] {
  color: var(--danger);
}
.session-meta {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  margin: 0;
  padding: 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  text-align: right;
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--muted);
  pointer-events: none;
}
#expiry {
  flex-shrink: 0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.mirror-unit {
  --screen-ratio: 0.4615;
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  display: grid;
  place-items: center;
}
.phone-frame {
  position: relative;
  width: var(--stage-width, 100%);
  max-width: 100%;
  min-width: 0;
}
.stage {
  position: relative;
  display: grid;
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  place-items: center;
  isolation: isolate;
  width: 100%;
  aspect-ratio: var(--screen-ratio);
  overflow: hidden;
  border-radius: 10px;
  background: var(--screen-bg);
}
.mirror-unit:has(.toolbar:not([hidden])) .stage {
  border-radius: 10px 10px 0 0;
}
#screen {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
  touch-action: none;
  user-select: none;
}
.video-placeholder {
  position: absolute;
  inset: 0;
  background: var(--screen-bg);
}
.stage-actions {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  pointer-events: none;
}
.stage-actions button {
  color: #eee;
  background: #2f2f2f;
  border-color: #626262;
  pointer-events: auto;
}
.stage-actions button:not(:disabled):hover {
  background: #393939;
}
.toolbar {
  background: var(--hover);
  border-radius: 0 0 10px 10px;
}
.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.controls .icon-button {
  width: 100%;
  background: transparent;
  outline-offset: -3px;
}
@media (hover: hover) {
  .controls .icon-button:hover {
    background: var(--bg);
  }
}
.unlock-dialog {
  width: min(360px, 100% - 32px);
  max-height: calc(100% - 32px);
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--control-line);
  border-radius: 18px;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: contain;
}
.unlock-dialog::backdrop {
  background: #00000044;
}
.unlock-form {
  display: grid;
  gap: 8px;
  padding: 18px;
}
.unlock-form h2 {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 650;
}
.unlock-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}
.unlock-form p,
#network-help {
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--muted);
}
#unlock-feedback:not(:empty) {
  margin-top: 6px;
}
#unlock-feedback[data-error='true'] {
  color: var(--danger);
}
.form-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ownership {
  display: flex;
  align-items: center;
  margin-right: 4px;
}
.ownership button {
  padding-inline: 12px;
}
.form-row input {
  flex: 1;
}
.viewer-side {
  display: contents;
}
.viewer-note,
.viewer-help {
  display: none;
}
#text-form {
  margin: 0;
  max-width: none;
  padding-top: 8px;
  flex: none;
}
.viewer:has(#text-form:not([hidden])) #toolbar {
  display: none !important;
}

details {
  border-top: 1px solid var(--line);
  margin-top: 8px;
}
summary {
  min-height: 44px;
  padding: 13px 0;
  font-size: 0.8125rem;
  color: var(--muted);
  cursor: pointer;
}
dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 18px;
  margin: 4px 0 12px;
  font-size: 0.8125rem;
}
dd {
  margin: 0;
  overflow-wrap: anywhere;
}
dt {
  color: var(--muted);
}

body.viewer-expanded {
  overflow: hidden;
}
.viewer:is(.expanded, :fullscreen) {
  display: flex;
  flex-direction: column;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right))
    calc(max(6px, env(safe-area-inset-bottom)) + var(--keyboard-room, 0px))
    max(10px, env(safe-area-inset-left));
  background: var(--bg);
  overflow: hidden;
  overscroll-behavior: contain;
}
.viewer.expanded {
  position: fixed;
  z-index: 1;
}
.viewer:is(.expanded, :fullscreen) > * {
  flex: none;
}
.viewer:is(.expanded, :fullscreen) .mirror-unit {
  flex: 1 1 0;
}
.viewer:is(.expanded, :fullscreen) .viewer-note,
.viewer:is(.expanded, :fullscreen) .viewer-help {
  display: none;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (max-width: 360px) {
  .viewer {
    width: calc(100% - 24px);
  }
  .viewer.expanded {
    width: 100%;
  }
}

.viewer-side > details {
  display: none;
}
.viewer-side > details[open] {
  display: block;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 7;
  max-height: 62dvh;
  overflow: auto;
  margin: 0;
  padding: 0 max(12px, env(safe-area-inset-left)) max(14px, env(safe-area-inset-bottom))
    max(12px, env(safe-area-inset-right));
  border-top: 1px solid var(--line);
  background: var(--bg);
  overscroll-behavior: contain;
}
.viewer-side > details[open] summary {
  position: sticky;
  top: 0;
  background: var(--bg);
}

@media (min-width: 900px) {
  .viewer:not(.expanded):not(:fullscreen) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    grid-template-rows: auto minmax(0, 1fr);
    column-gap: 20px;
    row-gap: 12px;
  }
  .viewer:not(.expanded):not(:fullscreen) .viewer-head {
    grid-column: 1 / -1;
  }
  .viewer:not(.expanded):not(:fullscreen) .mirror-unit {
    grid-column: 1;
    grid-row: 2;
  }
  .viewer:not(.expanded):not(:fullscreen) .viewer-side {
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
    overflow: auto;
    grid-column: 2;
    grid-row: 2;
  }
  .viewer:not(.expanded):not(:fullscreen) #text-form {
    grid-column: 1;
    grid-row: 3;
    padding-top: 0;
  }
  .viewer:not(.expanded):not(:fullscreen) .viewer-side > details {
    display: block;
    position: static;
    max-height: none;
    padding: 0;
    border-top: 1px solid var(--line);
  }
  .viewer:not(.expanded):not(:fullscreen) .viewer-side > details summary {
    position: static;
  }
  .viewer-note {
    display: block;
    margin: 0;
    color: var(--muted);
    font-size: 0.8125rem;
    line-height: 1.5;
  }
  .viewer-help {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    margin: 0;
    font-size: 0.8125rem;
  }
  .viewer-help a {
    color: var(--muted);
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .entry {
    margin-top: 24px;
  }
  .viewer {
    padding-top: max(4px, env(safe-area-inset-top));
    padding-bottom: calc(max(4px, env(safe-area-inset-bottom)) + var(--keyboard-room, 0px));
  }
  .phone-frame .session-meta {
    display: none;
  }
  .viewer-head {
    margin-bottom: 4px;
  }
}
