:root {
  --bg: #0b0c10;
  --panel: #16171d;
  --panel-2: #1f2028;
  --line: rgba(255, 255, 255, .08);
  --text: #eef0f6;
  --muted: #8b8fa3;
  --accent: #a78bfa;
  --accent-soft: #c4b5fd;
  --accent-ink: #14101f;
  --ok: #7ee2b8;
  --bad: #ff7d8a;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --font: -apple-system, "SF Pro Text", Inter, "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-font-smoothing: antialiased;
}
input, textarea, button { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
.ic { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

.screen { position: fixed; inset: 0; }

/* ===== Login ===== */
.login {
  display: flex; flex-direction: column;
  padding: calc(var(--sat) + 22px) calc(var(--sar) + 24px) calc(var(--sab) + 20px) calc(var(--sal) + 24px);
  overflow: hidden;
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--accent-soft); font-weight: 650; letter-spacing: -.01em; }
.brand .ic { width: 20px; height: 20px; stroke-width: 2.2; }
.login-body { flex: 1; display: flex; flex-direction: column; justify-content: center; max-width: 440px; position: relative; z-index: 1; }
.eyebrow { margin: 0 0 12px; font: 11px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.login h1 { margin: 0 0 14px; font-size: clamp(30px, 8.5vw, 42px); line-height: 1.05; letter-spacing: -.03em; font-weight: 650; }
.lede { margin: 0 0 34px; color: var(--muted); font-size: 15px; max-width: 34ch; }
label { display: block; font: 11px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 9px; }
#keyInput {
  display: block; width: 100%; padding: 15px 16px; margin-bottom: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; outline: none;
  font-family: var(--mono); font-size: 15px; letter-spacing: .04em;
  -webkit-user-select: text; user-select: text;
}
#keyInput:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(167, 139, 250, .15); }
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; padding: 15px 18px; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); font-weight: 650; letter-spacing: -.01em;
  transition: transform .08s ease, background .15s ease;
}
.btn-primary:active { transform: scale(.985); background: var(--accent-soft); }
.btn-primary.small { width: auto; padding: 11px 18px; border-radius: 12px; font-size: 14px; }
.btn-primary .ic { width: 18px; height: 18px; }
.form-err { min-height: 20px; margin: 12px 0 0; color: var(--bad); font-size: 13px; }
.login-foot { color: var(--muted); font-size: 12.5px; max-width: 34ch; position: relative; z-index: 1; }
.ring-motif {
  position: absolute; right: -110px; bottom: -90px; width: 340px; height: 340px;
  fill: none; stroke: var(--accent); stroke-width: .6; opacity: .28; pointer-events: none;
}

