:root {
  color-scheme: light;
  --paper: #e6e0d2;
  --paper-2: #f4efe4;
  --ink: #1c1b16;
  --muted: #5e594e;
  --line: #cfc6b4;
  --accent: #1f4d3a;
  --accent-2: #e7f0ea;
  --danger: #8d2f24;
  --stage: #12140f;
  --shadow: 0 16px 40px rgba(40, 32, 18, 0.12);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 10% -10%, #f7f1e4, transparent 50%),
    var(--paper);
  color: var(--ink);
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper-2);
  cursor: pointer;
}

button:hover { border-color: #b3a890; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button[aria-pressed="true"] {
  background: var(--accent);
  color: #f4efe4;
  border-color: var(--accent);
}

input, select, textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
}

#gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 16px;
}

.gate-card {
  width: min(440px, 100%);
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 28px;
  box-shadow: var(--shadow);
  padding: 28px 28px 22px;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--accent);
}

h1 {
  margin: 6px 0 8px;
  font-family: Palatino, "Iowan Old Style", Georgia, serif;
  font-size: 44px;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.lede, .fine, .hint { color: var(--muted); line-height: 1.45; }
.fine { font-size: 13px; }

label { display: block; margin: 14px 0 6px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.check input { width: auto; min-height: 0; }

#connect-btn {
  width: 100%;
  margin-top: 8px;
  background: var(--accent);
  color: #f6f3ea;
  border-color: var(--accent);
  border-radius: 14px;
  min-height: 48px;
}

.error { color: var(--danger); min-height: 1.2em; }
.advanced { margin-top: 16px; }
.advanced summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; }

#recent { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
#recent button { border-radius: 999px; }

#session {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(240px, 1fr) auto auto auto;
}

button:disabled,
input:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.top, #toolbar, #key-row, #type-form {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px 14px;
  flex-wrap: wrap;
}

.top {
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.identity { display: flex; flex-direction: column; gap: 2px; }
.identity span, .meters { color: var(--muted); font-size: 13px; }
.meters { display: flex; gap: 12px; flex-wrap: wrap; }

.banner {
  margin: 0;
  padding: 10px 14px;
  background: #f3e2c2;
  color: #5a3b12;
}

#stage {
  background: var(--stage);
  display: grid;
  place-items: center;
  min-height: 0;
  position: relative;
  overflow: auto;
}

#viewport {
  position: relative;
  width: fit-content;
  max-width: 100%;
}

#screen {
  display: block;
  width: min(100%, 1600px);
  height: auto;
  max-height: calc(100vh - 230px);
  background: #000;
  touch-action: none;
  cursor: crosshair;
}

#viewport.actual #screen {
  width: auto;
  max-width: none;
  max-height: none;
}

#remote-cursor {
  position: absolute;
  width: 14px;
  height: 14px;
  margin: -2px 0 0 -2px;
  border: 2px solid #e07a3d;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #12140f;
  pointer-events: none;
}

#stage-hint {
  position: absolute;
  left: 12px;
  bottom: 8px;
  margin: 0;
  color: #d9d3c3;
  font-size: 12px;
  opacity: 0.8;
}

#toolbar label, #type-form label { margin: 0; display: flex; align-items: center; gap: 6px; }
#toolbar select, #type-form input { width: auto; min-height: 40px; }
#type-form input { flex: 1; min-width: 180px; }

#key-row { padding-top: 0; }
#key-row button { min-width: 44px; }

#drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: min(420px, 100%);
  background: var(--paper-2);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  z-index: 5;
}

.drawer-head, .file-actions, #chat-form {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 12px;
}

.panel { padding: 0 12px 16px; overflow: auto; }
#file-list { list-style: none; margin: 0; padding: 0; }
#file-list button {
  width: 100%;
  text-align: left;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.path { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
#chat-log { display: flex; flex-direction: column; gap: 8px; min-height: 240px; }
.bubble { padding: 8px 10px; border-radius: 12px; background: white; border: 1px solid var(--line); }
.bubble.host { background: var(--accent-2); }
#chat-form input { flex: 1; width: auto; min-width: 0; }

body.drawer-open #session { padding-right: min(420px, 100%); }
.file-upload { margin: 0; }

#btn-lock { border-color: #e2b2aa; color: var(--danger); }

@media (max-width: 800px) {
  h1 { font-size: 36px; }
  #stage-hint { display: none; }
  #screen { max-height: calc(100vh - 280px); }
  #toolbar { overflow-x: auto; flex-wrap: nowrap; }
  #drawer { width: 100%; }
  body.drawer-open #session { padding-right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto; }
}
