/* Strictly grayscale. Emphasis comes from weight, underline, and spacing — never hue. */
:root {
  --bg: #fafafa;
  --fg: #141414;
  --muted: #666;
  --faint: #999;
  --line: #dedede;
  --press: #e8e8e8;
  --panel: #fff;
  --select: #cfcfcf;
  --backdrop: rgba(0, 0, 0, 0.25);
  color-scheme: light;
  accent-color: #444;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121212;
    --fg: #e6e6e6;
    --muted: #9c9c9c;
    --faint: #6c6c6c;
    --line: #2c2c2c;
    --press: #242424;
    --panel: #1a1a1a;
    --select: #4a4a4a;
    --backdrop: rgba(0, 0, 0, 0.55);
    color-scheme: dark;
    accent-color: #bbb;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

::selection {
  background: var(--select);
  color: var(--fg);
}

[hidden] {
  display: none !important;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

input:focus-visible,
textarea:focus-visible {
  outline: none;
}

input,
textarea,
button {
  font: inherit;
  color: inherit;
  caret-color: var(--fg);
}

input:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 100px var(--bg) inset;
  -webkit-text-fill-color: var(--fg);
}

::placeholder {
  color: var(--faint);
  opacity: 1;
}

#app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--app-top, 0px);
  height: var(--app-h, 100dvh);
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.muted {
  color: var(--muted);
}

.msg {
  margin: 8px 20px;
  color: var(--muted);
  font-size: 14px;
}

.msg:empty {
  display: none;
}

.error {
  color: var(--fg);
  font-weight: 600;
}

/* ---- buttons ---- */

button,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 8px 18px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

button:active,
.btn:active {
  background: var(--press);
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.primary {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
  font-weight: 600;
}

button.primary:active {
  opacity: 0.8;
}

button.quiet,
.btn.quiet {
  border-color: transparent;
  color: var(--muted);
  padding: 8px 10px;
}

button.armed {
  color: var(--fg);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ---- config ---- */

.config {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 32px 20px;
  max-width: 440px;
  width: 100%;
}

.config label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
  color: var(--muted);
}

.config input {
  font-size: 16px;
  color: var(--fg);
  padding: 10px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.config input:focus {
  border-bottom-color: var(--fg);
}

.config .msg {
  margin: 0;
}

.row {
  display: flex;
  align-items: center;
  gap: 20px;
}

/* ---- capture ---- */

.capture-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 0;
}

.chip {
  min-height: 32px;
  padding: 4px 14px;
  font-size: 14px;
  color: var(--muted);
}

.chip.on {
  color: var(--fg);
  border-color: var(--fg);
  font-weight: 600;
}

.status {
  font-size: 13px;
  color: var(--faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.source-input {
  margin: 8px 20px 0;
  padding: 8px 0;
  font-size: 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}

.capture-text {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: 16px 20px;
  border: 0;
  resize: none;
  background: transparent;
  font-size: 20px;
  line-height: 1.55;
}

.bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
}

.bar .primary {
  min-width: 120px;
  min-height: 48px;
  font-size: 17px;
}

/* ---- list ---- */

.list-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 0 12px;
}

.tabs {
  display: flex;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.tab {
  padding: 10px 8px;
  font-size: 15px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
}

.tab.active {
  color: var(--fg);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 8px;
}

.page-title {
  font-size: 15px;
  font-weight: 600;
}

.search-row {
  padding: 6px 20px 8px;
}

.search {
  width: 100%;
  padding: 9px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--press);
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}

.list-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 12px 6px 20px;
  font-size: 13px;
  color: var(--faint);
}

.list-tools .count {
  flex: 1;
}

.sort {
  display: flex;
}

.sort button {
  min-height: 32px;
  padding: 4px 8px;
  border: 0;
  font-size: 13px;
  color: var(--faint);
}

.sort button.active {
  color: var(--fg);
  font-weight: 600;
}

.list-tools button.export {
  min-height: 32px;
  padding: 4px 16px;
  font-size: 14px;
}

.notes {
  list-style: none;
  margin: 0;
  padding: 0 0 8px;
}

.notes > li > a {
  display: flex;
  flex-direction: column;
  padding: 10px 20px;
  text-decoration: none;
}

.notes > li > a:active {
  background: var(--press);
}

.notes .t {
  font-weight: 600;
  overflow-wrap: anywhere;
}

.notes .l {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notes .day {
  padding: 18px 20px 2px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

.notes .day:first-child {
  padding-top: 8px;
}

/* Short-note rows (Fleeting, Archive, reference pages): every row is exactly two lines tall. */
.notes.short .short-row {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  min-height: 0;
  padding: 9px 20px;
  border: 0;
  border-radius: 0;
  background: none;
  font: inherit;
  text-align: left;
  text-decoration: none;
  white-space: normal;
  color: inherit;
  cursor: pointer;
  user-select: auto;
  -webkit-user-select: auto;
}

.notes.short .short-row:active {
  background: var(--press);
}

.clip {
  flex: 1;
  min-width: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
  /* min/max rather than height: Chrome's line-clamp sizes the box to its content and ignores height */
  min-height: calc(2 * 1.45em);
  max-height: calc(2 * 1.45em);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.short-row .aside {
  flex: none;
  padding-top: 2px;
  font-size: 12px;
  color: var(--faint);
}

.notes .pending {
  color: var(--faint);
}

.notes.short .pending .short-row {
  cursor: default;
}

.notes.short .expanded .short-row {
  display: block;
  cursor: pointer;
}

.notes.short .expanded .prose {
  font-size: 16px;
  line-height: 1.55;
}

.notes.short .expanded .prose > :first-child {
  margin-top: 0;
}

.notes.short .expanded .prose > :last-child {
  margin-bottom: 0;
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 12px 6px;
}

.row-actions button {
  min-height: 32px;
  font-size: 13px;
}

.notes > li > a.create {
  color: var(--muted);
}

.empty {
  margin: 16px 20px;
  color: var(--faint);
}

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

.list-foot {
  display: flex;
  gap: 18px;
  padding: 32px 20px calc(24px + env(safe-area-inset-bottom));
  font-size: 13px;
  color: var(--faint);
}

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

.ed-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  font-size: 14px;
}

.ed-bar button,
.ed-bar .btn {
  font-size: 14px;
  min-height: 36px;
}

.ed-bar .status {
  flex: 0 1 auto;
  min-width: 0;
  display: block;
  font-size: 13px;
  color: var(--faint);
  cursor: default;
}

.ed-bar .status.error {
  color: var(--fg);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.spacer {
  flex: 1;
}

.ed-title {
  width: 100%;
  padding: 12px 20px 4px;
  border: 0;
  background: transparent;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.ed-body {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: 8px 20px 24px;
  border: 0;
  resize: none;
  background: transparent;
  font-size: 18px;
  line-height: 1.7;
}

button.done-btn {
  min-height: 34px;
  padding: 4px 16px;
  margin-left: 4px;
  border-color: var(--fg);
  font-weight: 600;
}

/* Modes: reading shows the rendered note; editing shows title + textarea. */
.editor.reading .ed-title,
.editor.reading .refs-edit,
.editor.reading .ed-body,
.editor.reading .toolbar,
.editor.reading .done-btn,
.editor.editing .reader,
.editor.editing .read-actions {
  display: none;
}

.read-actions {
  display: flex;
  align-items: center;
}

.toolbar {
  display: none;
  gap: 6px;
  padding: 6px 12px;
  border-top: 1px solid var(--line);
  overflow-x: auto;
}

.toolbar .tool {
  min-height: 36px;
  min-width: 48px;
  padding: 4px 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
}

/* On touch devices, formatting keys sit above the keyboard while writing; the linked strip steps aside. */
@media (pointer: coarse) {
  .editor.editing.typing-body .toolbar {
    display: flex;
  }

  .editor.editing.typing .linked {
    display: none;
  }
}

/* ---- reading ---- */

.reader {
  padding: 12px 20px 64px;
  cursor: text;
  -webkit-user-select: text;
  user-select: text;
}

.read-title {
  margin: 0 0 16px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.read-title.placeholder,
.empty-note {
  color: var(--faint);
}

.prose {
  max-width: 38em;
  font-size: 18px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.prose > :first-child {
  margin-top: 0;
}

.prose p,
.prose ul,
.prose ol,
.prose blockquote,
.prose pre,
.prose .table-wrap {
  margin: 0 0 1em;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4,
.prose h5,
.prose h6 {
  margin: 1.6em 0 0.5em;
  line-height: 1.3;
  font-weight: 700;
}

.prose h1 { font-size: 1.45em; }
.prose h2 { font-size: 1.25em; }
.prose h3 { font-size: 1.1em; }
.prose h4,
.prose h5,
.prose h6 {
  font-size: 1em;
  color: var(--muted);
}

.prose ul,
.prose ol {
  padding-left: 1.4em;
}

.prose li {
  margin: 0.2em 0;
}

.prose li > ul,
.prose li > ol {
  margin: 0.2em 0 0;
}

.prose li::marker {
  color: var(--faint);
}

.prose li.task {
  list-style: none;
  margin-left: -1.4em;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 0.5em;
}

.prose li.task > input {
  width: 1.05em;
  height: 1.05em;
  margin: 0;
  flex: none;
  transform: translateY(0.12em);
  cursor: pointer;
}

.prose li.task > ul,
.prose li.task > ol {
  flex-basis: 100%;
  padding-left: 1.55em;
}

.prose li.task.checked > span {
  color: var(--faint);
  text-decoration: line-through;
  text-decoration-color: var(--faint);
}

.prose blockquote {
  padding: 0 0 0 1em;
  border-left: 2px solid var(--line);
  color: var(--muted);
}

.prose blockquote > :last-child {
  margin-bottom: 0;
}

.prose hr {
  margin: 2em 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.prose code {
  font: 0.85em/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--press);
}

.prose pre {
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--press);
  overflow-x: auto;
  cursor: text;
}

.prose pre code {
  padding: 0;
  background: none;
  font-size: 14px;
  white-space: pre;
}

.prose mark {
  color: inherit;
  background: var(--select);
  padding: 0 0.1em;
  border-radius: 2px;
}

.prose del {
  color: var(--muted);
}

.prose img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0.5em 0;
  border-radius: 6px;
  filter: grayscale(1);
}

.prose .table-wrap {
  overflow-x: auto;
}

.prose table {
  border-collapse: collapse;
  font-size: 0.9em;
}

.prose th,
.prose td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.prose th {
  font-weight: 600;
  border-bottom-color: var(--faint);
}

.prose a {
  text-decoration-thickness: 1px;
  text-decoration-color: var(--faint);
  text-underline-offset: 4px;
}

.prose a:hover,
.prose a:active {
  text-decoration-color: var(--fg);
}

.prose a.wikilink {
  font-weight: 600;
}

.prose a.wikilink.unresolved {
  font-weight: 400;
  color: var(--muted);
  text-decoration-style: dotted;
}

.prose a.external::after {
  content: "\2197";
  margin-left: 0.1em;
  font-size: 0.75em;
  color: var(--faint);
}

.from {
  margin: 0 12px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.from-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}

.from-bar button {
  font-size: 13px;
  min-height: 32px;
}

.from-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
}

.from-text {
  max-height: 30vh;
  overflow-y: auto;
  padding: 4px 8px 12px;
  white-space: pre-wrap;
  color: var(--muted);
}

.linked {
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

.linked button.linked-toggle {
  width: 100%;
  justify-content: flex-start;
  min-height: 36px;
  padding: 6px 20px;
  border-radius: 0;
  font-size: 13px;
}

.linked-body {
  max-height: 35vh;
  padding: 0 20px 12px;
  font-size: 14px;
}

.linked-group h3 {
  margin: 8px 0 2px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.linked-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.linked-group li a {
  display: inline-block;
  padding: 3px 0;
}

.linked-group p {
  margin: 2px 0;
}

a.unresolved {
  color: var(--muted);
  text-decoration-style: dotted;
}

/* ---- wikilink autocomplete ---- */

.ac {
  position: fixed;
  z-index: 20;
  list-style: none;
  margin: 0;
  padding: 4px 0;
  width: min(320px, calc(100vw - 16px));
  max-height: 280px;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
}

.ac li {
  padding: 9px 14px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ac li.active {
  background: var(--press);
  font-weight: 600;
}

/* ---- misc ---- */

.toast {
  position: fixed;
  z-index: 40;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.offscreen {
  position: fixed;
  top: 0;
  left: -9999px;
  opacity: 0;
}

/* ---- capture: reference suggestions ---- */

.source-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 14px 0;
}

.source-suggest button {
  min-height: 32px;
  max-width: 100%;
  padding: 4px 12px;
  border-color: var(--line);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- reference ---- */

.ref-head {
  padding: 12px 20px 4px;
}

.reference .ed-title {
  padding: 0 0 4px;
}

.ref-title {
  margin-bottom: 2px;
}

.ref-meta {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--faint);
}

.section-label {
  margin: 20px 20px 2px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--faint);
}

.ref-permanent {
  border-top: 1px solid var(--line);
  margin-top: 8px;
}

/* ---- editor: references ---- */

.note-refs {
  margin: -8px 0 18px;
  font-size: 14px;
  color: var(--faint);
}

.note-refs a {
  color: var(--muted);
  text-decoration-color: var(--faint);
}

.refs-edit {
  padding: 0 20px 4px;
}

.ref-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
}

.ref-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 1px 2px 1px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 13px;
  color: var(--muted);
}

.ref-chip > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ref-chip button {
  min-height: 26px;
  padding: 0 8px;
  font-size: 15px;
}

.refs-edit button.add-ref {
  min-height: 28px;
  padding: 2px 4px;
  font-size: 13px;
  color: var(--faint);
}

.ref-input {
  width: 100%;
  margin-top: 4px;
  padding: 6px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  font-size: 16px;
}

.refs-edit .source-suggest {
  padding: 6px 0 0;
}

.ref-add {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)) 20px;
  border-top: 1px solid var(--line);
}

.ref-add-text {
  flex: 1;
  min-width: 0;
  max-height: 320px;
  padding: 8px 0;
  border: 0;
  resize: none;
  background: transparent;
  font-size: 17px;
  line-height: 1.5;
}

.ref-add button {
  min-height: 40px;
}
