/* Layout of this app. Colors and fonts come from the theme variables in
   css/themes.css (shared by every site: edit _theme/themes.css, then run
   _scripts/sync-theme.py). */

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 17px;
  color: var(--star);
  background: radial-gradient(ellipse at 50% -10%, var(--violet-soft) 0%, var(--void) 55%);
  /* No `background-attachment: fixed` here: body already has
     `overflow: hidden` below, so body itself never scrolls — there's
     nothing for "fixed" to hold still against. It was a no-op on desktop
     but a known trigger for repaint/ghosting glitches on mobile Chrome
     (worse layered under .panel's backdrop-filter blur), which is what
     the offset "double" panel in a phone screenshot turned out to be. */
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  transition: background 0.2s ease, color 0.2s ease;
}

#stars {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 1.5rem 1rem 1rem;
}

.topbar__sigil {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.topbar__title {
  position: relative;
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.3rem, 4.2vw, 2.1rem);
  letter-spacing: 0.06em;
  text-wrap: balance;
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold) 55%, #8a6a1a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.topbar__title span {
  -webkit-text-fill-color: initial;
  background: linear-gradient(180deg, var(--star) 0%, var(--star-dim) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.topbar__clock {
  position: absolute;
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--font-heading);
  font-size: 0.75rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--star-dim);
}

.topbar__user {
  position: absolute;
  left: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-heading);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--star-dim);
}

@media (max-width: 640px) {
  .topbar__user, .topbar__clock {
    position: static;
    transform: none;
  }

  /* Stack top-to-bottom (title, then account controls, then clock)
     instead of packing everything into one row and wrapping whatever
     doesn't fit. Wrapping alone wasn't enough: .topbar__user is a single
     flex item holding four controls (theme select, username, admin,
     sign out) with no wrap of its own, so on a narrow phone it — not its
     individual buttons — was the thing overflowing, spilling off both
     edges of the screen once centered. */
  .topbar {
    flex-direction: column;
    gap: 0.6rem;
    padding: 0.9rem 0.75rem 0.6rem;
  }

  .topbar__user {
    flex-wrap: wrap;
    justify-content: center;
    order: 2;
  }

  /* The phone's own status bar already shows the time (see any phone
     screenshot of this page) — a second clock here is pure vertical
     chrome competing with the note for space, not information the app
     alone provides. */
  .topbar__clock {
    display: none;
  }
}

.divider {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0 1.25rem 0.75rem;
  color: var(--gold);
}

.divider .line {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold) 50%, transparent);
  opacity: 0.55;
}

.divider .mark {
  font-size: 13px;
  opacity: 0.85;
  transform: rotate(45deg);
}

.layout {
  position: relative;
  z-index: 2;
  flex: 1;
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr); /* minmax: let toolbars scroll instead of widening the editor */
  gap: 1rem;
  padding: 0 1.25rem 1.25rem;
  min-height: 0;
}

.editor__back-mobile {
  display: none;
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 1fr;
  }

  /* Phone-width only: show the note list OR the open note, never both
     stacked — avoids scrolling past the whole list to reach the editor. */
  .layout.layout--note-selected .sidebar {
    display: none;
  }

  .layout:not(.layout--note-selected) .editor {
    display: none;
  }

  .editor__back-mobile {
    display: inline-flex;
  }
}

.panel {
  position: relative;
  background: linear-gradient(160deg, rgba(92, 42, 94, 0.22), rgba(45, 20, 68, 0.22));
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
}

.panel::before, .panel::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 1px solid var(--gold);
  opacity: 0.65;
  pointer-events: none;
}

.panel::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.panel::after  { bottom: -1px; right: -1px; border-left: none; border-top: none; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.9rem;
  min-height: 0;
}

.sidebar__controls {
  display: flex;
  gap: 0.5rem;
}

#search-input {
  flex: 1;
  min-width: 0;
}

input, textarea {
  background: rgba(19, 10, 31, 0.55);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  color: var(--star);
  font-family: var(--font-body);
  font-size: 1rem;
  padding: 0.5rem 0.65rem;
  outline: none;
}

input::placeholder, textarea::placeholder {
  color: var(--star-dim);
  opacity: 0.8;
}

input:focus, textarea:focus {
  border-color: var(--gold-bright);
  box-shadow: 0 0 0 2px var(--accent-tint);
}

