/* Midnight stationery: black ruled pages on a graphite desk, with frosted-glass bars floating above them.
   Red means "where the next line goes" and the mic. The cool blue is only for what you have selected and for focus. */
:root {
  color-scheme: dark;
  --desk: #0b0c0f;
  --desk-lift: #181b23;
  --paper: #000000;
  --paper-edge: rgba(255, 255, 255, 0.08);
  --rule: #2b3d58;
  --margin: #4c2226;
  --ink: #f7f7f4;
  --ink-soft: #a1a6af;
  --ink-faint: #666b74;
  --glass: rgba(22, 23, 28, 0.72);
  --glass-strong: rgba(15, 16, 19, 0.92);
  --panel: #1a1c21;
  --field: #0e0f12;
  --line: rgba(255, 255, 255, 0.1);
  --line-strong: rgba(255, 255, 255, 0.2);
  --marker: #ff5a47;
  --on-marker: #1a0603;
  --accent: #8ab4ff;
  --hl: rgba(255, 214, 64, 0.3);
  --shadow: 0 1px 1px rgba(0, 0, 0, 0.4), 0 12px 32px -8px rgba(0, 0, 0, 0.65);
  --ui: system-ui, -apple-system, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  --serif: KaTeX_Main, 'Latin Modern Roman', 'Times New Roman', serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --math: 19px;
  --row: 32px;
  --top: 60px;
  --rules-h: 928px;
  --label-q: 20px;
  --typer-h: 26px;
  --typer-font: 16px;
  --caret-h: 22px;
  --ghost-font: 13px;
  --wline-pad: 4px;
  --bad-h: 61px;
  --bad-font: 12px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--desk);
  color: var(--ink);
  font: 16px/1.4 var(--ui);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* A soft light from above, so the desk is not a flat slab. */
body {
  background-image: radial-gradient(1100px 560px at 50% -10%, var(--desk-lift), transparent 72%);
  background-attachment: fixed;
}

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

/* ---------- the pages ---------- */

#scroller {
  position: fixed;
  inset: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  padding: calc(max(12px, env(safe-area-inset-top)) + 64px) 0 260px;
  --s: 1;
}

#pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

/* The wrapper takes the scaled size; the sheet inside is always laid out at 816 x 1056 (Letter at 96 dpi). */
.page-wrap {
  position: relative;
  flex: none;
  width: calc(816px * var(--s));
  height: calc(1056px * var(--s));
}

.sheet {
  position: absolute;
  left: 0;
  top: 0;
  width: 816px;
  height: 1056px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--paper);
  box-shadow:
    0 0 0 1px var(--paper-edge),
    0 2px 4px rgba(0, 0, 0, 0.5),
    0 32px 60px -24px rgba(0, 0, 0, 0.9);
  transform: scale(var(--s));
  transform-origin: 0 0;
  cursor: text;
}

/* Narrow ruled: a line under each row. The spacing comes from layout.js, so the writing follows it. */
.rules {
  position: absolute;
  left: 0;
  right: 0;
  top: var(--top);
  height: var(--rules-h);
  background-image: linear-gradient(to bottom, transparent calc(100% - 1px), var(--rule) 0);
  background-size: 100% var(--row);
  pointer-events: none;
}

.margin {
  position: absolute;
  left: 62px;
  top: 0;
  bottom: 0;
  width: 1px;
  background: var(--margin);
  pointer-events: none;
}

.content {
  position: absolute;
  inset: 0;
}

