/* Perch — the connect page and the viewer. Colours and buttons come from perch.css. */

/* `hidden` must win over the display rules of .btn, .msg and friends. */
[hidden] { display: none !important; }

body.connect { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
body.connect .app { flex: 1; display: flex; flex-direction: column; }
body.connect main { flex: 1; padding-bottom: 32px; }
body.viewing { overflow: hidden; }

/* Starting up, and the "can't run inside another website" refusal */
.boot { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted); }
.boot p { max-width: 30em; font-size: 1.05rem; }
.boot.refused { color: var(--text); }
.boot.refused p { background: var(--warn-soft); border-radius: 14px; padding: 18px 20px; }

/* Screens */
.screen { padding-top: 8px; }
.screen h1 { font-size: clamp(1.6rem, 4.5vw, 2.1rem); line-height: 1.15; margin: 8px 0 12px; letter-spacing: -.01em; }
.screen h1:focus { outline: none; }
.screen h1:focus-visible { outline: 3px solid var(--accent); outline-offset: 4px; border-radius: 6px; }
.screen .lead { color: var(--muted); font-size: 1.06rem; margin: 0 0 20px; max-width: 36em; }
.screen .lead b { color: var(--text); }
.screen .list { color: var(--muted); }
.fine { color: var(--muted); font-size: .92rem; margin: 8px 0; }
h2.label { font-size: .85rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }

.stack { display: flex; flex-direction: column; gap: 10px; max-width: 420px; margin: 16px 0; }
.btn.big { min-height: 52px; font-size: 1.05rem; width: 100%; }
.btn.small { padding: .4em .8em; font-size: .92rem; }
.btn .icon { flex: none; }
.btn.quiet:hover { background: var(--surface-2); }
.more-links { margin-top: 28px; border-top: 1px solid var(--line); padding-top: 12px; }
.more-links .btn.quiet { padding-left: .4em; padding-right: .6em; }