a.btn { text-decoration: none; }

.btn {
  display: inline-block;
  cursor: pointer;
  font-family: var(--font-heading);
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--on-accent);
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  padding: 0.55rem 1rem;
  border-radius: 2px;
  border: none;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.15s ease;
  box-shadow: 0 0 0 rgba(230, 200, 102, 0);
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(230, 200, 102, 0.25);
}

.btn--ghost {
  background: transparent;
  color: var(--gold-bright);
  border: 1px solid var(--gold);
}

.btn--danger {
  color: var(--danger);
  border-color: var(--danger);
}

.btn--danger:hover {
  box-shadow: 0 6px 18px rgba(217, 102, 106, 0.25);
}

.tag-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.chip {
  cursor: pointer;
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.3rem 0.65rem;
  border-radius: 2px;
  border: 1px solid rgba(201, 162, 39, 0.4);
  background: transparent;
  color: var(--gold);
}

.chip--active {
  background: var(--accent-tint);
  color: var(--gold-bright);
  border-color: var(--gold-bright);
}

.note-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-right: 0.15rem;
}

.note-list__empty {
  color: var(--star-dim);
  text-align: center;
  padding: 2rem 0.5rem;
  font-style: italic;
}

.note-card {
  background: rgba(19, 10, 31, 0.5);
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--gold);
  border-radius: 3px;
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.15s;
}

.note-card:hover {
  transform: translateX(2px);
  box-shadow: 0 0 12px rgba(201, 162, 39, 0.25);
}

.note-card--active {
  box-shadow: 0 0 14px rgba(230, 200, 102, 0.35);
  border-color: var(--gold-bright);
}

.note-card--gold    { border-left-color: var(--gold-bright); }
.note-card--violet  { border-left-color: var(--violet-accent); }
.note-card--magenta { border-left-color: var(--magenta-accent); }
.note-card--rose    { border-left-color: var(--rose-accent); }
.note-card--star    { border-left-color: var(--star); }

.note-card__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.note-card__title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-card__pin {
  background: none;
  border: none;
  color: var(--gold-bright);
  padding: 0;
  font-size: 1rem;
  cursor: pointer;
}

.note-card__snippet {
  color: var(--star-dim);
  font-size: 0.9rem;
  margin: 0.35rem 0;
}

.note-card__meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-heading);
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--star-dim);
}

.note-card__delete {
  background: none;
  border: none;
  color: var(--star-dim);
  padding: 0;
  cursor: pointer;
  font-family: var(--font-body);
}

.note-card__delete:hover {
  color: var(--danger);
}

.editor {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1.25rem;
}

@media (max-width: 720px) {
  /* Every rem of padding here is a rem the textarea below the toolbars
     doesn't get, and on a phone — especially with the keyboard up — that
     trade isn't worth it. */
  .editor {
    padding: 0.75rem;
  }
}

.editor__empty {
  margin: auto;
  color: var(--star-dim);
  font-family: var(--font-heading);
  font-size: 1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.editor__form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  height: 100%;
}

.editor__title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--panel-border);
  border-radius: 0;
  color: var(--gold-bright);
  padding: 0.25rem 0.1rem 0.5rem;
}

.editor__toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.color-picker {
  display: flex;
  gap: 0.4rem;
}

.swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  padding: 0;
  border: 1px solid rgba(237, 227, 245, 0.4);
  cursor: pointer;
}

.swatch--active {
  box-shadow: 0 0 0 2px var(--star), 0 0 8px currentColor;
}

.swatch--gold    { background: var(--gold-bright); }
.swatch--violet  { background: var(--violet-accent); }
.swatch--magenta { background: var(--magenta-accent); }
.swatch--rose    { background: var(--rose-accent); }
.swatch--star    { background: var(--star); }

.swatch--custom {
  background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red);
  color: var(--void);
  font-size: 11px;
  line-height: 16px;
  text-align: center;
}

