@font-face {
  font-family: "Atkinson Hyperlegible Next";
  src: url("/assets/atkinson.ttf") format("truetype");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --space: #050a17;
  --panel: #101d34;
  --field: #081326;
  --ink: #edf4ff;
  --muted: #becde3;
  --quiet: #a4b8d5;
  --edge: #3c5376;
  --line: #2e4361;
  --control: #172a46;
  --accent: #244e96;
  --accent-hover: #315fa8;
  --focus: #a0d4ff;
  --notice: #b6dcff;
  --error: #ffd2e0;
  font: 16px/1.5 "Atkinson Hyperlegible Next", Arial, sans-serif;
  color: var(--ink);
  background: var(--space);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, #050a1720 0%, #050a1757 35%, var(--space) 92%),
    url("/assets/nebula.webp") right top / auto clamp(580px, 100vh, 1050px) no-repeat,
    var(--space);
}

main {
  width: min(100% - 48px, 930px);
  margin: 0 auto;
  padding: clamp(72px, 13vh, 146px) 0 32px;
}

h1, h2, p { margin: 0; }

.masthead {
  margin: 0 auto clamp(30px, 5vw, 54px);
  text-align: center;
}

.masthead h1 {
  font-size: clamp(3rem, 7vw, 6.1rem);
  line-height: .96;
  letter-spacing: -.045em;
  text-wrap: balance;
}

.masthead p {
  margin: 18px auto 0;
  color: var(--muted);
  font-size: clamp(1.1rem, 2.4vw, 1.36rem);
  text-wrap: balance;
}

h2 {
  font-size: clamp(1.36rem, 3vw, 1.8rem);
  line-height: 1.14;
  letter-spacing: -.012em;
}

.panel {
  min-width: 0;
  border: 1px solid var(--edge);
  border-radius: 15px;
  background: var(--panel);
  box-shadow: 0 18px 65px #01081768;
}

.split-panel {
  display: grid;
  grid-template-columns: minmax(0, .86fr) minmax(0, 1fr);
  background: linear-gradient(118deg, #162745, var(--panel) 59%);
}

.split-panel > * { min-width: 0; padding: 28px clamp(21px, 4vw, 40px); }
.split-panel > :nth-child(2) { border-left: 1px solid var(--line); }
.panel-intro p { margin-top: 9px; color: var(--muted); }
.panel-intro { display: flex; flex-direction: column; justify-content: center; }
.split-panel form h2 { margin-bottom: 16px; }

label { display: block; margin-bottom: 5px; font-size: .99rem; font-weight: 650; }
input, button, textarea { font: inherit; }

input, textarea {
  display: block;
  width: 100%;
  min-width: 0;
  color: var(--ink);
  background: var(--field);
  border: 1px solid var(--edge);
  border-radius: 7px;
  padding: 9px 12px;
  min-height: 44px;
}

input::placeholder, textarea::placeholder { opacity: 1; color: var(--quiet); }
input:disabled, textarea:disabled { opacity: .73; }
.hint { margin-top: 6px; color: var(--quiet); font-size: .88rem; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .83rem; }

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 8px 14px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  background: var(--control);
  color: var(--ink);
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
}

