:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #14171c;
  --muted: #687080;
  --line: #e1e4e9;
  --accent: #2f6bff;
  --accent-text: #ffffff;
  --you: #2f6bff;
  --you-text: #ffffff;
  --ok: #18a058;
  --danger: #e5484d;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1f232b;
    --text: #e9ebef;
    --muted: #8d95a3;
    --line: #262b34;
    --accent: #4d82ff;
    --you: #2f5fd6;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 20px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8;
      stroke-linecap: round; stroke-linejoin: round; flex: none; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:disabled { opacity: 0.45; cursor: default; }

/* ---- header ---- */
.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 12px; flex: 1; min-width: 0; }
h1 { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: 0.16em; }
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--muted);
          font-size: 13px; min-width: 0; white-space: nowrap; overflow: hidden; }
.status span { overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.status.ok .dot { background: var(--ok); }
.status.bad .dot { background: var(--danger); }
.actions { display: flex; gap: 6px; }
.tool {
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px;
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
}
.tool:hover { background: var(--surface-2); }
.tool.on { background: var(--accent); color: var(--accent-text); }
.tool.only-icon { padding: 0 8px; color: var(--muted); }
@media (max-width: 560px) {
  .tool span { display: none; }
  .tool { padding: 0 9px; }
}

/* ---- page ---- */
.page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
}

/* live screen */
.viewer {
  margin: 12px 16px 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  flex: none;
}
.viewer canvas { display: block; width: 100%; height: auto; max-height: 55vh; object-fit: contain; background: #000; }
.viewer-bar {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 8px 6px 14px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}
.live { flex: 1; display: inline-flex; align-items: center; gap: 8px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: blink 1.6s infinite; }
.ghost { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; color: var(--text); }
.ghost:hover { background: var(--surface-2); }
.viewer.full, .viewer:fullscreen { position: fixed; inset: 0; z-index: 10; margin: 0; border-radius: 0; }
.viewer.full canvas, .viewer:fullscreen canvas { flex: 1; min-height: 0; height: 100%; max-height: none; }

/* remote control */
.remote {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column;
  background: #000; color: #e9ebef;
}
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; touch-action: none; cursor: default;
         -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.stage canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; image-rendering: auto; }
.touch-dot { position: absolute; width: 36px; height: 36px; margin: -18px 0 0 -18px; border-radius: 50%;
             border: 2px solid rgba(255,255,255,.9); background: rgba(77,130,255,.35); pointer-events: none; }
.touch-dot.pop { animation: pop .35s ease-out forwards; }
.remote-help { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); margin: 0;
               width: max-content; max-width: calc(100% - 24px); padding: 6px 12px; border-radius: 10px;
               background: rgba(0,0,0,.65); color: #fff; font-size: 12px; text-align: center;
               pointer-events: none; transition: opacity .6s; }
.remote-bar { display: flex; align-items: center; gap: 2px; padding: 6px 8px 6px 14px;
              padding-bottom: calc(6px + env(safe-area-inset-bottom));
              background: #171a20; color: #8d95a3; font-size: 13px; }
.remote .ghost { color: #e9ebef; width: 40px; height: 40px; }
.remote .ghost:hover, .remote .ghost.on { background: #2a2f38; }
.keys-row { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; background: #11141a;
            padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
.keys-row button { min-width: 44px; height: 38px; padding: 0 10px; border-radius: 8px;
                   background: #262b34; color: #e9ebef; font-size: 14px; }
.keys-row button.on { background: #4d82ff; }
.kb-input { position: fixed; left: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0;
            font-size: 16px; /* 16px stops iPhones zooming in */ }
/* sideways phone: controls move to the right edge so the screen gets the full height */
@media (orientation: landscape) and (max-height: 560px) {
  .remote { flex-direction: row; flex-wrap: wrap; }
  .stage { order: 0; height: 100%; }
  .remote-bar { order: 1; flex-direction: column; justify-content: center; height: 100%;
                padding: 6px calc(6px + env(safe-area-inset-right)) 6px 6px; }
  .remote-bar .live { flex: 0; margin-bottom: 8px; }
  .remote-bar .live span { display: none; }   /* just the red dot */
  .keys-row { order: 2; position: absolute; left: 0; right: 56px; bottom: 0;
              flex-wrap: nowrap; overflow-x: auto; padding-bottom: 8px; }
  .keys-row button { flex: none; }
}
@keyframes pop { to { transform: scale(1.8); opacity: 0; } }

/* chat */
main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hint { margin: auto; text-align: center; color: var(--muted); padding: 24px 0; }
.hint h2 { margin: 0 0 4px; color: var(--text); font-size: 22px; font-weight: 600; }
.hint p { margin: 0 0 18px; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.chips button {
  padding: 8px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); font-size: 14px;
}
.chips button:hover { border-color: var(--accent); }

.msg {
  max-width: 82%;
  padding: 9px 14px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: rise 0.18s ease-out;
}
.msg.you { align-self: flex-end; background: var(--you); color: var(--you-text); border-bottom-right-radius: 6px; }
.msg.static { align-self: flex-start; background: var(--surface); box-shadow: var(--shadow); border-bottom-left-radius: 6px; }
.msg.you + .msg.static, .msg.static + .msg.you { margin-top: 6px; }
.msg.note { align-self: center; max-width: 90%; padding: 2px 0; color: var(--muted); font-size: 13px; background: none; }
.msg.typing::after { content: "•••"; letter-spacing: 2px; color: var(--muted); animation: blink 1.2s infinite; }
.msg.shot { padding: 6px; width: min(82%, 420px); }
.shot img { display: block; width: 100%; border-radius: 12px; cursor: zoom-in; }
.shot .shot-actions { display: flex; gap: 16px; padding: 8px 8px 4px; font-size: 14px; }
.shot .shot-actions a { color: var(--accent); text-decoration: none; font-weight: 500; }

/* ---- composer ---- */
.composer {
  padding: 10px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
}
.bar {
  display: flex; align-items: center; gap: 6px;
  max-width: 788px; margin: 0 auto;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.bar:focus-within { border-color: var(--accent); }
.bar input {
  flex: 1; min-width: 0;
  padding: 8px 4px;
  border: 0; outline: 0;
  background: none; color: var(--text);
  font: inherit;
}
.bar input::placeholder { color: var(--muted); }
.mic, .send, .stop {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
}
.mic { background: var(--surface-2); color: var(--text); }
.mic.recording { background: var(--danger); color: #fff; animation: pulse 1.4s infinite; }
.mic.busy { opacity: 0.6; }
.send { background: var(--accent); color: var(--accent-text); }
.stop { background: var(--danger); color: #fff; }
.stop svg { fill: currentColor; stroke: none; }

/* ---- settings ---- */
dialog {
  border: 0;
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  width: min(400px, calc(100% - 32px));
  padding: 22px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
dialog::backdrop { background: rgba(10, 12, 16, 0.5); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 16px; font-size: 18px; }
.settings-msg { margin: -6px 0 14px; color: var(--danger); font-size: 14px; }
dialog label { display: block; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
dialog label input[type=password], dialog label input[type=url] {
  display: block; width: 100%; margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); font: inherit; font-size: 15px;
}
dialog label input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
dialog label.row { display: flex; gap: 10px; align-items: center; color: var(--text); font-size: 15px; }
.buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.buttons button { padding: 9px 16px; border-radius: 10px; background: var(--accent); color: var(--accent-text); }
.buttons button.secondary { background: var(--surface-2); color: var(--text); }

@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(229, 72, 77, 0.22); } }
@keyframes blink { 50% { opacity: 0.35; } }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } }
