/* Sounding — chart-water palette, navy ink, buoy-amber signal */
:root {
  --water: #e8eef1;
  --paper: #ffffff;
  --ink: #14304a;
  --fathom: #4d6a80;
  --line: #c9d6de;
  --shoal: #d7e2e8;
  --buoy: #e5a823;
  --buoy-ink: #3d2a00;
  --danger: #b23a48;
  --add: #2f7d5b;
  --add-bg: #e3f2ea;
  --del-bg: #f8e4e7;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Newsreader', Georgia, 'Times New Roman', serif;
  --r-sm: 4px;
  --r-md: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --water: #0e1c28;
    --paper: #142636;
    --ink: #dce6ec;
    --fathom: #93aabb;
    --line: #26405a;
    --shoal: #1b3247;
    --buoy: #f0b93a;
    --buoy-ink: #241800;
    --danger: #e07383;
    --add: #7fcfa6;
    --add-bg: #173528;
    --del-bg: #3a1c23;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body {
  margin: 0;
  background: var(--water);
  color: var(--ink);
  font: 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--buoy); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .45rem .85rem; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--paper); cursor: pointer;
  font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--fathom); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--ink); color: var(--water); border-color: var(--ink); }
.btn-primary:hover { background: var(--fathom); border-color: var(--fathom); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--fathom); padding: .35rem .55rem; }
.btn-quiet:hover { color: var(--ink); border-color: var(--line); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); }
.field { display: grid; gap: .3rem; }
.field label { font-size: .85rem; color: var(--fathom); }
.input {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line);
  border-radius: var(--r-sm); background: var(--paper);
}
.input:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--buoy) 35%, transparent); }
.error-text { color: var(--danger); font-size: .9rem; min-height: 1.3em; margin: 0; }

/* ---------- Sign-in ---------- */
.auth {
  min-height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 440px);
}
.auth-chart {
  position: relative; overflow: hidden; padding: 3rem clamp(1.5rem, 5vw, 4rem);
  display: flex; flex-direction: column; justify-content: flex-end;
  background: var(--ink); color: var(--water);
}
.auth-chart svg { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .9; }
.auth-chart h1 {
  position: relative; margin: 0; font: 400 clamp(3rem, 8vw, 6.5rem)/0.95 var(--serif); letter-spacing: -.02em;
}
.auth-chart p { position: relative; max-width: 30rem; margin: 1rem 0 0; font-size: 1.05rem; color: color-mix(in srgb, var(--water) 75%, transparent); }
.auth-form { padding: 3rem clamp(1.5rem, 4vw, 3rem); display: flex; flex-direction: column; justify-content: center; gap: 1.1rem; background: var(--paper); }
.auth-form h2 { margin: 0; font: 500 1.6rem/1.2 var(--serif); }
.auth-switch { color: var(--fathom); font-size: .92rem; }
.auth-switch button { background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; color: var(--ink); }

/* ---------- App shell ---------- */
.shell { height: 100%; display: grid; grid-template-columns: 290px minmax(0, 1fr) 340px; }
.shell.panel-closed { grid-template-columns: 290px minmax(0, 1fr) 0; }
.sidebar { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); }
.sidebar-head { padding: 1rem 1rem .75rem; display: grid; gap: .6rem; }
.brand { display: flex; align-items: center; gap: .5rem; font: 500 1.25rem/1 var(--serif); }
.brand img { width: 22px; height: 22px; }
.vault-row { display: flex; gap: .35rem; }
.vault-row select { flex: 1; min-width: 0; }
.doc-list { list-style: none; margin: 0; padding: 0 .5rem 1rem; overflow-y: auto; flex: 1; }
.doc-item button {
  width: 100%; text-align: left; border: 0; background: none; cursor: pointer;
  padding: .6rem .7rem; border-radius: var(--r-sm); display: grid; gap: .1rem;
  border-left: 3px solid transparent;
}
.doc-item button:hover { background: var(--shoal); }
.doc-item.active button { background: var(--paper); border-left-color: var(--buoy); }
.doc-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-meta { font-size: .8rem; color: var(--fathom); }
.doc-excerpt { font: .86rem/1.35 var(--serif); color: var(--fathom); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.sidebar-foot { padding: .75rem 1rem; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: .5rem; font-size: .85rem; color: var(--fathom); }
.sidebar-foot span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 1.5rem 1rem; color: var(--fathom); }
.empty p { margin: 0 0 .8rem; }

/* ---------- Editor ---------- */
.editor { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }
.editor-bar {
  display: flex; align-items: center; gap: .5rem; padding: .6rem 1rem;
  border-bottom: 1px solid var(--line); min-height: 52px;
}
.save-state { margin-right: auto; font-size: .85rem; color: var(--fathom); display: flex; align-items: center; gap: .4rem; }
.save-state .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.save-state.dirty .dot { background: var(--buoy); }
.editor-body { flex: 1; overflow-y: auto; display: flex; justify-content: center; }
.editor-inner { width: 100%; max-width: 44rem; padding: 2.5rem 1.5rem 4rem; display: flex; flex-direction: column; }
.title-input {
  border: 0; background: none; padding: 0; margin-bottom: 1.25rem;
  font: 500 clamp(1.8rem, 3vw, 2.4rem)/1.15 var(--serif); letter-spacing: -.01em;
}
.title-input:focus { outline: none; }
.content-input {
  flex: 1; min-height: 60vh; border: 0; resize: none; background: none; padding: 0;
  font: 400 1.15rem/1.7 var(--serif);
}
.content-input:focus { outline: none; }
.welcome { margin: auto; max-width: 30rem; padding: 2rem; text-align: center; color: var(--fathom); }
.welcome h2 { font: 400 1.9rem/1.2 var(--serif); color: var(--ink); margin: 0 0 .6rem; }
.mobile-only { display: none; }

/* ---------- Side panel ---------- */
.panel { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel-closed .panel { display: none; }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 .5rem; }
.tab { border: 0; background: none; padding: .9rem .7rem .75rem; cursor: pointer; color: var(--fathom); border-bottom: 2px solid transparent; font-weight: 500; }
.tab-close { margin-left: auto; align-self: center; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.panel-body { padding: 1rem; overflow-y: auto; flex: 1; }
.panel-body h3 { font: 500 1.05rem/1.3 var(--serif); margin: 0 0 .6rem; }
.hint { color: var(--fathom); font-size: .88rem; margin: 0 0 1rem; }

/* The sounding line: version history as depth marks on a lead line */
.sounding { position: relative; list-style: none; margin: 0 0 1rem; padding: 0 0 2.2rem 0; }
.sounding::before {
  content: ''; position: absolute; left: 3.1rem; top: .2rem; bottom: 1.2rem; width: 2px; background: var(--ink);
}
.sounding::after { /* the lead weight */
  content: ''; position: absolute; left: calc(3.1rem - 6px); bottom: 0; width: 14px; height: 18px;
  background: var(--ink); clip-path: polygon(30% 0, 70% 0, 100% 100%, 0 100%); border-radius: 2px;
}
.mark { position: relative; }
.mark button {
  width: 100%; display: grid; grid-template-columns: 2.6rem 1.4rem 1fr; align-items: center;
  border: 0; background: none; cursor: pointer; padding: .45rem 0; text-align: left; border-radius: var(--r-sm);
}
.mark button:hover { background: var(--shoal); }
.mark-num { font: italic 400 1.25rem/1 var(--serif); text-align: right; font-variant-numeric: tabular-nums; }
.mark-tick { justify-self: start; margin-left: .5rem; width: .7rem; height: 2px; background: var(--ink); }
.mark-when { font-size: .85rem; color: var(--fathom); padding-left: .3rem; }
.mark.current .mark-num { color: var(--ink); font-weight: 500; }
.mark.current .mark-tick { width: 1rem; height: 4px; background: var(--buoy); margin-left: .25rem; }
.mark.selected button { background: var(--paper); box-shadow: inset 0 0 0 1px var(--line); }
.mark.archived .mark-num, .mark.archived .mark-when { opacity: .45; }

.version-view { border-top: 1px solid var(--line); padding-top: 1rem; }
.version-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin: .6rem 0 1rem; }
.diff { font: .92rem/1.5 var(--serif); border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--paper); max-height: 50vh; overflow: auto; }
.diff div { padding: 0 .6rem; white-space: pre-wrap; word-break: break-word; min-height: 1.4em; }
.diff .add { background: var(--add-bg); }
.diff .add::before { content: '+ '; color: var(--add); font-family: var(--sans); }
.diff .del { background: var(--del-bg); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.diff .del::before { content: '− '; color: var(--danger); font-family: var(--sans); text-decoration: none; display: inline-block; }
.diff .same { color: var(--fathom); }

.share-new { display: flex; gap: .4rem; margin-bottom: 1rem; }
.share-new select { flex: 1; }
.share-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .6rem; }
.share-item { border: 1px solid var(--line); border-radius: var(--r-sm); padding: .6rem .7rem; background: var(--paper); display: grid; gap: .35rem; }
.share-item.inactive { opacity: .6; }
.share-url { font-size: .82rem; word-break: break-all; color: var(--fathom); }
.share-row { display: flex; gap: .3rem; align-items: center; justify-content: space-between; font-size: .82rem; color: var(--fathom); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem .75rem; margin: 0 0 1.25rem; }
.stats div { display: grid; }
.stats dt { font-size: .8rem; color: var(--fathom); order: 2; }
.stats dd { margin: 0; font: 400 1.6rem/1.1 var(--serif); font-variant-numeric: tabular-nums; }
.export-row { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1.25rem; }

