:root {
  --bg-0: #f6f2e9;
  --bg-1: #efe7da;
  --panel: rgba(255, 253, 249, 0.92);
  --line: #d8cab5;
  --line-strong: #c4b197;
  --text: #2f2a24;
  --muted: #716858;
  --ok: #1e8f62;
  --warn: #a87412;
  --err: #b4483c;
  --accent: #0b7a75;
  --accent-2: #1f9f92;
  --shadow: 0 18px 40px rgba(94, 78, 53, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 700px at -10% -20%, #f4d8ac 0%, transparent 60%),
              radial-gradient(1000px 520px at 120% 120%, #cce3de 0%, transparent 65%),
              linear-gradient(180deg, var(--bg-0), var(--bg-1));
  display: flex;
  flex-direction: column;
}

.bg-ornament {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image: linear-gradient(90deg, rgba(91, 74, 50, 0.06) 1px, transparent 1px),
                    linear-gradient(0deg, rgba(91, 74, 50, 0.06) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: radial-gradient(circle at center, black, transparent 80%);
}

.shell {
  flex: 1;
  width: min(960px, calc(100% - 2rem));
  margin: 2.25rem auto;
  position: relative;
  z-index: 1;
}

.app-footer {
  width: min(960px, calc(100% - 2rem));
  margin: 0 auto 1.2rem;
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  text-align: right;
  opacity: 0.92;
}

.app-version {
  display: inline-block;
  padding: 0.24rem 0.42rem;
  border-radius: 8px;
  border: 1px solid rgba(91, 74, 50, 0.15);
  background: rgba(255, 255, 255, 0.45);
}

.brand-row h1 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: clamp(2rem, 5vw, 2.6rem);
  letter-spacing: 0.01em;
}

.brand-row p {
  margin: 0.3rem 0 1.4rem;
  color: var(--muted);
  font-size: 1rem;
}

.session-tools {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  margin-bottom: 0.6rem;
}

.session-tools button {
  width: auto;
  padding: 0.5rem 0.7rem;
  font-size: 0.86rem;
  background: rgba(255, 250, 242, 0.75);
}

#btn-alias.aliasing-inverted {
  background: #0b0b0b;
  color: #ffdead;
  border-color: #0b0b0b;
}

#btn-alias.aliasing-inverted:hover {
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.26);
}

.card,
.chat {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 20px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

.card {
  position: relative;
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), #dbb263, var(--accent-2));
  opacity: 0.75;
}

.card h2,
.chat h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: 1.6rem;
}

.lead {
  color: var(--muted);
  margin-top: 0.42rem;
  line-height: 1.45;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.95rem;
}

label {
  display: block;
  margin: 0.55rem 0 0.34rem;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

input,
textarea,
button {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--text);
  padding: 0.68rem 0.78rem;
  font: inherit;
}

input::placeholder,
textarea::placeholder {
  color: #9c8f7b;
}

input:focus,
textarea:focus,
button:focus-visible {
  outline: 2px solid color-mix(in oklab, var(--accent) 45%, white);
  outline-offset: 1px;
  border-color: var(--line-strong);
}

textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.35;
}

button {
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 12px rgba(67, 57, 45, 0.15);
}

button.primary {
  background: linear-gradient(145deg, var(--accent), var(--accent-2));
  color: white;
  border: none;
}

.row-tight {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
}

.row-tight button {
  width: auto;
  min-width: 78px;
}

.setup-actions {
  margin-top: 1.05rem;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.7rem;
}

.setup-actions button {
  min-height: 45px;
  font-weight: 600;
}

.status {
  margin: 0.95rem 0 0;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.34rem 0.62rem;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.7);
}

.status.ok { color: var(--ok); border-color: color-mix(in oklab, var(--ok) 35%, white); }
.status.error { color: var(--err); border-color: color-mix(in oklab, var(--err) 35%, white); }
.status.working { color: var(--warn); border-color: color-mix(in oklab, var(--warn) 35%, white); }
.status.idle { color: var(--muted); border-color: color-mix(in oklab, var(--muted) 30%, white); }

.setup-status {
  margin-top: 0.28rem;
  color: var(--muted);
}

