/* Kenji's Minimalist NoteTaker
   Direction: a Braun appliance (Dieter Rams is a stakeholder). Neutral grey body, ink for
   text and pressed states, round calculator-style keys, and one signal colour used in one
   place only: the New note key. Kenji's own words are always set in serif; the app's
   controls are set in sans, so his writing and the tool never look alike.
   Colours come from ui/Theme.js (checked for WCAG AA by tests/theme.test.js); the values
   below are only the first-paint fallback before JavaScript runs. */

:root {
  /* Dark is the default (Kenji's card lists dark mode as a need), so the first paint is dark. */
  --bg: #1b1b1a;
  --surface: #262624;
  --text: #e7e7e3;
  --muted: #a2a29c;
  --accent: #e7e7e3;
  --on-accent: #1b1b1a;
  --border: #7a7a74;
  --hairline: #30302e;
  --danger: #ff8b80;
  --signal: #f2c230;
  --on-signal: #1b1b1a;

  --sans: "Helvetica Neue", Helvetica, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --serif: Charter, "Bitstream Charter", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

  --measure: 38rem; /* ~70 characters of serif text */
  --page: 44rem;
  --gutter: max(1rem, env(safe-area-inset-left));
  --bar: 3.75rem;
  --key: 2.75rem;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: dark;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
html:not(.ready) body { visibility: hidden; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Frame ---------- */
.view { min-height: 100dvh; }

.page {
  max-width: var(--page);
  margin: 0 auto;
  padding: 0 var(--gutter) calc(6rem + env(safe-area-inset-bottom));
}

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  max-width: var(--page);
  height: calc(var(--bar) + env(safe-area-inset-top));
  margin: 0 auto;
  padding: env(safe-area-inset-top) var(--gutter) 0;
  background: var(--bg);
}

.bar-title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.bar-title-center {
  flex: 1;
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0;
  text-align: center;
}

.bar-actions { display: flex; align-items: center; gap: 0.35rem; }

/* ---------- Keys ---------- */
.icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--key);
  height: var(--key);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-btn:hover { background: var(--surface); }
.icon-btn-spacer { width: var(--key); }

.icon-btn svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn circle { fill: currentColor; stroke: none; }

/* The one signal colour: like the "=" key on a Braun calculator. */
.key-btn {
  background: var(--signal);
  color: var(--on-signal);
  box-shadow: inset 0 -2px 0 rgb(0 0 0 / 0.12);
}

.key-btn:hover { background: var(--signal); filter: brightness(0.96); }
.key-btn:active { box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.2); }
.key-btn svg { stroke-width: 2.25; }

.text-btn {
  min-height: var(--key);
  padding: 0 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.text-btn:hover { background: var(--surface); }
.text-btn.danger { border-color: transparent; color: var(--danger); }
.text-btn.danger:hover { border-color: var(--danger); background: transparent; }

/* ---------- Settings menu ---------- */
.menu {
  position: absolute;
  top: calc(var(--bar) + env(safe-area-inset-top) - 0.35rem);
  right: calc(var(--gutter) - 0.25rem);
  z-index: 20;
  display: grid;
  min-width: 15.5rem;
  padding: 0.35rem;
  border: 1px solid var(--hairline);
  border-radius: 14px;
  background: var(--bg);
  box-shadow: 0 1px 0 var(--hairline), 0 16px 40px -12px rgb(0 0 0 / 0.28);
}

.menu hr { width: calc(100% - 1.5rem); margin: 0.3rem auto; border: 0; border-top: 1px solid var(--hairline); }

.menu-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: var(--key);
  padding: 0 0.75rem;
  border: 0;
  border-radius: 10px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.menu-item:hover { background: var(--surface); }

.switch {
  position: relative;
  flex: none;
  width: 2.3rem;
  height: 1.35rem;
  border: 1.5px solid var(--border);
  border-radius: 999px;
}

.switch::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 0.15rem;
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  background: var(--border);
  transform: translateY(-50%);
}

[aria-checked="true"] > .switch { border-color: var(--accent); background: var(--accent); }
[aria-checked="true"] > .switch::after { background: var(--on-accent); transform: translate(0.95rem, -50%); }

/* ---------- Home ---------- */
.search {
  position: relative;
  margin: 0.5rem 0 0.75rem;
}