/* ===== Viewer ===== */
.viewer { background: #000; }
/* Rotated mode: the whole viewer is turned 90deg so a portrait phone held
   sideways shows the laptop full width. JS sets the size and transform. */
.viewer.rotated { inset: auto; top: 0; left: 0; transform-origin: 0 0; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

.topbar {
  position: absolute; top: calc(var(--sat) + 10px); left: calc(var(--sal) + 12px); right: calc(var(--sar) + 12px);
  display: flex; align-items: center; justify-content: space-between; gap: 10px; pointer-events: none;
}
.chip {
  pointer-events: auto;
  display: inline-flex; align-items: center; gap: 8px; max-width: 70%;
  padding: 8px 13px 8px 10px; border-radius: 999px;
  background: rgba(22, 23, 29, .82); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  font-size: 13px; color: var(--text);
}
.chip-text { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #4a4d5c; flex: none; transition: background .2s; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(126, 226, 184, .18); }
.dot.live { background: var(--accent); box-shadow: 0 0 0 3px rgba(167, 139, 250, .2); }
.dot.bad { background: var(--bad); }
.stats { font: 11px var(--mono); color: rgba(255, 255, 255, .55); letter-spacing: .04em; white-space: nowrap; }

.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(11, 12, 16, .72);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  transition: opacity .2s ease;
}
.overlay.hide { opacity: 0; pointer-events: none; }
.overlay-card { text-align: center; max-width: 320px; }
.overlay-icon {
  width: 54px; height: 54px; margin: 0 auto 16px; border-radius: 18px;
  display: grid; place-items: center; background: var(--panel); border: 1px solid var(--line); color: var(--accent-soft);
}
.overlay-icon .ic { width: 24px; height: 24px; stroke-width: 2.2; }
.overlay h2 { margin: 0 0 6px; font-size: 20px; letter-spacing: -.02em; font-weight: 650; }
.overlay p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

/* Floating dock */
.dock {
  position: absolute; left: 50%; bottom: calc(var(--sab) + 14px); transform: translateX(-50%);
  display: flex; gap: 2px; padding: 6px; border-radius: 999px;
  background: rgba(22, 23, 29, .86); border: 1px solid var(--line);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .45);
  transition: transform .25s ease, opacity .25s ease;
}
.dock button {
  position: relative; width: 48px; height: 46px; border-radius: 999px;
  display: grid; place-items: center; color: var(--text);
  transition: background .12s ease, color .12s ease;
}
.dock button:active, .dock button.on { background: var(--accent); color: var(--accent-ink); }
.dock .badge {
  position: absolute; top: 6px; right: 7px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: var(--accent); color: var(--accent-ink);
  font: 600 10px/16px var(--mono); text-align: center;
}
.dock button.on .badge { background: var(--accent-ink); color: var(--accent-soft); }
.viewer.kb-open .dock { transform: translate(-50%, 140px); opacity: 0; pointer-events: none; }

.toast {
  position: absolute; left: 50%; bottom: calc(var(--sab) + 82px); transform: translate(-50%, 8px);
  padding: 9px 14px; border-radius: 999px; font-size: 13px; white-space: nowrap;
  background: rgba(22, 23, 29, .9); border: 1px solid var(--line); color: var(--text);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.tappable { pointer-events: auto; background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }

.action-list { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.action-list button {
  display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-radius: 14px;
  background: var(--panel-2); font-size: 14.5px; font-weight: 500; text-align: left;
}
.action-list button:active { background: #2a2c37; }
.action-list .ic { width: 18px; height: 18px; color: var(--accent-soft); }

/* Hidden keyboard catcher */
.kb {
  position: fixed; left: 0; bottom: 0; width: 1px; height: 1px;
  opacity: 0; border: 0; padding: 0; margin: 0; background: transparent; color: transparent;
  caret-color: transparent;
}

/* Sheets */
.scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); opacity: 0; pointer-events: none; transition: opacity .2s; }
.scrim.show { opacity: 1; pointer-events: auto; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 78%; display: flex; flex-direction: column;
  padding: 10px 16px calc(var(--sab) + 16px);
  background: var(--panel); border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  transform: translateY(105%); transition: transform .26s cubic-bezier(.32, .72, 0, 1);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .5);
}
.sheet.show { transform: translateY(0); }
.sheet::before {
  content: ""; width: 38px; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .18);
  margin: 0 auto 8px;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-title { font-weight: 650; letter-spacing: -.01em; font-size: 16px; }
.sheet-hint { margin: -4px 0 12px; color: var(--muted); font-size: 13px; }
.icon-btn { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; color: var(--muted); background: var(--panel-2); }
.icon-btn.accent { background: var(--accent); color: var(--accent-ink); }
.icon-btn .ic { width: 18px; height: 18px; }

.row-input {
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; margin-bottom: 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 14px; color: var(--muted);
}
.row-input .ic { width: 18px; height: 18px; }
.row-input input { flex: 1; min-width: 0; background: none; border: 0; outline: none; padding: 8px 0; color: var(--text); -webkit-user-select: text; user-select: text; }
.row-input:focus-within { border-color: var(--accent); }

.tab-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.tab-list li {
  display: flex; align-items: center; gap: 12px; padding: 11px 6px 11px 8px;
  border-bottom: 1px solid var(--line);
}
.tab-list li:last-child { border-bottom: 0; }
.tab-list .fav { width: 28px; height: 28px; border-radius: 9px; background: var(--panel-2); display: grid; place-items: center; flex: none; overflow: hidden; }
.tab-list .fav img { width: 16px; height: 16px; }
.tab-list .fav .ic { width: 16px; height: 16px; color: var(--muted); }
.tab-list .meta { flex: 1; min-width: 0; }
.tab-list .t { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab-list .u { font: 11px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.tab-list li.live .t { color: var(--accent-soft); }
.tab-list li.live .fav { box-shadow: 0 0 0 1.5px var(--accent); }
.tab-list .close { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--muted); }
.tab-list .close .ic { width: 16px; height: 16px; }
.tab-list .empty { padding: 24px 8px; color: var(--muted); text-align: center; font-size: 14px; }

#composeText {
  width: 100%; min-height: 140px; resize: none; padding: 14px; border-radius: 14px;
  background: var(--bg); border: 1px solid var(--line); outline: none; line-height: 1.5;
  -webkit-user-select: text; user-select: text;
}
#composeText:focus { border-color: var(--accent); }
.sheet-actions { display: flex; gap: 10px; margin-top: 12px; }
.sheet-actions .btn-primary { flex: 1; padding: 13px; }
.btn-ghost { flex: 1; padding: 13px; border-radius: 14px; background: var(--panel-2); color: var(--text); font-weight: 600; }

.grid-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px; }
.grid-actions button {
  display: flex; align-items: center; gap: 10px; padding: 13px 14px; border-radius: 14px;
  background: var(--panel-2); font-size: 14px; font-weight: 500;
}
.grid-actions button:active { background: #2a2c37; }
.grid-actions .ic { width: 18px; height: 18px; color: var(--accent-soft); }
.grid-actions button.wide { grid-column: 1 / -1; }
.grid-actions button.on { background: var(--accent); color: var(--accent-ink); }
.grid-actions button.on .ic { color: var(--accent-ink); }

.cam-panel {
  position: absolute; top: calc(var(--sat) + 56px); right: calc(var(--sar) + 12px);
  width: 116px; display: flex; flex-direction: column; gap: 6px; align-items: stretch;
  transition: width .22s cubic-bezier(.32, .72, 0, 1);
}
.cam-panel.big { width: min(74vw, 340px); }
.cam-preview {
  width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 14px; display: block;
  border: 1.5px solid var(--accent); background: #000; box-shadow: 0 10px 30px rgba(0, 0, 0, .5);
  transform: scaleX(-1);
}
.cam-preview.back { transform: none; }
.cam-tag {
  position: absolute; top: 7px; left: 7px; padding: 3px 8px; border-radius: 999px;
  background: rgba(11, 12, 16, .72); font: 10px/1.4 var(--mono); letter-spacing: .08em;
  text-transform: uppercase; color: var(--accent-soft); pointer-events: none;
}
.cam-tools { display: flex; gap: 6px; justify-content: flex-end; }
.cam-tools button {
  width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center;
  background: rgba(22, 23, 29, .88); border: 1px solid var(--line); color: var(--text);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.cam-tools button:active, .cam-tools button.on { background: var(--accent); color: var(--accent-ink); }
.cam-tools .ic { width: 17px; height: 17px; }
.seg-label { font: 11px/1 var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.seg { display: flex; padding: 4px; background: var(--bg); border-radius: 12px; border: 1px solid var(--line); margin-bottom: 16px; }
.seg button { flex: 1; padding: 9px; border-radius: 9px; font-size: 13px; color: var(--muted); font-weight: 500; }
.seg button.on { background: var(--panel-2); color: var(--text); }
.btn-danger-ghost { display: flex; align-items: center; gap: 10px; color: var(--bad); font-size: 14px; padding: 8px 4px; }
.btn-danger-ghost .ic { width: 18px; height: 18px; }

@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; width: 460px; transform: translate(-50%, 105%); }
  .sheet.show { transform: translate(-50%, 0); }
  .login-body { max-width: 520px; }
}