.gateway-install-note {
  margin-top: 0.35rem;
  margin-bottom: 0;
  color: var(--warn);
  font-size: 0.92rem;
}

.gateway-install-note a {
  color: var(--accent);
}

.gateway-install-note p {
  margin: 0.18rem 0;
}

.gateway-install-note code {
  background: rgba(18, 18, 18, 0.06);
  border: 1px solid rgba(18, 18, 18, 0.1);
  border-radius: 6px;
  padding: 0.12rem 0.3rem;
  font-size: 0.85rem;
}

.gateway-install-note pre {
  margin: 0.35rem 0;
  padding: 0.52rem 0.62rem;
  border: 1px solid rgba(18, 18, 18, 0.12);
  border-radius: 8px;
  background: rgba(18, 18, 18, 0.04);
  color: #584b39;
  font-size: 0.8rem;
  line-height: 1.32;
  white-space: pre-wrap;
  word-break: break-word;
}

.gateway-install-note .copy-origin {
  display: inline-block;
  width: auto;
  min-width: 0;
  margin-left: 0.45rem;
  padding: 0.22rem 0.46rem;
  font-size: 0.8rem;
}

.publish-info {
  margin-top: 0.7rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(255, 250, 240, 0.78));
}

.publish-line {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
}

.publish-line + .publish-line {
  margin-top: 0.22rem;
}

.publish-line a {
  color: var(--accent);
  text-decoration: none;
}

.publish-line a:hover {
  text-decoration: underline;
}

.hidden {
  display: none !important;
}

.lock-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 0;
  background: radial-gradient(circle at 18% 12%, rgba(98, 217, 255, 0.24), transparent 38%),
              radial-gradient(circle at 84% 86%, rgba(154, 111, 255, 0.28), transparent 42%),
              radial-gradient(circle at 48% 42%, rgba(26, 74, 124, 0.3), transparent 56%),
              linear-gradient(160deg, rgba(4, 15, 32, 0.9), rgba(9, 24, 43, 0.86));
  backdrop-filter: blur(7px);
}

.lock-card {
  position: relative;
  width: 100vw;
  height: 100vh;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
  color: #e8f3fb;
  overflow: hidden;
}

.lock-banner {
  position: absolute;
  top: clamp(0.9rem, 2.8vh, 2rem);
  left: clamp(0.9rem, 2.8vw, 2.2rem);
  z-index: 2;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0;
  max-width: min(92vw, 760px);
  padding: 0.62rem 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(177, 225, 255, 0.32);
  background: linear-gradient(160deg, rgba(8, 24, 48, 0.62), rgba(9, 23, 56, 0.52));
  backdrop-filter: blur(4px);
}

.lock-title {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: clamp(1.2rem, 3.5vw, 2rem);
  letter-spacing: 0.015em;
  color: #f2fbff;
  text-shadow: 0 2px 16px rgba(78, 196, 255, 0.35);
}

.lock-subtitle {
  margin: 0.32rem 0 0;
  color: #d3ebff;
  font-size: clamp(0.88rem, 1.8vw, 1rem);
}

.lock-canvas {
  width: 100%;
  height: 100%;
  border-radius: 0;
  display: block;
  border: 0;
  background: #071425;
}

.yaml-editor-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(20, 16, 12, 0.54);
  backdrop-filter: blur(3px);
}

.yaml-editor-card {
  width: min(940px, 100%);
  max-height: min(90vh, 900px);
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto auto;
  gap: 0.65rem;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.98);
  box-shadow: 0 22px 52px rgba(40, 31, 22, 0.34);
  padding: 0.85rem;
}

.yaml-editor-head h2 {
  margin: 0;
  font-size: 1.25rem;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
}

.yaml-editor-context {
  margin: 0.22rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.yaml-editor-text {
  min-height: 280px;
  max-height: 62vh;
  width: 100%;
  resize: vertical;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fffdf8;
  font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92rem;
  line-height: 1.42;
}

.yaml-editor-text.hidden-by-cm {
  display: none;
}

.yaml-editor-cm {
  min-height: 280px;
  max-height: 62vh;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fffdf8;
  overflow: auto;
}

.yaml-editor-cm .cm-editor {
  min-height: 278px;
  max-height: 62vh;
}

.yaml-editor-cm .cm-scroller {
  font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92rem;
  line-height: 1.42;
}

.yaml-editor-cm.disabled {
  opacity: 0.65;
  pointer-events: none;
}

.yaml-editor-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.yaml-editor-status.working { color: var(--warn); }
.yaml-editor-status.error { color: var(--err); }
.yaml-editor-status.ok { color: var(--ok); }

.yaml-editor-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.55rem;
}