.colorpicker {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.colorpicker__wheel-wrap,
.colorpicker__bar-wrap {
  position: relative;
}

.colorpicker__wheel {
  border-radius: 50%;
  cursor: crosshair;
  display: block;
  touch-action: none;
}

.colorpicker__thumb {
  position: absolute;
  top: 0;
  left: 0;
  width: 14px;
  height: 14px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.colorpicker__bar {
  border-radius: 4px;
  cursor: pointer;
  display: block;
  touch-action: none;
}

.colorpicker__bar-thumb {
  position: absolute;
  top: 0;
  left: -3px;
  right: -3px;
  height: 4px;
  border: 2px solid #fff;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  transform: translateY(-50%);
}

.colorpicker__preview {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  border: 1px solid var(--panel-border);
  flex-shrink: 0;
}

.colorpicker__fields {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.colorpicker__field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--star-dim);
}

.colorpicker__field input {
  width: 70px;
}

.colorpicker__field--hex input {
  width: 100px;
  text-transform: none;
}

.editor__tags {
  flex: 1;
  min-width: 120px;
  /* Anything below 16px makes iOS/Android auto-zoom the whole page on
     focus, forcing a manual pinch back out — this field was the one
     writing-flow input still under that threshold. */
  font-size: 1rem;
}

.save-status {
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--star-dim);
  font-style: italic;
  min-width: 70px;
}

.editor__presence {
  font-size: 0.75rem;
  color: var(--gold-bright);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.editor__preview {
  margin-left: auto;
}

.editor__shared-banner {
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--star-dim);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 0.35rem 0.6rem;
  margin-bottom: 0.5rem;
}

.editor__share-hint {
  font-size: 0.75rem;
  color: var(--star-dim);
  margin: 0;
}

.editor__share-link {
  flex: 1;
  min-width: 160px;
  font-size: 1rem; /* same auto-zoom-on-focus reason as .editor__tags above */
}

.editor__attachments {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 140px;
  overflow-y: auto;
  flex-shrink: 0;
}

.editor__attachments-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.editor__attachments-title {
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--star-dim);
  margin-right: auto;
}

.attachment-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.attachment-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  padding: 0.2rem 0;
}

.attachment-row__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--gold-bright);
  text-decoration: none;
}

.attachment-row__name:hover {
  text-decoration: underline;
}

.attachment-row__size {
  color: var(--star-dim);
  font-size: 0.75rem;
  white-space: nowrap;
}

.attachment-row__remove {
  background: none;
  border: none;
  color: var(--star-dim);
  cursor: pointer;
  padding: 0 0.2rem;
  font-size: 0.9rem;
}

.attachment-row__remove:hover {
  color: var(--danger);
}

.editor__content {
  flex: 1;
  resize: none;
  font-size: 1.05rem;
  line-height: 1.6;
  min-height: 200px;
}

.editor__field-wrap {
  position: relative;
}