.search svg {
  position: absolute;
  top: 50%;
  left: 0.9rem;
  width: 1.05rem;
  height: 1.05rem;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
  stroke-linecap: round;
  transform: translateY(-50%);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: var(--key);
  padding: 0 1rem 0 2.5rem;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  box-shadow: inset 0 1px 2px rgb(0 0 0 / 0.06);
}

.search input::placeholder { color: var(--muted); opacity: 1; }
.search input:focus { outline: none; border-color: var(--accent); }
.search input::-webkit-search-cancel-button { cursor: pointer; }

.folders {
  display: flex;
  gap: 0.4rem;
  margin: 0 calc(-1 * var(--gutter)) 0.5rem;
  padding: 0 var(--gutter) 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
}

.chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  min-height: 2.25rem;
  padding: 0 0.9rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
}

.chip:hover { background: var(--surface); }
.chip[aria-pressed="true"],
.chip[aria-pressed="true"]:hover { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.chip-count { color: inherit; opacity: 0.75; font-variant-numeric: tabular-nums; }

.group { margin-top: 1.5rem; }

.group-title {
  margin: 0 0 0.15rem;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.notes { margin: 0; padding: 0; list-style: none; }

.note-item {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border-bottom: 1px solid var(--hairline);
}

.note-open {
  display: grid;
  flex: 1;
  min-width: 0;
  gap: 0.2rem;
  padding: 0.9rem 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.note-title {
  overflow: hidden;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

/* Kenji's own words, in the same serif as the editor. */
.note-preview {
  overflow: hidden;
  color: var(--muted);
  font: 400 0.95rem/1.45 var(--serif);
  white-space: nowrap;
  text-overflow: ellipsis;
}

button.note-open:hover .note-title { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }

.note-delete { flex: none; color: var(--muted); }
.note-delete:hover { color: var(--danger); }

/* With a mouse, delete floats over the end of the row only while you point at it,
   so previews can use the full width. */
@media (hover: hover) {
  .note-item { position: relative; }
  .note-delete {
    position: absolute;
    right: 0;
    opacity: 0;
    background: var(--bg);
    box-shadow: -1.5rem 0 1rem -0.25rem var(--bg);
  }
  .note-item:hover .note-delete,
  .note-delete:focus-visible { opacity: 1; }
  .note-delete:hover { background: var(--surface); }
}

.bin-link {
  display: block;
  margin: 2.5rem auto 0;
  padding: 0.5rem 0.75rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.9rem;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  cursor: pointer;
}

.bin-link:hover { color: var(--text); }

.empty {
  margin: 4rem auto;
  max-width: 20rem;
  color: var(--muted);
  font: 400 1.1rem/1.6 var(--serif);
  text-align: center;
}

.hint { margin: 0.25rem 0 0.5rem; color: var(--muted); font-size: 0.9rem; }

.bin-item { flex-wrap: wrap; padding-bottom: 0.75rem; }
.bin-item .note-open { flex-basis: 100%; padding-bottom: 0.5rem; cursor: default; }
.bin-item .note-preview { font: 400 0.9rem/1.45 var(--sans); } /* the app speaking, not Kenji */
.bin-actions { display: flex; gap: 0.25rem; }

/* Wide screens: month labels sit in their own column, like a Rams grid. */
@media (min-width: 56rem) {
  :root { --page: 52rem; }
  .group {
    display: grid;
    grid-template-columns: 9rem 1fr;
    gap: 1.5rem;
    margin-top: 2rem;
  }
  .group-title { padding-top: 1.05rem; }
}

/* ---------- Editor ---------- */
.word-count {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

#view-editor .bar { max-width: calc(var(--measure) + 2 * var(--gutter)); }

.format-toggle { font: 400 1.15rem/1 var(--serif); }
.format-toggle[aria-expanded="true"],
.format-toggle[aria-expanded="true"]:hover { background: var(--accent); color: var(--on-accent); }

.format-menu {
  position: sticky;
  top: calc(var(--bar) + env(safe-area-inset-top));
  z-index: 9;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  margin: 0 auto;
  padding: 0.25rem var(--gutter) 0.75rem;
  background: var(--bg);
  border-bottom: 1px solid var(--hairline);
}

.format-menu button {
  min-width: var(--key);
  min-height: var(--key);
  padding: 0 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  cursor: pointer;
}

.format-menu button.round { display: inline-grid; place-items: center; width: var(--key); padding: 0; font-size: 1.1rem; }
.format-menu svg { width: 1.3rem; height: 1.3rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.format-menu svg circle { fill: currentColor; stroke: none; }
.format-menu button:hover { background: var(--surface); }
.format-menu button[aria-pressed="true"],
.format-menu button[aria-checked="true"] { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.format-menu [data-style="HEADING"] { font-weight: 700; }

/* Phone: text styling on the first row, note options (word count, pin) on the second. */
.format-break { flex-basis: 100%; height: 0; }
@media (min-width: 40rem) { .format-break { display: none; } }

.segmented { display: inline-flex; }
.format-menu .segmented button { min-width: 0; }
.format-menu .segmented button:first-child { border-radius: 999px 0 0 999px; }
.format-menu .segmented button:last-child { margin-left: -1px; border-radius: 0 999px 999px 0; }
.format-menu [data-style="FONT_SERIF"] { font-family: var(--serif); }
.format-menu [data-style="FONT_SANS"] { font-family: var(--sans); }

.editor-page {
  position: relative;
  max-width: calc(var(--measure) + 2 * var(--gutter));
  padding-top: 1rem;
}

.editor {
  min-height: calc(100dvh - var(--bar) - 5rem);
  outline: none;
  font: 400 1.2rem/1.75 var(--serif);
  caret-color: var(--text);
  overflow-wrap: anywhere;
  hanging-punctuation: first;
}

.editor:focus-visible { outline: none; } /* the caret is the focus indicator for the writing area */

.editor.is-empty::before {
  content: attr(data-placeholder);
  position: absolute;
  color: var(--muted);
  pointer-events: none;
}

.editor p,
.editor div { margin: 0 0 0.85em; }

/* Headings switch to the app's sans, so structure reads differently from prose. */
.editor h2 {
  margin: 1.4em 0 0.35em;
  font: 700 1.35rem/1.3 var(--sans);
  letter-spacing: -0.02em;
}

.editor h2:first-child { margin-top: 0; }

/* Lists (D7). Markers sit outside the text, so wrapped lines align with the words, and
   numbers use equal-width digits, so 9. and 10. line up on the full stop. */
.editor ul,
.editor ol { margin: 0 0 0.85em; padding-left: 1.6em; }
.editor li { margin: 0 0 0.3em; padding-left: 0.2em; }
.editor li > p { margin: 0; }
.editor ul { list-style: disc; }
.editor ul ul { list-style: circle; }
.editor ol { font-variant-numeric: tabular-nums; }
.editor li::marker { color: var(--muted); }
.editor ol > li::marker { font: 400 0.95em/1 var(--sans); }
.editor [data-font="serif"], .editor font[face*="serif"]:not([face*="sans"]) { font-family: var(--serif); }
.editor [data-font="sans"], .editor font[face*="sans"] { font-family: var(--sans); }

/* ---------- Toast & errors ---------- */
.toast {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(1.25rem + env(safe-area-inset-bottom));
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: fit-content;
  max-width: calc(100% - 2rem);
  margin: 0 auto;
  padding: 0.35rem 1.1rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 0.95rem;
  box-shadow: 0 12px 32px -10px rgb(0 0 0 / 0.35);
}

.toast > span { padding: 0.45rem 0; }
.toast:has(.toast-action) { padding-right: 0.35rem; }

.toast-action {
  min-height: 2.5rem;
  padding: 0 1rem;
  border: 0;
  border-radius: 999px;
  background: var(--signal);
  color: var(--on-signal);
  font-weight: 600;
  cursor: pointer;
}

.fatal { max-width: var(--measure); margin: 20vh auto 0; padding: 0 var(--gutter); }
.fatal p { font: 400 1.1rem/1.6 var(--serif); }

/* ---------- Motion: only in answer to something Kenji did ---------- */
@media (prefers-reduced-motion: no-preference) {
  .switch::after { transition: transform 140ms var(--ease); }
  .format-menu:not([hidden]) { animation: drop 160ms var(--ease); }
  .menu:not([hidden]) { animation: drop 140ms var(--ease); }
  .toast:not([hidden]) { animation: rise 200ms var(--ease); }
}

@keyframes drop {
  from { opacity: 0; transform: translateY(-6px); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
}