.pageno {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 22px;
  color: #50545c;
  font: 13px/1 var(--serif);
  text-align: center;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- blocks ---------- */

.block {
  position: absolute;
  left: 0;
  top: 0;
  width: max-content;
  border-radius: 6px;
  font-size: var(--math);
  line-height: 1.2;
  color: var(--ink);
  white-space: nowrap;
  transform-origin: 0 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.block .katex-display {
  margin: 0;
  text-align: left;
}

.block .katex-display > .katex {
  text-align: left;
}

.probe {
  left: -100000px;
  visibility: hidden;
  pointer-events: none;
}

/* A long line, wrapped: each piece sits on its own ruled row(s). */
.wline {
  display: flex;
  align-items: flex-end;
  padding-bottom: var(--wline-pad);
}

/* Delete (or clear) this page. */
.page-del {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 2;
  min-height: 0;
  padding: 5px 12px;
  border-radius: 8px;
  background: transparent;
  color: var(--ink-faint);
  box-shadow: inset 0 0 0 1px var(--paper-edge);
  font-size: 13px;
  font-weight: 500;
}

.page-del:hover {
  color: var(--marker);
  box-shadow: inset 0 0 0 1px var(--marker);
}

/* Question, part and sub-part labels. */
.label {
  font-family: var(--serif);
}

.label.question {
  font-size: var(--label-q);
  font-weight: 700;
}

.label.part,
.label.subpart {
  color: rgba(247, 247, 244, 0.78);
}

.block.sel {
  outline: 1.5px solid var(--accent);
  outline-offset: 4px;
  box-shadow: 0 0 0 7px rgba(138, 180, 255, 0.12);
}

.block.bad {
  max-height: var(--bad-h);
  overflow: hidden;
  white-space: normal;
  border: 1.5px dashed var(--marker);
  padding: 4px 8px;
}

.block.bad .raw {
  font: var(--bad-font)/1.3 var(--mono);
  color: var(--marker);
  word-break: break-word;
}

.block.bad .msg {
  margin-top: 3px;
  font: 12px/1.3 var(--ui);
  color: var(--ink-soft);
}

/* Typing straight onto the page: the words sit on the line until the model has turned them into math. */
.typer {
  position: absolute;
  left: 0;
  top: 0;
  height: var(--typer-h);
  margin: 0;
  padding: 0 4px;
  border: 0;
  border-bottom: 1.5px dashed var(--ink-soft);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  caret-color: var(--marker);
  font: var(--typer-font)/var(--typer-h) var(--ui);
  outline: none;
}

.typer:focus-visible {
  outline: none;
}

.typer::placeholder {
  color: var(--ink-faint);
}

.typer.busy {
  color: var(--ink-soft);
  font-style: italic;
}

/* Where the next line will be written. */
.caret {
  position: absolute;
  left: 0;
  top: 0;
  width: 3px;
  height: var(--caret-h);
  border-radius: 2px;
  background: var(--marker);
  pointer-events: none;
}

/* The words just heard, shown where they will land while the model works. */
.ghost {
  position: absolute;
  left: 0;
  top: 0;
  max-width: 520px;
  padding: 3px 12px;
  border: 1.5px dashed var(--ink-soft);
  border-radius: 8px;
  color: var(--ink-soft);
  font-size: var(--ghost-font);
  font-style: italic;
  pointer-events: none;
}

/* Highlighter swipe over a block that was just changed. */
.block::before {
  content: '';
  position: absolute;
  inset: 2px -4px;
  z-index: -1;
  border-radius: 5px;
  background: var(--hl);
  opacity: 0;
  clip-path: inset(0 100% 0 0);
}

.block.hl::before {
  animation: sweep 1.9s ease-out forwards;
}

.block.pop {
  animation: pop 0.18s ease-out;
}

@keyframes sweep {
  0% {
    opacity: 1;
    clip-path: inset(0 100% 0 0);
  }
  35% {
    opacity: 1;
    clip-path: inset(0 0 0 0);
  }
  100% {
    opacity: 0;
    clip-path: inset(0 0 0 0);
  }
}

@keyframes pop {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

#empty {
  position: fixed;
  left: 50%;
  top: 34%;
  z-index: 1;
  margin: 0;
  width: min(440px, calc(100% - 48px));
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--ink-faint);
  font: italic 19px/1.6 var(--serif);
  pointer-events: none;
}

/* ---------- home: the notebooks, as covers ---------- */

#home {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: none;
  overflow-y: auto;
  padding: max(24px, env(safe-area-inset-top)) 20px 72px;
}

body[data-screen='home'] #home {
  display: block;
}

body[data-screen='home'] #scroller,
body[data-screen='home'] #bar,
body[data-screen='home'] #dock,
body[data-screen='home'] #editor,
body[data-screen='home'] #empty {
  display: none !important;
}

.home-inner {
  max-width: 940px;
  margin: 0 auto;
}

.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 0 34px;
}

.home-head h1 {
  margin: 0;
  font: 400 clamp(34px, 6vw, 46px) / 1.05 var(--serif);
  letter-spacing: -0.005em;
}

#syncState {
  position: relative;
  min-height: 32px;
  margin: 0 10px 0 auto;
  padding: 0 12px 0 24px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 13px;
  font-weight: 500;
}

#syncState::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 11px;
  width: 6px;
  height: 6px;
  margin-top: -3px;
  border-radius: 50%;
  background: var(--ink-faint);
}

#syncState[data-state='ok']::before {
  background: #6fd39a;
}

#syncState[data-state='syncing']::before {
  background: var(--accent);
  animation: breathe-dot 1.1s ease-in-out infinite;
}

#syncState[data-state='wrong'],
#syncState[data-state='unset'],
#syncState[data-state='error'] {
  color: var(--marker);
}

