:root {
  color-scheme: dark;
  font-family: 'Segoe UI', system-ui, sans-serif;
  color: #f3f5f8;
  background: #11141b;
  --surface: #14181f;
  --control: #1b2029;
  --line: #303744;
  --muted: #a5aebd;
  --gutter-color: #8794a7;
  --accent: #9ee0d3;
  --inset: clamp(.85rem, 3vw, 2rem);
  --gutter: 3.25rem;
  --code-padding: .875rem;
  --code-font: 'Cascadia Mono', Consolas, 'Liberation Mono', monospace;
  --code-line: 1.6rem;
}

* { box-sizing: border-box; }
body, p { margin: 0; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
a { color: var(--accent); text-underline-offset: .2em; }

.app-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  min-height: 3.5rem;
  padding: .5rem var(--inset);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand {
  flex: none;
  margin: 0;
  font: 650 1.25rem/1.25 var(--code-font);
  letter-spacing: -.04em;
}
.brand span { color: var(--accent); }
.app-role { color: var(--muted); font-size: .875rem; }

.shell {
  max-width: 70rem;
  padding: clamp(1rem, 3.5vw, 2.5rem) var(--inset) 2.5rem;
}
.stack { display: grid; gap: 1.35rem; }
#unlock { max-width: 26rem; }
#unlock-form { justify-items: start; gap: .7rem; }
#sender-key { width: 100%; }
label { font-size: .9rem; font-weight: 600; }
.connection label { display: block; margin-bottom: .5rem; }
.link-row { display: flex; gap: .5rem; }
.link-row button { flex: none; }
input, select {
  min-width: 0;
  padding: .52rem .7rem;
  border: 1px solid var(--line);
  border-radius: .38rem;
  background: var(--surface);
  color: inherit;
}
#link {
  flex: 1;
  font: .9rem/1.3 var(--code-font);
  color: var(--accent);
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .4rem .75rem;
  margin-bottom: .55rem;
}
.format-picker {
  display: flex;
  align-items: center;
  gap: .55rem;
  color: var(--muted);
  font-weight: 400;
}
.format-picker select { min-height: 2.25rem; padding-block: .3rem; }
.editor-field, .document-lines {
  --line-gutter: max(var(--gutter), calc(var(--line-number-width, 0ch) + 1rem + 1px));
}
.editor-field {
  position: relative;
  height: clamp(16rem, 38vh, 26rem);
  border: 1px solid var(--line);
  border-radius: .5rem;
  background: var(--surface);
  overflow: hidden;
}
.editor-field:focus-within { border-color: var(--accent); }
.code-lines, .editor-input { font: 1rem/var(--code-line) var(--code-font); tab-size: 4; }
.code-lines { padding-block: .7rem; color: #f3f5f8; }
.code-line {
  display: grid;
  grid-template-columns: var(--line-gutter) minmax(0, 1fr);
  min-height: var(--code-line);
}
.line-number {
  padding-inline: .35rem .65rem;
  border-right: 1px solid var(--line);
  color: var(--gutter-color);
  text-align: right;
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.line-number::before { content: attr(data-number); }
.line-text {
  min-width: 0;
  padding-inline: var(--code-padding);
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.editor-lines {
  position: absolute;
  inset: 0 0 0 0;
  overflow: hidden;
  pointer-events: none;
}
.editor-input {
  position: absolute;
  inset: 0 0 0 var(--line-gutter);
  width: calc(100% - var(--line-gutter));
  height: 100%;
  margin: 0;
  padding: .7rem var(--code-padding);
  border: 0;
  background: transparent;
  color: inherit;
  resize: none;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}
.editor-input:focus-visible { outline: 0; }
.editor-field[data-highlighted] .editor-input { color: transparent; caret-color: #f3f5f8; }
.editor-field[data-highlighted] .editor-input::selection { background: #377d9b6b; color: transparent; }
.editor-input::placeholder { color: var(--muted); }

.syntax-comment { color: #9eb19f; }
.syntax-string { color: #f5c88f; }
.syntax-keyword { color: #9dc5ff; }
.syntax-type, .syntax-function { color: #9ee0d3; }
.syntax-number, .syntax-literal { color: #d9b5fc; }
.syntax-operator { color: #f3a9b6; }
.syntax-heading { color: #a8caff; }

button {
  min-height: 2.6rem;
  padding: .45rem .68rem;
  border: 1px solid var(--line);
  border-radius: .38rem;
  background: var(--control);
  color: inherit;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: #596678; background: #262e3a; }
button.primary { background: var(--accent); color: #122a28; border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: #b5eee3; border-color: #b5eee3; }
button:disabled { opacity: .46; cursor: default; }
button[data-active] { color: #ffabb8; border-color: #954b5c; }
button.subtle { color: var(--muted); border-color: transparent; background: transparent; }
.actions { display: flex; flex-wrap: wrap; gap: .48rem; margin-top: .7rem; }
.status { color: var(--muted); font-size: .875rem; line-height: 1.5; }
.status:not(:empty) { margin-top: .45rem; }
.status[data-error] { color: #ffabb8; }
.preview { border-top: 1px solid var(--line); padding-top: .7rem; }
.preview summary { width: fit-content; color: var(--muted); font-size: .9rem; cursor: pointer; }
.preview-content { display: grid; gap: .65rem; margin-top: .7rem; }
.preview-content a { width: fit-content; font-size: .875rem; }
.preview iframe { display: block; width: 100%; min-height: 23rem; border: 1px solid var(--line); border-radius: .38rem; }

.viewer .app-bar { position: sticky; top: 0; z-index: 1; }
.text-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: .35rem .7rem; }
.toolbar-button { min-height: 2.15rem; background: transparent; font-weight: 500; }
.display { min-height: calc(100dvh - 3.5rem); }
.notice { padding: .85rem var(--inset); color: var(--muted); font: .95rem/1.5 var(--code-font); }
.document-lines { max-width: calc(110ch + var(--line-gutter) + 2 * var(--code-padding)); }
.text-wrap:focus-visible { outline-offset: -2px; }
.shared-image {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100dvh - 3.5rem);
  object-fit: contain;
  object-position: left top;
}

@media (max-width: 32rem) {
  :root { --gutter: 2.65rem; --code-padding: .65rem; }
  .line-number { padding-right: .45rem; }
  .text-actions { gap: .3rem .5rem; }
}