.editor__field-wrap--grow {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* Other people's live cursor position, overlaid on top of the plain
   textarea/input — a native <textarea> can't host DOM children inside its
   text, so this is positioned via a hidden "mirror" element that copies the
   field's exact text layout and reports where that offset lands on screen. */
.remote-cursor {
  position: absolute;
  top: 0;
  left: 0;
  width: 2px;
  pointer-events: none;
  transition: top 0.1s linear, left 0.1s linear;
}

.remote-cursor__flag {
  position: absolute;
  top: -1.1em;
  left: 0;
  font-family: var(--font-heading);
  font-size: 0.6rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  padding: 0.05em 0.35em;
  border-radius: 2px;
  color: var(--void);
  transform: translateX(-2px);
}

.editor__format-toolbar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.editor__format-toolbar .btn {
  padding: 0.35rem 0.6rem;
  min-width: 2rem;
}

.editor__md-preview-toggle {
  margin-left: auto;
}

@media (max-width: 720px) {
  /* .editor__toolbar and .editor__format-toolbar carry ~15 controls
     between them (color swatches, tags, share/delete, bold/italic/
     heading/lists/link, font & size pickers, checklist, preview). Left to
     wrap, that's 4-5 stacked rows of chrome standing between "open a note"
     and "see the textarea" — on a phone, with the on-screen keyboard then
     eating another third of the viewport, there's barely a line of the
     actual note left to type into. Scroll them horizontally instead:
     everything stays reachable, but the content field claims the vertical
     space right under the title.
     This has to come after the base rules above (not in the earlier
     phone-breakpoint block near .layout) — same selector, same
     specificity, so source order alone decides the winner, and a rule
     placed before flex-wrap: wrap loses to it even inside a matching
     media query. */
  .editor__toolbar,
  .editor__format-toolbar {
    /* overflow-x makes a flex item's min-height 0, so without this a tall
       checklist/table squashes these rows down to nothing. */
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.3rem;
  }

  .editor__toolbar > *,
  .editor__format-toolbar > * {
    flex-shrink: 0;
  }

  .editor__md-preview-toggle {
    margin-left: 0;
  }
}

.editor__content-preview {
  flex: 1;
  min-height: 200px;
  overflow-y: auto;
  padding: 0.6rem 0.1rem;
  line-height: 1.6;
}

.editor__content-preview h1,
.editor__content-preview h2,
.editor__content-preview h3 {
  font-family: var(--font-heading);
  color: var(--gold-bright);
  margin: 0.6em 0 0.3em;
}

.editor__content-preview p {
  margin: 0 0 0.75em;
}

.editor__content-preview ul,
.editor__content-preview ol {
  margin: 0 0 0.75em;
  padding-left: 1.4em;
}

.editor__content-preview li {
  margin: 0.2em 0;
}

.editor__content-preview li > ul,
.editor__content-preview li > ol {
  margin: 0.2em 0;
}

.editor__content-preview li.task-list-item {
  list-style: none;
}

.editor__content-preview li.task-list-item input[type="checkbox"] {
  margin-right: 0.4em;
}

.editor__content-preview code {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 2px;
  padding: 0.1em 0.3em;
  font-family: var(--font-mono, monospace);
}

.editor__content-preview pre code {
  display: block;
  padding: 0.6em;
  overflow-x: auto;
}

.editor__content-preview blockquote {
  border-left: 2px solid var(--panel-border);
  margin: 0 0 0.75em;
  padding-left: 0.75em;
  color: var(--star-dim);
}

.editor__content-preview a {
  color: var(--gold-bright);
}

.editor__content-checklist {
  flex: 1;
  min-height: 200px;
  overflow-y: auto;
  padding: 0.6rem 0.1rem;
}

/* One grid for the whole list, with each row and the column header as a
   subgrid, so every checkbox column lines up under its name however long
   the names are. Column count comes from js/checklist.js. */
.checklist {
  display: grid;
  grid-template-columns: repeat(var(--checklist-columns, 1), minmax(1.6rem, max-content)) minmax(0, 1fr) auto;
  column-gap: 0.5rem;
  row-gap: 0.35rem;
}

.checklist__item,
.checklist__header,
.checklist__column-editor {
  grid-column: 1 / -1;
}

.checklist__item,
.checklist__header {
  display: grid;
  grid-template-columns: subgrid;
  align-items: center;
}

.checklist__item {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.15);
}

.checklist__header {
  /* Same horizontal padding + border width as an item, so labels sit
     exactly above their checkboxes. */
  padding: 0 0.5rem;
  border: 1px solid transparent;
}

.checklist__column-label {
  justify-self: center;
  max-width: 7rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: none;
  border: none;
  border-bottom: 1px dashed transparent;
  padding: 0.2rem 0.1rem;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gold-bright);
}

button.checklist__column-label {
  cursor: pointer;
}

button.checklist__column-label:hover,
.checklist__column-label--active {
  border-bottom-color: currentColor;
}

.checklist__header-tail {
  grid-column: span 2;
  display: flex;
  justify-content: flex-end;
}

.checklist__add-column {
  background: none;
  border: none;
  color: var(--star-dim);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.8rem;
  padding: 0.2rem 0.3rem;
}

.checklist__add-column:hover {
  color: var(--gold-bright);
}

.checklist__column-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border: 1px dashed var(--panel-border);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
}

.checklist__column-name-input {
  flex: 1 1 8rem;
  min-width: 0;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--panel-border);
  padding: 0.3rem 0;
  color: var(--star);
  font-family: var(--font-body);
  font-size: 1rem;
}

.checklist__column-name-input:focus {
  outline: none;
  border-bottom-color: var(--gold-bright);
}

.checklist__column-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.checklist__column-swatch {
  width: 1.3rem;
  height: 1.3rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.checklist__column-swatch--theme {
  background: var(--gold-bright);
}

.checklist__column-swatch--active {
  border-color: var(--star);
  box-shadow: 0 0 0 1px var(--panel-border);
}

.checklist__column-actions {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
}

.checklist__column-remove:hover {
  color: var(--danger);
}

.checklist__checkbox-wrap {
  justify-self: center;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* The visible checkbox stays small (matches the text); the label's
     padding pads out the *tappable* area without changing how it looks.
     Kept modest (not the full ~44px target) so the padded hit area of one
     row doesn't bleed into its neighbor across the list's 0.35rem gap. */
  padding: 0.5rem;
  margin: -0.5rem;
  cursor: pointer;
}

.checklist__checkbox {
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--gold-bright);
}

