:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #151922;
  --text-2: #5e6878;
  --border: #dfe3ea;
  --input: #f6f7fa;
  --accent: #2f5bea;
  --accent-text: #ffffff;
  --error: #c62f2f;
  --warning: #9a5a0c;
  --session-bg: #0b0d11;
  --toolbar: #15181e;
  --toolbar-text: #e8ebf1;
  --toolbar-hover: #262a33;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1014;
    --card: #181b21;
    --text: #eceff4;
    --text-2: #9aa3b2;
    --border: #2a2f38;
    --input: #20242c;
    --accent: #7c9bff;
    --accent-text: #0e1014;
    --error: #ff7b7b;
    --warning: #f0b25b;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0e1014;
  --card: #181b21;
  --text: #eceff4;
  --text-2: #9aa3b2;
  --border: #2a2f38;
  --input: #20242c;
  --accent: #7c9bff;
  --accent-text: #0e1014;
  --error: #ff7b7b;
  --warning: #f0b25b;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }

/* ---- Connect page ---------------------------------------------------------------------- */

.connect {
  max-width: 440px;
  margin: 0 auto;
  padding: max(32px, env(safe-area-inset-top)) 16px 32px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
}
.brand h1 { margin: 0; font-size: 1.35rem; font-weight: 650; letter-spacing: -0.01em; }
.brand p { margin: 2px 0 0; color: var(--text-2); font-size: 0.95rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 8px; font-size: 1rem; }

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 0.875rem;
  color: var(--text-2);
}
label:first-child { margin-top: 0; }

input, select, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
}
#device-id { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 1.2rem; letter-spacing: 0.04em; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, canvas:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button { font: inherit; cursor: pointer; }
button.primary {
  width: 100%;
  margin-top: 18px;
  padding: 12px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
button.primary:disabled { opacity: 0.6; cursor: progress; }
button.secondary {
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
}

.message { margin: 14px 0 0; font-size: 0.925rem; }
.message.error { color: var(--error); }
.message.warning { color: var(--warning); }
.footnote { color: var(--text-2); font-size: 0.85rem; }

.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-list button {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px;
  border: 0;
  border-top: 1px solid var(--border);
  background: none;
  color: var(--text);
  text-align: left;
}
.recent-list li:first-child button { border-top: 0; }
.recent-list .id { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.recent-list .detail { color: var(--text-2); font-size: 0.875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Session -------------------------------------------------------------------------- */

.session {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--session-bg);
  color: var(--toolbar-text);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
  background: var(--toolbar);
  min-height: 52px;
}
.session-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.session-title .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-title .meta { font-size: 0.8rem; color: #9aa3b2; }

.tools { display: flex; gap: 10px; overflow-x: auto; scrollbar-width: none; }
.tool-group { display: flex; gap: 2px; }
.tool-group + .tool-group { padding-left: 10px; border-left: 1px solid #2a2f38; }

.tool {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--toolbar-text);
  flex: none;
}
.tool:hover { background: var(--toolbar-hover); }
.tool svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.tool.danger { color: #ff8a8a; }
.tool-select {
  width: auto;
  height: 40px;
  padding: 0 8px;
  background: #20242c;
  color: var(--toolbar-text);
  border: 1px solid #2a2f38;
  border-radius: 8px;
  font-size: 0.875rem;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
}
#screen {
  display: block;
  background: #000;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: rgba(11, 13, 17, 0.82);
  text-align: center;
  padding: 24px;
}
.overlay p { margin: 0; max-width: 360px; }
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #39404d;
  border-top-color: #7c9bff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.banner {
  position: absolute;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: #2a2f38;
  color: #f0f2f6;
  font-size: 0.875rem;
  max-width: calc(100% - 32px);
}

/* ---- Side panels (files, clipboard) ---------------------------------------------------- */

.panel {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(380px, 100%);
  display: flex;
  flex-direction: column;
  background: #15181e;
  border-left: 1px solid #2a2f38;
  color: var(--toolbar-text);
  z-index: 2;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 6px 6px 16px;
  border-bottom: 1px solid #2a2f38;
}
.panel-head h2 { margin: 0; font-size: 1rem; }
.panel label { color: #9aa3b2; margin: 0 0 6px; }
.panel textarea {
  background: #20242c;
  color: var(--toolbar-text);
  border-color: #2a2f38;
  resize: vertical;
  font-size: 0.9rem;
}
.panel .hint { margin: 8px 16px; font-size: 0.8rem; color: #9aa3b2; }
.panel-section { padding: 14px 16px 0; display: flex; flex-direction: column; gap: 8px; }
.panel-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 14px;
  border: 1px solid #39404d;
  border-radius: 8px;
  background: #20242c;
  color: var(--toolbar-text);
  font-size: 0.9rem;
  cursor: pointer;
}
.panel-button:hover { background: #262a33; }
.panel-button.accent { background: #7c9bff; border-color: #7c9bff; color: #0e1014; font-weight: 600; }

.path-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  border-bottom: 1px solid #2a2f38;
}
.path-bar .path {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  color: #c8ceda;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: rtl;
  text-align: left;
}

.file-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; min-height: 0; }
.file-list button {
  width: 100%;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 2px 10px;
  align-items: center;
  padding: 7px 14px;
  border: 0;
  background: none;
  color: var(--toolbar-text);
  text-align: left;
}
.file-list button:hover { background: #20242c; }
.file-list svg { grid-row: span 2; width: 20px; height: 20px; fill: none; stroke: #9aa3b2; stroke-width: 1.8; stroke-linejoin: round; }
.file-list .folder svg { stroke: #7c9bff; }
.file-list .name { font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-list .meta { font-size: 0.75rem; color: #9aa3b2; }
.file-list .notice { padding: 16px; color: #9aa3b2; font-size: 0.9rem; }

.panel-foot {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px 0;
  border-top: 1px solid #2a2f38;
  flex-wrap: wrap;
}
.panel-foot .hint { margin: 0 0 0 8px; }

.transfers { list-style: none; margin: 0; padding: 6px 16px 12px; max-height: 40%; overflow-y: auto; }
.transfers li { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; padding: 6px 0; font-size: 0.85rem; }
.transfers .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transfers progress { grid-column: 1; width: 100%; height: 6px; accent-color: #7c9bff; }
.transfers .status { grid-column: 1 / span 2; color: #9aa3b2; font-size: 0.75rem; }
.transfers .status.error { color: #ff8a8a; }
.transfers .tool { width: 28px; height: 28px; grid-row: 1 / span 2; grid-column: 2; }
.transfers .tool svg { width: 16px; height: 16px; }

.drop-overlay {
  position: absolute;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 2px dashed #7c9bff;
  border-radius: 14px;
  background: rgba(20, 30, 60, 0.6);
  font-weight: 600;
  pointer-events: none;
  z-index: 3;
}

/* Off-screen field that brings up the phone keyboard and collects typed text. */
.ime {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  padding: 0;
  border: 0;
  resize: none;
}

.dialog {
  width: min(440px, calc(100% - 32px));
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  padding: 20px;
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.dialog h2 { margin: 0 0 4px; font-size: 1.05rem; }
.dialog p { margin: 0 0 12px; color: var(--text-2); font-size: 0.9rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.dialog-actions .primary { width: auto; margin: 0; padding: 10px 18px; }

@media (max-width: 600px) {
  .toolbar { flex-wrap: wrap; gap: 6px; }
  .session-title { flex-basis: 100%; }
  .tools { width: 100%; }
  .tool-group + .tool-group { padding-left: 6px; }
}