/* Known Macs */
.macs { list-style: none; padding: 0; margin: 0 0 8px; display: grid; gap: 10px; max-width: 520px; }
.mac { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 6px 4px 4px; }
.mac-go {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 10px;
  border: 0; border-radius: 10px; background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.mac-go:hover { background: var(--surface-2); }
.mac-go .icon:first-child { color: var(--accent); }
.mac-go .icon:last-child { color: var(--muted); margin-left: auto; }
.mac-text { display: flex; flex-direction: column; min-width: 0; }
.mac-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mac-when { color: var(--muted); font-size: .88rem; }
.mac-forget { flex: none; color: var(--muted); }

/* Connecting steps */
.steps { list-style: none; padding: 0; margin: 8px 0 20px; display: grid; gap: 10px; }
.steps li { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.steps li::before {
  content: ""; flex: none; width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); box-sizing: border-box;
}
.steps li.done { color: var(--text); }
.steps li.done::before { border-color: var(--accent); background: var(--accent); box-shadow: inset 0 0 0 3px var(--surface); }
.steps li.now { color: var(--text); font-weight: 600; }
.steps li.now::before { border-color: var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@media (prefers-reduced-motion: reduce) { .steps li.now::before { animation-duration: 2.4s; } }

/* Forms */
#codeForm, #backupForm { max-width: 420px; }
input.code { max-width: 420px; }
input:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.note { margin: 16px 0; max-width: 40em; }
.msg[hidden], .note[hidden] { display: none; }

/* ---------- the viewer ---------- */
.viewer { position: fixed; inset: 0; z-index: 10; background: #000; color: #e8ebf0; overflow: hidden; color-scheme: dark; }
.viewer[hidden] { display: none; }
.surface {
  position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; outline: none;
}
.zoom { position: absolute; inset: 0; transform-origin: 0 0; will-change: transform; }
.zoom video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; pointer-events: none; }
.viewer.view-only .surface { cursor: not-allowed; }

/* Toolbar: slides down from the top, tucks away when not in use */
.toolbar {
  position: absolute; top: 0; left: 50%; transform: translate(-50%, -110%); transition: transform .2s ease;
  display: flex; align-items: center; gap: 2px; padding: calc(env(safe-area-inset-top) + 4px) 8px 4px;
  max-width: calc(100% - 8px); overflow-x: auto; scrollbar-width: none; white-space: nowrap;
  background: rgba(22, 25, 32, .9); border: 1px solid rgba(255, 255, 255, .12); border-top: 0;
  border-radius: 0 0 16px 16px; box-shadow: 0 6px 24px rgba(0, 0, 0, .45); z-index: 3;
}
.toolbar::-webkit-scrollbar { display: none; }
@supports (backdrop-filter: blur(8px)) { .toolbar, .menu, .banner, .keysbar { backdrop-filter: blur(12px); } }
.viewer.tb-on .toolbar { transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toolbar { transition: none; } }
.tb-mac { display: inline-flex; align-items: center; gap: 8px; padding: 0 10px 0 6px; font-weight: 600; font-size: .95rem; max-width: 220px; }
.tb-name { overflow: hidden; text-overflow: ellipsis; }
.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .2); }
.dot.fair { background: #f5b84a; box-shadow: 0 0 0 3px rgba(245, 184, 74, .2); }
.dot.poor { background: #ff6b5b; box-shadow: 0 0 0 3px rgba(255, 107, 91, .2); }
.tb-btn {
  flex: none; display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 10px;
  background: transparent; color: inherit; cursor: pointer; font: inherit;
}
.tb-btn:hover { background: rgba(255, 255, 255, .1); }
.tb-btn[aria-pressed="true"], .tb-btn[aria-expanded="true"] { background: rgba(45, 212, 191, .22); color: #5eead4; }
.tb-btn[hidden], .tb-select[hidden], .tb-volume[hidden] { display: none; }
.tb-text { font-size: 1.25rem; font-weight: 600; }
.tb-bye { color: #ff8a7a; }
.tb-select select {
  min-height: 44px; padding: 0 28px 0 10px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .16);
  background: rgba(255, 255, 255, .06); color: inherit; font: inherit; font-size: .95rem; cursor: pointer;
}
.tb-select option { background: #161a21; color: #e8ebf0; }
.tb-volume { display: inline-flex; align-items: center; padding: 0 6px; }
.tb-volume input { width: 84px; accent-color: #2dd4bf; }
.viewer :focus-visible { outline: 3px solid #2dd4bf; outline-offset: 1px; }

/* The little tab that brings the toolbar back (mainly for touch screens) */
.handle {
  position: absolute; top: env(safe-area-inset-top); left: 50%; transform: translateX(-50%); width: 88px; height: 28px;
  border: 0; padding: 0; background: transparent; cursor: pointer; z-index: 2; display: grid; place-items: start center;
}
.handle span { display: block; width: 44px; height: 5px; margin-top: 6px; border-radius: 3px; background: rgba(255, 255, 255, .55); box-shadow: 0 0 0 1px rgba(0, 0, 0, .35); }
.viewer.touch .handle { height: 44px; }
.viewer.tb-on .handle { visibility: hidden; }

/* More menu */
.menu {
  position: absolute; top: calc(env(safe-area-inset-top) + 58px); right: 12px; z-index: 4; width: min(320px, calc(100% - 24px));
  background: rgba(22, 25, 32, .95); border: 1px solid rgba(255, 255, 255, .14); border-radius: 14px; padding: 12px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .5); display: flex; flex-direction: column; gap: 8px;
}
.menu[hidden] { display: none; }
.menu .fine { color: #9aa3b2; margin: 0 0 4px; font-size: .86rem; }
.menu .btn { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .16); color: inherit; justify-content: flex-start; }
.menu .btn[disabled] { opacity: .45; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 0; font-weight: 600; cursor: pointer; }
.check input { width: 22px; height: 22px; accent-color: #2dd4bf; }
.check[hidden], .menu .fine[hidden] { display: none; }

/* Status notes */
.banners {
  position: absolute; top: calc(env(safe-area-inset-top) + 58px); left: 50%; transform: translateX(-50%); z-index: 2;
  width: min(600px, calc(100% - 24px)); display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.banner {
  pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px;
  background: rgba(22, 25, 32, .92); border: 1px solid rgba(255, 255, 255, .12); border-left: 4px solid #5eead4;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4); font-size: .95rem; line-height: 1.4;
}
.banner.warn { border-left-color: #f5b84a; }
.banner.warn > .icon { color: #f5b84a; }
.banner.bad { border-left-color: #ff6b5b; }
.banner.bad > .icon { color: #ff8a7a; }
.banner > .icon { flex: none; color: #5eead4; }
.banner-text { flex: 1; }
.banner-text span { color: #c4cad4; }
.banner .btn { flex: none; background: rgba(255, 255, 255, .08); border-color: rgba(255, 255, 255, .2); color: inherit; }
.banner-x { flex: none; width: 44px; height: 44px; margin: -8px -6px -8px 0; border: 0; background: transparent; color: #9aa3b2; cursor: pointer; border-radius: 10px; }
.banner-x:hover { color: #fff; background: rgba(255, 255, 255, .08); }

/* "Tap for sound" */
.sound-prompt {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 28px); transform: translateX(-50%); z-index: 3;
  display: inline-flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 22px; border-radius: 999px;
  border: 0; background: #2dd4bf; color: #04201d; font: inherit; font-weight: 700; font-size: 1.05rem; cursor: pointer;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .5);
}
.sound-prompt[hidden] { display: none; }
.viewer:has(.keysbar:not([hidden])) .sound-prompt { bottom: calc(var(--kb-inset, 0px) + env(safe-area-inset-bottom) + 84px); }

/* Connection details */
.stats {
  position: absolute; left: 10px; bottom: calc(env(safe-area-inset-bottom) + 10px); z-index: 2; pointer-events: none;
  background: rgba(10, 12, 16, .82); border: 1px solid rgba(255, 255, 255, .12); border-radius: 10px; padding: 8px 12px;
  font: 12px/1.5 var(--mono); color: #d7dce4;
}
.stats[hidden] { display: none; }
.stats dl { display: grid; grid-template-columns: auto auto; gap: 0 14px; margin: 0; }
.stats dt { color: #9aa3b2; }
.stats dd { margin: 0; text-align: right; }
.viewer:has(.keysbar:not([hidden])) .stats { bottom: calc(var(--kb-inset, 0px) + env(safe-area-inset-bottom) + 70px); }

/* Keys bar */
.keysbar {
  position: absolute; left: 0; right: 0; bottom: var(--kb-inset, 0px); z-index: 3; display: flex; gap: 6px;
  padding: 8px 8px calc(env(safe-area-inset-bottom) + 8px); overflow-x: auto; scrollbar-width: none;
  background: rgba(22, 25, 32, .92); border-top: 1px solid rgba(255, 255, 255, .12);
}
.keysbar::-webkit-scrollbar { display: none; }
.keysbar[hidden] { display: none; }
.key {
  flex: none; min-width: 48px; height: 44px; padding: 0 12px; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .16);
  background: rgba(255, 255, 255, .07); color: inherit; font: inherit; font-weight: 600; font-size: 1rem; cursor: pointer;
  touch-action: manipulation;
}
.key.mod { font-size: 1.2rem; }
.key.wide { font-size: .9rem; }
.key:active { background: rgba(255, 255, 255, .18); }
.key[aria-pressed="true"] { background: #2dd4bf; color: #04201d; border-color: #2dd4bf; }

/* The phone keyboard button, always on screen on touch devices, and its invisible text box lying on top of it. */
.kbd-fab {
  position: absolute; right: calc(env(safe-area-inset-right) + 14px);
  bottom: calc(var(--kb-inset, 0px) + env(safe-area-inset-bottom) + 18px); z-index: 3;
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(22, 25, 32, .72); border: 1px solid rgba(255, 255, 255, .22); color: #e8ebf0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35);
}
.kbd-fab[hidden] { display: none; }
.kbd-fab.open { background: #2dd4bf; color: #04201d; border-color: #2dd4bf; }
.kbd-fab .icon { width: 26px; height: 26px; pointer-events: none; }
.viewer:has(.keysbar:not([hidden])) .kbd-fab { bottom: calc(var(--kb-inset, 0px) + env(safe-area-inset-bottom) + 80px); }
@supports (backdrop-filter: blur(8px)) { .kbd-fab:not(.open) { backdrop-filter: blur(12px); } }
.softkbd {
  position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; margin: 0; border-radius: 50%;
  opacity: 0; resize: none; overflow: hidden; cursor: pointer;
  /* 16px stops iPhones zooming the page in when the box gets focus. */
  font-size: 16px; color: transparent; background: transparent; caret-color: transparent;
  -webkit-user-select: text; user-select: text;
}

/* When the session ends */
.ended { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .6); }
.ended[hidden] { display: none; }
.ended-card {
  width: min(460px, 100%); background: var(--surface); color: var(--text); border-radius: 18px; padding: 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .5); color-scheme: light dark;
}
.ended-card h2 { margin: 0 0 8px; font-size: 1.4rem; }
.ended-card h2:focus { outline: none; }
.ended-card p { color: var(--muted); margin: 0 0 8px; }
.ended-card .stack { margin-bottom: 0; }
.ended-card .btn[hidden] { display: none; }

/* Demo mode's list of messages */
.demolog {
  position: absolute; right: 8px; bottom: 8px; z-index: 2; width: min(380px, 60vw); max-height: 38vh; overflow: auto;
  background: rgba(10, 12, 16, .85); border: 1px solid rgba(255, 255, 255, .14); border-radius: 10px; padding: 8px 10px;
  font: 11px/1.45 var(--mono); color: #d7dce4; pointer-events: none;
}
.demolog[hidden] { display: none; }
.demolog h2 { font: 600 11px/1.4 system-ui, sans-serif; margin: 0 0 4px; color: #5eead4; text-transform: uppercase; letter-spacing: .05em; }
.demolog ol { margin: 0; padding-left: 0; list-style: none; }
.demolog li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.demolog li.move { color: #9aa3b2; }
.viewer:has(.keysbar:not([hidden])) .demolog { bottom: calc(var(--kb-inset, 0px) + 72px); }

@media (max-width: 560px) {
  .tb-mac { max-width: 130px; padding-right: 4px; }
  .tb-select select { padding-right: 6px; font-size: .9rem; }
  .screen .lead { font-size: 1rem; }
}