.checklist__text,
.checklist__text-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--star);
}

.checklist__text {
  word-break: break-word;
}

.checklist__item--checked .checklist__text {
  color: var(--star-dim);
  text-decoration: line-through;
}

.checklist__text--editable {
  cursor: text;
  min-height: 1.6rem;
  padding: 0.4rem 0;
}

.checklist__text a,
.sheet__cell a {
  color: var(--gold-bright);
}

.checklist__text-input {
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 0.4rem 0;
}

.checklist__text-input:focus {
  outline: none;
  border-bottom-color: var(--gold-bright);
}

.checklist__remove {
  flex: none;
  background: none;
  border: none;
  color: var(--star-dim);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.55rem;
  margin: -0.2rem -0.3rem -0.2rem 0;
  min-width: 2.2rem;
  min-height: 2.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.checklist__remove:hover {
  color: var(--danger);
}

.checklist__empty {
  color: var(--star-dim);
  font-style: italic;
  padding: 0.5rem;
}

.checklist__add-row {
  margin-top: 0.5rem;
}

.checklist__add-input {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px dashed var(--panel-border);
  border-radius: 4px;
  padding: 0.4rem 0.6rem;
  color: var(--star);
  font-family: var(--font-body);
  font-size: 1rem; /* was 0.95rem — too close to the 16px auto-zoom floor */
}

.checklist__add-input:focus {
  outline: none;
  border-color: var(--gold-bright);
  border-style: solid;
}

@media (max-width: 480px) {
  /* Roomier rows and bigger tap targets once a mouse pointer is no longer
     the assumption — thumbs need more room than a cursor does. */
  .checklist {
    row-gap: 0.55rem;
  }

  .checklist__item {
    padding: 0.5rem 0.6rem;
  }

  .checklist__checkbox {
    width: 1.3rem;
    height: 1.3rem;
  }

  .checklist__remove {
    font-size: 1.05rem;
  }

  .checklist__add-input {
    padding: 0.6rem 0.7rem;
  }
}

/* ---------- table mode (js/table.js) ----------
   Only theme variables, so every theme (and new ones) styles it for free. */
.editor__content-table {
  flex: 1 1 auto;
  /* Room for the formula bar, two rows of tools and a usable grid, so
     the sheet never spills over the attachments below it. */
  min-height: 360px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.4rem 0.1rem 0;
  min-width: 0;
}

.sheet__bar {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.2);
  font-family: var(--font-body);
}

.sheet__name {
  flex: none;
  min-width: 5.5rem;
  padding: 0.35rem 0.6rem;
  border-right: 1px solid var(--panel-border);
  color: var(--gold-bright);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  white-space: nowrap;
}

.sheet__fx {
  flex: none;
  padding: 0.35rem 0.5rem;
  color: var(--star-dim);
  font-style: italic;
  border-right: 1px solid var(--panel-border);
}

.sheet__formula {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  padding: 0.35rem 0.6rem;
  color: var(--star);
  font-family: var(--font-mono);
  font-size: 1rem; /* at least 16px: iOS zooms into smaller inputs */
}

/* Some themes uppercase inputs; formulas and source text must show as typed. */
.sheet__formula,
.sheet__input,
.checklist__text-input {
  text-transform: none;
}

.sheet__formula:focus {
  outline: 1px solid var(--gold-bright);
  outline-offset: -1px;
}

.sheet__tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.sheet__tool {
  padding: 0.2rem 0.6rem;
  font-size: 0.85rem;
}

.sheet__scroll {
  flex: 1 1 0;
  min-height: 180px;
  overflow: auto;
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.15);
  outline: none;
  overscroll-behavior: contain;
}

.sheet__scroll:focus-visible {
  border-color: var(--gold-bright);
}

.sheet__grid {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--star);
  user-select: none;
}