/* ---------- Shared document (public) ---------- */
.public { min-height: 100%; display: flex; justify-content: center; background: var(--paper); }
.public article { width: 100%; max-width: 42rem; padding: 3.5rem 1.5rem 5rem; }
.public h1 { font: 500 clamp(2rem, 4vw, 2.8rem)/1.15 var(--serif); margin: 0 0 .5rem; }
.public .meta { color: var(--fathom); font-size: .9rem; margin: 0 0 2.5rem; }
.public .body { font: 1.18rem/1.75 var(--serif); white-space: pre-wrap; word-break: break-word; }
.public footer { margin-top: 4rem; padding-top: 1rem; border-top: 1px solid var(--line); color: var(--fathom); font-size: .85rem; }

/* ---------- Dialog & toast ---------- */
dialog { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--paper); color: var(--ink); padding: 1.4rem; width: min(26rem, calc(100vw - 2rem)); }
dialog::backdrop { background: color-mix(in srgb, var(--ink) 40%, transparent); }
dialog h2 { margin: 0 0 .5rem; font: 500 1.3rem/1.25 var(--serif); }
dialog p { margin: 0 0 1rem; color: var(--fathom); }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.1rem; }
.dialog-actions-start { justify-content: flex-start; flex-wrap: wrap; }
#toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translate(-50%, 1rem); opacity: 0;
  background: var(--ink); color: var(--water); padding: .6rem 1rem; border-radius: var(--r-sm);
  transition: opacity .2s, transform .2s; pointer-events: none; max-width: calc(100vw - 2rem);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

.loading { display: grid; place-items: center; height: 100%; color: var(--fathom); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .shell, .shell.panel-closed { grid-template-columns: 260px minmax(0, 1fr); }
  .panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(360px, 100vw); background: var(--water); z-index: 5; box-shadow: -8px 0 24px color-mix(in srgb, var(--ink) 18%, transparent); }
}
@media (max-width: 760px) {
  .auth { grid-template-columns: 1fr; }
  .auth-chart { min-height: 38vh; padding: 2rem 1rem; }
  .auth-form { padding: 2rem 1rem; }
  .shell, .shell.panel-closed { grid-template-columns: 1fr; }
  .shell.viewing-doc .sidebar { display: none; }
  .shell:not(.viewing-doc) .editor { display: none; }
  .mobile-only { display: inline-flex; }
  .editor-inner { padding: 1.5rem 1rem 3rem; }
  .editor-bar { flex-wrap: wrap; padding: .5rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
.share-row > span:last-child { display: flex; flex-shrink: 0; }
