:root {
  color-scheme: light;
  --bg: #fcfaf9;
  --text: #000000;
  --muted: #000000;
  --line: #000000;
  --soft: #f3d3bd;
  --danger: #000000;
  --accent: #48e5c2;
  --note-min: 260px;
  --emoji-font: "Noto Emoji";
  font-family: "Xanh Mono Variable", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* {
  box-sizing: border-box;
  font-weight: normal;
}

html {
  background: var(--bg);
  color: var(--text);
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
}

a {
  color: inherit;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}

.auth-layout {
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
  padding: clamp(1rem, 3vw, 1.5rem);
  border-right: 1px solid var(--line);
  background: var(--bg);
}

.sidebar-top {
  display: grid;
  align-content: start;
  gap: 1.25rem;
}

.sidebar-bottom {
  margin: auto 0 0;
}

.mobile-footer {
  display: none;
}

.brand {
  font-size: 1.25rem;
  font-weight: normal;
  text-decoration: none;
}

.sidebar-tags {
  display: grid;
  gap: 0.5rem;
}

.sidebar-tags h2 {
  margin: 0;
  font-size: 1rem;
}

.sidebar-tags ul {
  display: grid;
  gap: 0.35rem;
  padding: 0;
  margin: 0;
  list-style: none;
}

.sidebar-tags a {
  color: var(--text);
  font-style: italic;
  text-decoration: none;
}

.sidebar-empty {
  color: var(--text);
  font-style: italic;
}

.row-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.row-actions form {
  margin: 0;
}

.page {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: clamp(1rem, 4vw, 2rem);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--text);
  background: var(--bg);
  color: var(--text);
  line-height: 1.1;
  text-decoration: none;
  cursor: pointer;
}

.emoji-button {
  width: auto;
  inline-size: fit-content;
  min-height: 0;
  padding: 0;
  border: 0;
  appearance: none;
  background: transparent;
  font-family: var(--emoji-font);
  font-weight: normal;
  font-variant-emoji: text;
  justify-self: start;
  align-self: center;
  line-height: 1;
}

.emoji-glyph {
  display: inline-block;
  font-family: var(--emoji-font);
  font-weight: normal;
  font-style: normal;
  font-variant-emoji: text;
  font-size: 1.35rem;
  line-height: 1;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.button:hover {
  background: var(--soft);
}

.button.primary {
  background: var(--accent);
  color: var(--text);
}

.button.secondary,
.button.subtle {
  border-color: var(--line);
}

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

.button.emoji-button,
.button.emoji-button:hover,
.button.emoji-button.primary,
.button.emoji-button.secondary,
.button.emoji-button.subtle,
.button.emoji-button.danger {
  width: auto;
  inline-size: fit-content;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-family: var(--emoji-font);
  box-shadow: none;
}

.auth-shell,
.empty-state {
  display: grid;
  place-items: center;
  min-height: calc(100vh - 160px);
  text-align: center;
}

.auth-panel {
  width: min(420px, 100%);
  text-align: left;
}

.auth-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.auth-actions .form-note {
  margin: 0;
}

.auth-actions .emoji-button {
  flex: 0 0 auto;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  line-height: 1.05;
  margin-bottom: 1rem;
}

h2 {
  font-size: 1.1rem;
  line-height: 1.2;
}

.stack,
.note-form {
  display: grid;
  gap: 1rem;
}

label {
  display: grid;
  gap: 0.35rem;
}

label span,
legend {
  color: var(--muted);
  font-size: 0.9rem;
}

input,
textarea {
  width: 100%;
  background: var(--bg);
  color: var(--text);
}

input {
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0;
}

textarea {
  border: 1px solid var(--line);
  padding: 0.65rem 0.75rem;
}

::placeholder {
  color: #c9c9c9;
  opacity: 1;
}

textarea {
  resize: vertical;
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
}

.checkbox-field input {
  width: auto;
  margin: 0;
}

.checkbox-field span {
  color: var(--text);
}

input:focus,
textarea:focus,
button:focus,
a:focus,
button:focus-visible,
a:focus-visible {
  outline: 0;
}

.form-note,
.date,
.note-card .note-text,
.editable-attachment span {
  color: var(--muted);
}

.alert {
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 0.75rem;
}

.list-tools {
  margin-bottom: 1rem;
}

.search-form {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 0.5rem;
}

.search-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.search-field input {
  border: 0;
  padding-right: 0.5rem;
}

.notes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--note-min)), 1fr));
  align-items: start;
  gap: 1rem;
}

@supports (grid-template-rows: masonry) {
  .notes-grid {
    grid-template-rows: masonry;
  }
}

.notes-grid.masonry-polyfill {
  display: block;
  position: relative;
}

.notes-grid.masonry-polyfill > .note-card {
  position: absolute;
  width: var(--masonry-card-width);
}

.note-card {
  overflow: hidden;
  min-width: 0;
  border: 1px solid var(--note-border, transparent);
  background: var(--note-bg, #fcfaf9);
  color: var(--note-fg, var(--text));
}

.note-card:hover {
  outline: 0;
}

.card-body {
  display: grid;
  gap: 1.15rem;
  padding: 1rem 1rem 1.35rem;
}

.card-header {
  display: grid;
  gap: 1rem;
  margin-bottom: 0;
}

.note-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.card-link,
.card-note-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.card-media {
  display: block;
  background: #f3d3bd;
}

.card-media img,
.attachments img {
  display: block;
  width: 100%;
  height: auto;
}

.note-card h2 {
  margin: 0;
  overflow-wrap: anywhere;
}

.pin-marker {
  flex: 0 0 auto;
  color: var(--note-fg, var(--text));
  font-size: 1rem;
  line-height: 1;
}

.pin-marker.detail {
  align-self: center;
  font-size: 1.2rem;
}

.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 0;
  margin: 0;
  list-style: none;
}