button:hover:enabled { background: #223b61; }
button.primary { border-color: #527fc4; background: var(--accent); color: #f7fbff; }
button.primary:hover:enabled { background: var(--accent-hover); }
button:disabled, button.primary:disabled { border-color: var(--line); background: #14213a; color: var(--quiet); cursor: default; }
:is(input, button, textarea):focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 14px; }
.notice { margin-top: 10px; color: var(--notice); font-size: .92rem; overflow-wrap: anywhere; }
.notice:empty { margin: 0; }
.notice.error, .notice[data-tone="error"] { color: var(--error); }
.page-status { text-align: center; }

.account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px 18px;
  padding: 0 2px;
  margin-bottom: 14px;
  color: var(--muted);
}

.account p { overflow-wrap: anywhere; }
.account strong { color: var(--ink); }
.account button { flex-shrink: 0; }
.account .hint { margin-top: 1px; }
.account-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.lobby-intro { align-items: start; }
.lobby button, .invite-panel button { margin-top: 14px; }
.anchor-input { width: 100%; margin-top: 17px; }
.anchor-input .hint { margin-top: 9px; }
.anchor-input button { margin-top: 8px; }
.panel-intro .anchor-input .hint { color: var(--quiet); }

main:has(#room:not([hidden])) { padding-top: clamp(20px, 4.5vh, 46px); }
main:has(#room:not([hidden])) .masthead { margin-bottom: 24px; }
main:has(#room:not([hidden])) .masthead h1 { font-size: clamp(2.4rem, 5.2vw, 4rem); }
main:has(#room:not([hidden])) .masthead p { margin-top: 9px; font-size: 1rem; }

.room { overflow: hidden; }
.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 24px;
  background: linear-gradient(110deg, #162745, var(--panel));
  border-bottom: 1px solid var(--line);
}

.room-header h2 { font-size: 1.4rem; }
.room-status { margin-top: 3px; color: var(--notice); font-size: .91rem; }
.room-header button { flex-shrink: 0; }
.invite-panel { margin: 16px 24px 0; border: 1px solid var(--line); border-radius: 9px; background: #14223a; padding: 13px 15px; }
.invite-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.invite-row button { margin: 0; }

.session-anchor { margin: 12px 24px 0; color: var(--quiet); font-size: .88rem; }
.session-anchor summary { width: fit-content; cursor: pointer; }
.session-anchor summary:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.session-anchor p { margin-top: 6px; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }

.conversation { padding: 0 24px 20px; }
.message-area { position: relative; min-height: clamp(170px, 29vh, 280px); }
.empty-chat {
  position: absolute;
  inset: 20px;
  display: grid;
  place-content: center;
  padding: 10px;
  text-align: center;
  color: var(--quiet);
  pointer-events: none;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 9px;
  height: clamp(170px, 29vh, 280px);
  padding: 15px 7px 15px 0;
  margin: 0;
  list-style: none;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--edge) transparent;
}

.messages li {
  max-width: min(82%, 560px);
  align-self: flex-start;
  flex: 0 0 auto;
  padding: 8px 13px;
  color: var(--ink);
  background: #182b47;
  border: 1px solid var(--line);
  border-radius: 11px 11px 11px 4px;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.messages li.outgoing {
  align-self: flex-end;
  border-color: #385b92;
  background: #1b3661;
  border-radius: 11px 11px 4px 11px;
}

.message-meta { display: block; margin-bottom: 2px; color: var(--notice); font-size: .76rem; white-space: normal; }
.message-body { display: block; }
.message-attachment { display: grid; gap: 3px; white-space: normal; }
.message-filename { font-weight: 700; overflow-wrap: anywhere; }
.message-file-size { color: var(--muted); font-size: .88rem; }
.message-download { justify-self: start; margin-top: 5px; }

.compose { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 9px; padding-top: 13px; border-top: 1px solid var(--line); }
.compose textarea { min-height: 52px; max-height: 170px; resize: vertical; }
.compose-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
#send-button { min-width: 84px; }
.attachment-preview {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  gap: 11px;
  padding: 5px 5px 5px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--field);
  color: var(--muted);
}

#attachment-name { flex: 1; min-width: 0; overflow-wrap: anywhere; }
#remove-attachment { flex: 0 0 auto; }

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

footer { padding-top: 21px; text-align: center; color: var(--quiet); }
.privacy-facts { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 21px; font-size: .88rem; }
.local-label { margin-top: 7px; color: var(--quiet); font-size: .79rem; }

@media (max-width: 640px) {
  body { background-position: 0 0, 70% top, 0 0; }
  main { width: calc(100% - 28px); padding-top: clamp(36px, 11vw, 70px); }
  .masthead p { margin-top: 13px; }
  .split-panel { grid-template-columns: minmax(0, 1fr); }
  .split-panel > * { padding: 18px; }
  .split-panel > :nth-child(2) { border-left: 0; border-top: 1px solid var(--line); }
  .lobby button { margin-top: 11px; }
  .room-header { padding: 14px; }
  .invite-panel { margin: 12px 14px 0; }
  .session-anchor { margin-inline: 14px; }
  .conversation { padding: 0 14px 14px; }
  #send-button { min-width: 65px; }
  .privacy-facts { gap: 3px 14px; }
}

@media (max-width: 460px) {
  .compose:has(#attachment-controls:not([hidden])) { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 350px) {
  .invite-row { grid-template-columns: 1fr; }
  .actions { grid-template-columns: 1fr; }
}