#syncState[data-state='wrong']::before,
#syncState[data-state='unset']::before,
#syncState[data-state='error']::before {
  background: var(--marker);
}

@keyframes breathe-dot {
  50% {
    opacity: 0.3;
  }
}

.home-head button.icon {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}

#nbList {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 30px 22px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* A cover is a small page: black, ruled, with the red margin line, and the name written on the first line. */
.nb {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.nb-open {
  --pad: 22px;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  aspect-ratio: 3 / 4;
  padding: var(--pad) 14px 0 36px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 5px 13px 13px 5px;
  background-color: #000;
  background-image: linear-gradient(to bottom, transparent calc(100% - 1px), rgba(43, 61, 88, 0.85) 0);
  background-size: 100% 26px;
  background-position: 0 var(--pad);
  color: var(--ink);
  text-align: left;
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.6),
    0 22px 30px -18px rgba(0, 0, 0, 0.95);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease;
}

.nb-open::before {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 22px;
  width: 1.5px;
  background: var(--marker);
  opacity: 0.6;
}

.nb-open::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 9px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.09), transparent);
}

.nb-open:hover {
  transform: translateY(-4px);
  border-color: var(--line-strong);
  box-shadow:
    0 2px 3px rgba(0, 0, 0, 0.6),
    0 30px 36px -18px rgba(0, 0, 0, 0.95);
}

.nb-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
  font: 400 22px/26px var(--serif);
  overflow-wrap: anywhere;
}

.nb-meta {
  position: absolute;
  inset: auto 0 0 0;
  padding: 22px 14px 12px 36px;
  background: linear-gradient(to top, #000 62%, transparent);
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.35;
}

.nb-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.nb-actions button,
.nb-actions button.quiet {
  min-height: 32px;
  padding: 0 9px;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  box-shadow: none;
  font-size: 13px;
  font-weight: 500;
}

.nb-actions button:hover {
  background: rgba(255, 255, 255, 0.07);
  color: var(--ink);
}

.nb-actions button.armed,
.nb-actions button.armed:hover {
  background: rgba(255, 90, 71, 0.14);
  color: var(--marker);
  box-shadow: inset 0 0 0 1px rgba(255, 90, 71, 0.55);
}

.nb-rename,
#newForm {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  aspect-ratio: 3 / 4;
  padding: 14px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 5px 13px 13px 5px;
}

.nb-rename input,
#newForm input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  font-size: 16px;
}

/* The dashed tile that makes a new one. */
#newBtn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  aspect-ratio: 3 / 4;
  padding: 0;
  border: 1.5px dashed var(--line-strong);
  border-radius: 5px 13px 13px 5px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  font-weight: 500;
  transition:
    color 0.2s ease,
    border-color 0.2s ease,
    background 0.2s ease;
}

#newBtn .plus {
  font: 300 38px/1 var(--serif);
}

#newBtn:hover {
  border-color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
}

#nbEmpty {
  margin: 30px 0 0;
  color: var(--ink-faint);
  font: italic 17px/1.6 var(--serif);
}

@media (max-width: 520px) {
  #home {
    padding-left: 16px;
    padding-right: 16px;
  }
  #nbList {
    gap: 26px 16px;
  }
  .nb-name {
    font-size: 20px;
  }
}

/* ---------- controls ---------- */

#bar {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  z-index: 4;
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

#bar > * {
  pointer-events: auto;
}

/* Everything that floats above the page is the same frosted glass. */
.cluster,
#heard,
.chip,
#kbBtn,
#delBtn,
.panel,
#toast,
dialog {
  border: 1px solid var(--line);
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(1.5);
  backdrop-filter: blur(22px) saturate(1.5);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.cluster {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  border-radius: 17px;
}

#nbName {
  display: none;
  max-width: 24ch;
  padding: 0 14px 0 6px;
  overflow: hidden;
  color: var(--ink-soft);
  font: 400 17px/1 var(--serif);
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 1000px) {
  #nbName {
    display: block;
  }
}

button {
  min-height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--ink);
  color: var(--desk);
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.1s ease;
}

button:active:not(:disabled) {
  transform: scale(0.97);
}

button.quiet {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--line-strong);
  font-weight: 500;
}

button.quiet:hover {
  background: rgba(255, 255, 255, 0.06);
}

button.txt {
  min-height: 42px;
  padding: 0 14px;
  background: transparent;
  color: var(--ink);
  font-size: 14.5px;
  font-weight: 500;
  white-space: nowrap;
}

button.txt:hover,
button.icon:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