.tags li:empty,
.tags a:empty {
  display: none;
}

.tags a {
  color: var(--note-fg, var(--text));
  font-size: 0.82rem;
  font-style: italic;
  text-decoration: none;
}

.tags li:not(:last-child)::after {
  content: ",";
  margin-right: 0.4rem;
  color: var(--note-fg, var(--text));
  font-size: 0.82rem;
  font-style: italic;
}

.note-meta .tags {
  justify-content: flex-end;
  text-align: right;
}

.card-audio {
  margin: 0;
}

.card-audio audio {
  display: block;
  width: 100%;
}

.card-location,
.card-audio p,
.attachment-link small {
  color: var(--note-muted, var(--muted));
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.card-location {
  margin: 0;
}

.card-audio p {
  margin: 0.35rem 0 0;
}

.attachment-link {
  display: grid;
  gap: 0.2rem;
  color: inherit;
  overflow-wrap: anywhere;
  text-decoration: none;
}

.attachment-link span {
  text-decoration: underline;
}

.note-text {
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.note-text.compact {
  max-height: 12rem;
  overflow: hidden;
}

.detail-note {
  display: grid;
  gap: 1rem;
  padding: clamp(1rem, 4vw, 2rem);
  border: 1px solid var(--note-border, transparent);
  background: var(--note-bg, #fcfaf9);
  color: var(--note-fg, var(--text));
}

.note-card .date,
.note-card .note-text,
.detail-note .date {
  color: var(--note-muted, var(--muted));
}

.note-card .date,
.detail-note .date {
  font-size: 0.82rem;
  line-height: 1.2;
}

.detail-header {
  display: grid;
  gap: 1rem;
}

.title-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  width: 100%;
  gap: 1rem;
  padding-bottom: 0.2rem;
  border-bottom: 1px solid currentColor;
}

.editor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.detail-header h1,
.editor-header h1 {
  margin: 0;
}

.attachments.detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
  gap: 1rem;
}

.attachments figure,
.audio-attachment,
.attachment-link.detail,
.location-card {
  margin: 0;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

.attachment-editor,
.location-editor,
.existing-attachments {
  margin: 0;
  padding-top: 1rem;
}

.attachment-editor {
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
}

.attachments figcaption,
.audio-attachment p {
  margin-top: 0.35rem;
  margin-bottom: 0;
  color: var(--note-muted, var(--muted));
  font-size: 0.9rem;
}

.detail-note .attachments figure,
.detail-note .audio-attachment,
.detail-note .attachment-link.detail,
.detail-note .location-card {
  border-top: 0;
  padding-top: 0;
}

.audio-attachment audio {
  width: 100%;
}

.editor-shell {
  width: min(820px, 100%);
  margin: 0 auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}

.colour-field {
  border: 0;
  margin: 0;
  padding: 0;
}

.colour-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.colour-choice {
  display: block;
  position: relative;
  cursor: pointer;
}

.colour-choice input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.colour-choice span {
  display: block;
  width: 2.35rem;
  height: 2.35rem;
  overflow: hidden;
  border: 1px solid transparent;
  outline: 0;
  background: var(--swatch);
  cursor: pointer;
}

.colour-choice[style*="#fcfaf9"] span {
  border-color: #d8d4d1;
}

.colour-choice input:checked + span {
  border-color: var(--text);
}

.file-picker {
  position: relative;
}

.file-picker:has(input:focus-visible) {
  outline: 0;
}

.file-preview:not(:empty) {
  margin-top: 0.65rem;
}

.location-editor {
  padding-bottom: 1rem;
}

.location-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 1rem;
}

.location-controls > .emoji-button {
  display: inline-grid;
  place-items: center;
  inline-size: 1.6rem;
  block-size: 2.85rem;
  align-self: end;
}

.editable-attachment {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.65rem 0;
}

.editable-attachment strong,
.editable-attachment span {
  display: block;
}

.editable-attachment + .editable-attachment {
  border-top: 1px solid var(--line);
}

.attachment-delete-form {
  display: none;
}

@media (max-width: 720px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
  }

  .sidebar {
    position: static;
    display: block;
    min-height: 0;
    height: auto;
    padding: 1rem;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-top {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: start;
    gap: 0.6rem 1rem;
  }

  .sidebar-new {
    justify-self: end;
  }

  .sidebar-tags {
    grid-column: 1 / -1;
  }

  .sidebar-tags ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
  }

  .sidebar-tags li:not(:last-child)::after {
    content: ",";
    margin-right: 0.35rem;
  }

  .sidebar-bottom {
    display: none;
  }

  .page {
    flex: 1;
  }

  .mobile-footer {
    display: flex;
    justify-content: flex-end;
    padding: 1rem;
    border-top: 1px solid var(--line);
  }

  .mobile-footer form {
    margin: 0;
  }

  .editor-header {
    align-items: stretch;
    flex-direction: column;
  }

  .title-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .card-header {
    gap: 0.75rem;
  }

  .search-form,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .row-actions {
    align-items: stretch;
  }

  .button {
    width: 100%;
  }

  .auth-actions {
    align-items: center;
    flex-direction: row;
  }

  .emoji-button {
    width: auto;
  }
}