.room-hero h2 {
  margin: 0;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
  font-size: clamp(2rem, 4.2vw, 2.8rem);
  line-height: 1.1;
}

.room-description {
  margin-top: 0.55rem;
  max-width: 66ch;
  font-size: 1.15rem;
  line-height: 1.5;
  color: #4a4034;
}

.transcript {
  margin-top: 0.95rem;
  min-height: 280px;
  max-height: 50vh;
  overflow: auto;
  border: 1px solid #dbcdb9;
  border-radius: 14px;
  padding: 0.75rem;
  background: rgba(255, 251, 243, 0.9);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.msg {
  margin: 0;
}

.msg p {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.42;
}

.msg.system p {
  color: #1f5da8;
}

.composer {
  margin-top: 0.8rem;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.55rem;
}

.composer button {
  width: auto;
  min-width: 90px;
}

.chat-body {
  display: grid;
  grid-template-columns: 1fr 190px;
  gap: 0.75rem;
  align-items: start;
  margin-top: 1rem;
}

.chat-main {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

/* Remove the top margin from transcript and composer when they live inside .chat-main */
.chat-main .transcript {
  margin-top: 0;
}

.chat-main .composer {
  margin-top: 0;
}

.avatar-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 250, 242, 0.9);
  padding: 0.55rem 0.65rem;
  min-height: 120px;
  overflow: hidden;
}

.avatar-panel-label {
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 0.45rem;
}

#avatar-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: calc(50vh - 60px);
  overflow-y: auto;
}

.avatar-item {
  font-size: 0.82rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0.18rem 0.1rem;
}

.matrix-modal {
  position: fixed;
  inset: 0;
  z-index: 62;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(14, 10, 8, 0.58);
  backdrop-filter: blur(3px);
}

.matrix-card {
  width: min(960px, 100%);
  max-height: min(92vh, 920px);
  display: grid;
  grid-template-rows: auto minmax(260px, 1fr) auto;
  gap: 0.65rem;
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  background: rgba(255, 253, 248, 0.98);
  box-shadow: 0 22px 52px rgba(40, 31, 22, 0.34);
  padding: 0.85rem;
}

.matrix-head h2 {
  margin: 0;
  font-size: 1.2rem;
  font-family: "Iowan Old Style", "Palatino Linotype", serif;
}

.matrix-head p {
  margin: 0.22rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.matrix-text {
  margin: 0;
  min-height: 260px;
  max-height: 62vh;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--text);
  padding: 0.75rem;
  overflow: auto;
  font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
  line-height: 1.42;
  white-space: pre-wrap;
  word-break: break-word;
}

.matrix-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

@media (max-width: 780px) {
  .shell {
    width: min(960px, calc(100% - 1.1rem));
    margin: 1.1rem auto;
  }

  .card,
  .chat {
    padding: 0.9rem;
    border-radius: 16px;
  }

  .grid-2,
  .setup-actions {
    grid-template-columns: 1fr;
  }

  .session-tools {
    justify-content: flex-start;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .chat-body {
    grid-template-columns: 1fr;
  }

  .lock-card {
    border-radius: 0;
    padding: 0;
  }

  .lock-banner {
    left: 0.65rem;
    top: 0.65rem;
    max-width: calc(100vw - 1.3rem);
    flex-direction: row;
    align-items: flex-start;
    padding: 0.5rem 0.65rem;
  }

  .lock-canvas {
    height: 100%;
  }

  .yaml-editor-card {
    padding: 0.7rem;
    max-height: 94vh;
  }

  .yaml-editor-actions {
    grid-template-columns: 1fr;
  }

  .matrix-actions {
    grid-template-columns: 1fr;
  }

  #avatar-list {
    max-height: 140px;
  }
}