button.icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 42px;
  min-height: 0;
  padding: 0;
  background: transparent;
  color: var(--ink);
  box-shadow: none;
}

button.icon:disabled {
  opacity: 0.3;
  cursor: default;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.panel {
  border-radius: 18px;
}

/* ---------- block editor ---------- */

#editor {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 66px);
  left: 50%;
  z-index: 5;
  width: min(520px, calc(100% - 24px));
  padding: 14px;
  transform: translateX(-50%);
  animation: drop 0.18s ease-out;
}

#said {
  margin: 0 0 10px;
  color: var(--ink-soft);
  font: italic 16px/1.4 var(--serif);
}

#said:empty {
  display: none;
}

#latexInput,
#tagInput,
dialog input,
dialog select {
  display: block;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--field);
  font-size: 16px;
}

#latexInput {
  font: 15px/1.5 var(--mono);
  resize: vertical;
}

#latexInput:focus,
#tagInput:focus,
dialog input:focus,
dialog select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(138, 180, 255, 0.2);
}

#tagRow {
  display: block;
  color: var(--ink-soft);
  font-size: 14px;
}

#tagInput {
  margin-top: 4px;
}

#latexErr {
  margin: 6px 0 0;
  color: var(--marker);
  font-size: 13px;
}

#latexErr:empty {
  display: none;
}

.row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.row.spread {
  justify-content: space-between;
}

@keyframes drop {
  from {
    opacity: 0;
    transform: translate(-50%, -6px);
  }
  to {
    opacity: 1;
    transform: translate(-50%, 0);
  }
}

/* ---------- dock: what was heard, where writing goes, the mic, and timing ---------- */

#dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  pointer-events: none;
}

#dock > * {
  pointer-events: auto;
}

#heard {
  max-width: min(640px, 100%);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 17px;
  text-align: center;
  animation: rise 0.16s ease-out;
}

#heard.interim {
  color: var(--ink-soft);
}

#heard.question {
  border-radius: 16px;
  border-color: rgba(255, 90, 71, 0.6);
}

/* The chip says where the next line goes, with the same red as the caret on the page. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 500;
}

.chip::before {
  content: '';
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--marker);
}

.chip:empty {
  display: none;
}

.chip:hover {
  color: var(--ink);
}

#dockRow {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  width: min(560px, 100%);
}

#kbBtn {
  justify-self: start;
  border-radius: 15px;
}

#kbBtn[aria-pressed='true'] {
  background: var(--ink);
  color: var(--desk);
}

/* The delete button sits opposite the keyboard button; the response time hangs under it without moving it. */
#dockRight {
  position: relative;
  justify-self: end;
}

#delBtn {
  border-radius: 15px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#delBtn.held {
  background: rgba(255, 255, 255, 0.14);
  transform: scale(0.94);
}

#timing {
  position: absolute;
  top: calc(100% + 6px);
  right: 2px;
  white-space: nowrap;
  color: var(--ink-faint);
  font-size: 12px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

#micWrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
}

/* An on/off switch: a red ring when off, solid red when on, with a glow that follows how loud you are. */
#mic {
  position: relative;
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  min-height: 0;
  padding: 0;
  border-radius: 50%;
  background: var(--glass-strong);
  color: var(--marker);
  box-shadow:
    inset 0 0 0 1.5px rgba(255, 90, 71, 0.9),
    var(--shadow);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#mic svg {
  width: 32px;
  height: 32px;
  stroke-width: 1.9;
}

#mic::after {
  content: '';
  position: absolute;
  inset: -4px;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 90, 71, 0.75) 58%, rgba(255, 90, 71, 0) 100%);
  opacity: 0;
  pointer-events: none;
}

#mic[aria-checked='true'] {
  background: var(--marker);
  color: var(--on-marker);
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

#mic[aria-checked='true']::after {
  opacity: calc(0.42 + var(--lvl, 0) * 0.58);
  transform: scale(calc(1.12 + var(--lvl, 0) * 0.7));
  transition:
    transform 0.08s linear,
    opacity 0.08s linear;
}

/* No loudness to follow (recording is off or has not started): breathe instead. */
#mic[aria-checked='true']:not(.lv)::after {
  animation: breathe 2.4s ease-in-out infinite;
}

@keyframes breathe {
  0%,
  100% {
    opacity: 0.35;
    transform: scale(1.1);
  }
  50% {
    opacity: 0.75;
    transform: scale(1.5);
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

#micState {
  color: var(--ink-soft);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1;
}

#micState.live {
  color: var(--marker);
  font-weight: 600;
}

/* ---------- toast and settings ---------- */