.sheet__grid th,
.sheet__grid td {
  height: 1.9rem;
  border-right: 1px solid var(--panel-border);
  border-bottom: 1px solid var(--panel-border);
  padding: 0 0.4rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sheet__grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

.sheet__col-head,
.sheet__row-head,
.sheet__corner {
  background: var(--panel);
  color: var(--star-dim);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  text-align: center;
  cursor: pointer;
  /* Headers stick over scrolling cells, and --panel is see-through in
     most themes: lay it over the opaque page color. */
  background: linear-gradient(var(--panel), var(--panel)), var(--void);
}

.sheet__col-head {
  width: 7rem;
  min-width: 7rem;
  max-width: 7rem;
}

.sheet__row-head,
.sheet__corner {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 2.6rem;
  min-width: 2.6rem;
}

.sheet__corner {
  z-index: 3;
  cursor: default;
}

.sheet__head--on {
  color: var(--gold-bright);
  background: linear-gradient(var(--accent-tint), var(--accent-tint)), linear-gradient(var(--panel), var(--panel)), var(--void);
}

.sheet__cell {
  cursor: cell;
  max-width: 7rem;
}

.sheet__cell--number,
.sheet__cell--bool {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sheet__cell--bool {
  text-align: center;
}

.sheet__cell--error {
  color: var(--danger);
  text-align: center;
}

.sheet__cell--selected {
  background: var(--accent-tint, rgba(255, 255, 255, 0.08));
}

.sheet__cell--active {
  box-shadow: inset 0 0 0 2px var(--gold-bright);
}

.sheet__cell--editing {
  padding: 0;
  overflow: visible;
}

.sheet__input {
  width: 100%;
  min-width: 100%;
  height: 100%;
  border: none;
  padding: 0 0.4rem;
  background: var(--panel);
  color: var(--star);
  font: inherit;
  font-family: var(--font-mono);
  outline: 2px solid var(--gold-bright);
  outline-offset: -2px;
}

@media (max-width: 720px) {
  .sheet__col-head {
    width: 5.5rem;
    min-width: 5.5rem;
    max-width: 5.5rem;
  }

  .sheet__cell {
    max-width: 5.5rem;
  }

  .sheet__grid th,
  .sheet__grid td {
    height: 2.3rem;
  }

  .sheet__input {
    font-size: 1rem;
  }
}

/* Fixed, sanitizer-safe formatting classes the toolbar inserts — never raw
   inline `style`, since CSS values inside a style attribute aren't reliably
   vetted for injection by the sanitizer even though the markup itself is. */
.md-size-sm  { font-size: 0.8em; }
.md-size-lg  { font-size: 1.3em; }
.md-size-xl  { font-size: 1.8em; }
.md-font-serif   { font-family: Georgia, 'Times New Roman', serif; }
.md-font-sans    { font-family: Arial, Helvetica, sans-serif; }
.md-font-mono    { font-family: 'JetBrains Mono', monospace; }
.md-font-cursive { font-family: 'Brush Script MT', cursive; }

/* Theme switcher — a dropdown so more themes can be added without crowding the UI */
.theme-select {
  cursor: pointer;
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  background: rgba(19, 10, 31, 0.4);
  color: var(--star-dim);
  font-family: var(--font-heading);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 0.3rem 1.6rem 0.3rem 0.7rem;
  outline: none;
  transition: border-color 0.15s ease, color 0.15s ease;
}

@media (max-width: 720px) {
  /* This select is used both as the small decorative theme picker and as
     the font/size pickers inside the format toolbar — its 0.65rem
     (~11px) is well under the 16px floor that keeps iOS/Android from
     auto-zooming the page on focus. Scoped to mobile rather than changed
     globally so the compact pill look in the topbar is untouched on
     desktop, where nothing auto-zooms anyway. */
  .theme-select {
    font-size: 1rem;
  }
}

.theme-select:hover,
.theme-select:focus {
  border-color: var(--gold-bright);
  color: var(--gold-bright);
}

.theme-select option {
  background: var(--void);
  color: var(--star);
  text-transform: none;
  letter-spacing: 0;
}

.auth-theme-switch {
  display: flex;
  justify-content: center;
  margin-bottom: 1.25rem;
}

/* Auth screen */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  position: relative;
  width: 100%;
  max-width: 380px;
  padding: 2.25rem 2rem 2rem;
  text-align: center;
  background: linear-gradient(160deg, rgba(92, 42, 94, 0.3), rgba(45, 20, 68, 0.3));
  border: 1px solid var(--panel-border);
  border-radius: 4px;
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
}

.auth-card::before, .auth-card::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  border: 1px solid var(--gold);
  opacity: 0.7;
}