#toast {
  position: fixed;
  top: calc(max(12px, env(safe-area-inset-top)) + 66px);
  left: 50%;
  z-index: 10;
  max-width: min(520px, calc(100% - 24px));
  padding: 11px 18px;
  transform: translateX(-50%);
  border-radius: 14px;
  font-size: 15px;
  animation: drop 0.18s ease-out;
}

#toast.tap {
  cursor: pointer;
}

/* With the block editor open, messages go above the dock instead of on top of the editor. */
#editor:not([hidden]) ~ #toast {
  top: auto;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 150px);
}

#toast.error {
  border-color: rgba(255, 90, 71, 0.6);
  background: rgba(60, 22, 19, 0.82);
}

dialog {
  width: min(480px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 24px;
  border-radius: 22px;
  background: var(--glass-strong);
  color: var(--ink);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

dialog h2 {
  margin: 0 0 6px;
  font: 400 28px/1.2 var(--serif);
}

dialog label {
  display: block;
  margin-top: 14px;
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 500;
}

dialog input,
dialog select {
  margin-top: 5px;
  color: var(--ink);
  font-weight: 400;
}

dialog .hint {
  margin: 7px 0 0;
  color: var(--ink-faint);
  font-size: 13px;
  line-height: 1.45;
}

dialog .hint b {
  color: var(--ink-soft);
  font-weight: 600;
}

dialog hr {
  margin: 20px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
}

dialog .row {
  margin-top: 16px;
}

#testOut:empty {
  display: none;
}

#testOut {
  margin: 10px 0 0;
  font-size: 14px;
  overflow-wrap: anywhere;
}

#testOut.bad {
  color: var(--marker);
}

button.txt .abbr {
  display: none;
}

/* Narrow screens: keep the top bar on one line. */
@media (max-width: 640px) {
  #bar {
    flex-wrap: nowrap;
    gap: 6px;
  }
  .cluster {
    gap: 0;
    padding: 2px;
  }
  button.txt {
    padding: 0 6px;
    font-size: 14px;
  }
  button.txt .full {
    display: none;
  }
  button.txt .abbr {
    display: inline;
  }
  #bar button.icon {
    width: 36px;
  }
}

/* Very narrow phones: let the top bar use a second row rather than clip. */
@media (max-width: 380px) {
  #bar {
    flex-wrap: wrap;
  }
  #menu {
    margin-left: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .block.hl::before {
    animation: none;
    opacity: 0.8;
    clip-path: none;
  }
  .block.pop {
    animation: none;
  }
  #delBtn,
  #mic,
  #mic::after,
  #mic[aria-checked='true']::after,
  .nb-open,
  #newBtn,
  #syncState::before,
  #editor,
  #toast,
  #heard,
  button {
    animation: none !important;
    transition: none !important;
  }
  #mic[aria-checked='true']:not(.lv)::after {
    opacity: 0.55;
    transform: scale(1.3);
  }
}

#micDebug {
  margin: 10px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
}

#micDebug summary {
  cursor: pointer;
}

#micLog {
  max-height: 150px;
  margin: 8px 0 0;
  padding: 8px 10px;
  overflow: auto;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink-faint);
  font: 11px/1.5 ui-monospace, Menlo, monospace;
  white-space: pre-wrap;
}

/* ---------- Export as PDF (the browser's print, saved as a PDF) ----------
   Only the pages, one per sheet of Letter paper, as white paper with dark ink so they print and read well. */
@media print {
  @page {
    size: letter;
    margin: 0;
  }
  :root {
    --paper: #ffffff;
    --ink: #111111;
    --ink-soft: #444444;
    --ink-faint: #777777;
    --rule: #bccbe2;
    --margin: #e6a3a3;
  }
  * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  html,
  body {
    height: auto !important;
    overflow: visible !important;
    background: #ffffff !important;
  }
  body > *:not(#scroller) {
    display: none !important;
  }
  #scroller {
    position: static !important;
    overflow: visible !important;
    padding: 0 !important;
    --s: 1 !important;
  }
  #pages {
    display: block !important;
  }
  .page-wrap {
    width: 816px !important;
    height: 1056px !important;
    margin: 0 !important;
    break-after: page;
    page-break-after: always;
    break-inside: avoid;
  }
  .page-wrap:last-child {
    break-after: auto;
    page-break-after: auto;
  }
  .sheet {
    transform: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
  }
  .caret,
  .ghost,
  .typer,
  .page-del {
    display: none !important;
  }
  .block.sel,
  .block.hl {
    background: none !important;
    box-shadow: none !important;
  }
}