.auth-card::before { top: -1px; left: -1px; border-right: none; border-bottom: none; }
.auth-card::after  { bottom: -1px; right: -1px; border-left: none; border-top: none; }

.auth-sigil {
  width: 72px;
  height: 72px;
  margin: 0 auto 1.25rem;
}

.auth-title {
  margin: 0 0 0.5rem;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.3rem, 8vw, 2rem);
  text-wrap: balance;
  background: linear-gradient(180deg, var(--gold-bright) 0%, var(--gold) 55%, #8a6a1a 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.auth-subtitle {
  margin: 0 0 1.5rem;
  font-family: var(--font-heading);
  font-size: 0.75rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--star-dim);
}

.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.auth-tab {
  flex: 1;
  cursor: pointer;
  background: transparent;
  border: 1px solid rgba(201, 162, 39, 0.3);
  color: var(--star-dim);
  font-family: var(--font-heading);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.55rem 0.5rem;
  border-radius: 2px;
}

.auth-tab--active {
  color: var(--gold-bright);
  border-color: var(--gold-bright);
  background: var(--accent-tint);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.auth-form input {
  text-align: center;
}

.auth-form .btn {
  margin-top: 0.25rem;
}

.auth-error {
  min-height: 1.1rem;
  font-family: var(--font-heading);
  font-size: 0.75rem;
  letter-spacing: 0.03em;
  color: var(--danger);
}

.app-root {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.toast-stack {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
}

.toast {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  background: rgba(19, 10, 31, 0.92);
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  padding: 0.6rem 0.9rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s, transform 0.3s;
}

.toast--in {
  opacity: 1;
  transform: translateY(0);
}

.toast--error {
  border-color: var(--danger);
  color: #f0a3a6;
}

.toast--info {
  border-color: var(--gold);
  color: var(--gold-bright);
}

::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-thumb {
  background: var(--panel-border);
  border-radius: 4px;
}

/* Admin panel */
.admin-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: rgba(8, 4, 14, 0.55);
  backdrop-filter: blur(2px);
}

.admin-modal {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.5rem;
  background: linear-gradient(160deg, rgba(92, 42, 94, 0.35), rgba(19, 10, 31, 0.92));
}

.admin-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.admin-modal__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.3rem;
  color: var(--gold-bright);
}

.admin-section {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.admin-field {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--font-heading);
  font-size: 0.85rem;
}

.admin-field__label {
  color: var(--star-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.7rem;
}

.admin-field__value {
  color: var(--star);
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--panel-border);
}

.admin-form h3 {
  margin: 0 0 0.15rem;
  font-family: var(--font-heading);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--star-dim);
}

.admin-row {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: center;
}

.admin-row--split {
  justify-content: space-between;
}

.admin-import-label {
  cursor: pointer;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

.admin-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  padding: 0.6rem 0.3rem;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  background: rgba(19, 10, 31, 0.4);
}

.admin-stat__value {
  font-family: var(--font-display);
  font-size: 1.2rem;
  color: var(--gold-bright);
}

.admin-stat__label {
  font-family: var(--font-heading);
  font-size: 0.6rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--star-dim);
}

.admin-trash-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 220px;
  overflow-y: auto;
}

.admin-trash-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  grid-template-rows: auto auto;
  gap: 0.25rem 0.6rem;
  align-items: center;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  background: rgba(19, 10, 31, 0.4);
}

.admin-trash-row__title {
  grid-column: 1 / -1;
  font-family: var(--font-heading);
  font-size: 0.85rem;
  color: var(--star);
}

.admin-trash-row__meta {
  font-size: 0.7rem;
  color: var(--star-dim);
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 180px;
  overflow-y: auto;
}

.admin-list-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--panel-border);
  border-radius: 3px;
  background: rgba(19, 10, 31, 0.4);
}

.admin-list-row__actions {
  display: flex;
  gap: 0.4rem;
  margin-left: auto;
}

.admin-list-row__title {
  font-family: var(--font-heading);
  font-size: 0.85rem;
  color: var(--star);
}

.admin-list-row__meta {
  font-size: 0.7rem;
  color: var(--star-dim);
  white-space: nowrap;
}

