:root {
  --paper: #f6f2e8;
  --paper-strong: #fffdf6;
  --sidebar: #f5f1e8;
  --line: rgba(60, 60, 67, 0.18);
  --line-soft: rgba(60, 60, 67, 0.1);
  --text: #1d1d1f;
  --muted: rgba(60, 60, 67, 0.62);
  --gold: #d5a000;
  --gold-soft: #ffe088;
  --selected: rgba(255, 214, 79, 0.45);
  --danger: #ff3b30;
  --field: rgba(118, 118, 128, 0.12);
  --shadow: rgba(0, 0, 0, 0.18);
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Arial, sans-serif;
}

:root.dark {
  --paper: #1c1c1e;
  --paper-strong: #202023;
  --sidebar: #171719;
  --line: rgba(235, 235, 245, 0.16);
  --line-soft: rgba(235, 235, 245, 0.1);
  --text: #f5f5f7;
  --muted: rgba(235, 235, 245, 0.62);
  --gold: #ffd60a;
  --gold-soft: #6a5200;
  --selected: rgba(255, 214, 10, 0.22);
  --danger: #ff453a;
  --field: rgba(118, 118, 128, 0.24);
  --shadow: rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light) {
    --paper: #1c1c1e;
    --paper-strong: #202023;
    --sidebar: #171719;
    --line: rgba(235, 235, 245, 0.16);
    --line-soft: rgba(235, 235, 245, 0.1);
    --text: #f5f5f7;
    --muted: rgba(235, 235, 245, 0.62);
    --gold: #ffd60a;
    --gold-soft: #6a5200;
    --selected: rgba(255, 214, 10, 0.22);
    --danger: #ff453a;
    --field: rgba(118, 118, 128, 0.24);
    --shadow: rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, textarea {
  font: inherit;
}

button {
  border: 0;
  background: transparent;
  color: var(--gold);
  cursor: pointer;
  padding: 0;
}

input[type="file"] { display: none; }

.app {
  height: 100dvh;
  display: none;
  grid-template-columns: minmax(310px, 34vw) 1fr;
  background: var(--paper);
}

body.authenticated .app {
  display: grid;
}

.auth-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(28px, env(safe-area-inset-top)) 20px max(28px, env(safe-area-inset-bottom));
  background: radial-gradient(circle at top, var(--paper-strong), var(--paper));
}

body.authenticated .auth-screen {
  display: none;
}

.auth-card {
  width: min(100%, 390px);
  border: 1px solid var(--line);
  border-radius: 30px;
  background: color-mix(in srgb, var(--paper-strong) 92%, transparent);
  box-shadow: 0 24px 70px var(--shadow);
  padding: 30px;
}

.auth-icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: linear-gradient(#ffd43b 0 30%, #fffbea 30%);
  border: 1px solid var(--line);
  margin-bottom: 18px;
}

.auth-card h1 {
  font-size: 34px;
  margin-bottom: 7px;
}

.auth-copy {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.35;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-field {
  width: 100%;
  border: 0;
  outline: none;
  border-radius: 14px;
  background: var(--field);
  color: var(--text);
  padding: 14px 15px;
  font-size: 17px;
}

.auth-submit {
  margin-top: 3px;
  height: 48px;
  border-radius: 16px;
  background: var(--gold);
  color: #000;
  font-weight: 700;
}

.auth-switch,
.auth-error {
  text-align: center;
  font-size: 14px;
}

.auth-switch { color: var(--muted); }
.auth-error { min-height: 18px; color: var(--danger); }

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.side-top {
  padding: 20px 18px 10px;
}

.side-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  margin-bottom: 10px;
}

.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 34px;
}

.title-tools {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

h1 {
  margin: 0;
  font-size: 34px;
  letter-spacing: -0.8px;
  line-height: 1;
  font-weight: 800;
}

.count {
  margin: 6px 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.search-wrap {
  position: relative;
  margin-top: 16px;
}

.search-wrap svg {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
}

.search {
  width: 100%;
  height: 36px;
  border: 0;
  outline: none;
  border-radius: 10px;
  background: var(--field);
  padding: 0 12px 0 34px;
  color: var(--text);
  font-size: 16px;
}

.notes-list {
  overflow: auto;
  padding: 8px 10px calc(76px + env(safe-area-inset-bottom));
  scrollbar-width: none;
}

.notes-list::-webkit-scrollbar { display: none; }

.note-card {
  width: 100%;
  text-align: left;
  color: var(--text);
  border-radius: 12px;
  padding: 12px 12px 11px;
  display: block;
  min-height: 70px;
}

.note-card.selected {
  background: var(--selected);
}

.folder-wrap,
.note-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 12px;
}

.folder-wrap + .folder-wrap,
.note-wrap + .note-wrap {
  margin-top: 2px;
}

.note-wrap .note-card,
.folder-wrap .note-card {
  position: relative;
  z-index: 1;
  background: var(--sidebar);
  transition: transform 0.18s cubic-bezier(.2, .8, .2, 1);
}

.note-card + .note-card {
  margin-top: 2px;
}

.note-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.note-meta {
  display: flex;
  gap: 5px;
  min-width: 0;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.25;
}

.snippet {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1 1 auto;
}

.note-meta > span:first-child {
  flex: 0 0 auto;
  white-space: nowrap;
}

.editor {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--paper-strong);
  padding-top: env(safe-area-inset-top);
}

.settings-panel {
  display: none;
  flex-direction: column;
  min-width: 0;
  background: var(--paper-strong);
  padding-top: env(safe-area-inset-top);
}

.app.settings-open .editor {
  display: none;
}

.app.settings-open .settings-panel {
  display: flex;
}

.toolbar {
  min-height: 55px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px max(20px, env(safe-area-inset-right)) 8px 20px;
  border-bottom: 1px solid transparent;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 18px;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: var(--gold);
}

.icon-btn:active {
  background: rgba(213, 160, 0, 0.12);
}

.icon-btn.folder-action,
.icon-btn.folder-settings {
  color: var(--gold);
}

.delete { color: var(--danger); }

.edit-area {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 14px max(42px, env(safe-area-inset-right)) calc(92px + env(safe-area-inset-bottom)) 42px;
  scrollbar-width: none;
}

.edit-area::-webkit-scrollbar { display: none; }

.settings-area {
  flex: 1;
  overflow: auto;
  padding: 14px max(42px, env(safe-area-inset-right)) calc(92px + env(safe-area-inset-bottom)) 42px;
  scrollbar-width: none;
}

.settings-area::-webkit-scrollbar { display: none; }

.settings-title {
  margin: 0 0 24px;
  font-size: 34px;
  line-height: 1.15;
  letter-spacing: -0.6px;
  font-weight: 800;
}

.settings-subtitle {
  margin: 18px 2px 10px;
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.settings-group {
  border-radius: 16px;
  background: var(--field);
  overflow: hidden;
  margin-bottom: 22px;
  border: 1px solid var(--line-soft);
}

.settings-row {
  display: grid;
  grid-template-columns: 96px 1fr;
  align-items: center;
  min-height: 49px;
  gap: 12px;
  padding: 0 14px;
}

.settings-row + .settings-row,
.collaborator-row + .collaborator-row {
  border-top: 1px solid var(--line-soft);
}

.settings-row label {
  color: var(--text);
  font-size: 16px;
}

.settings-row input,
.invite-input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  padding: 13px 0;
}

.settings-note {
  margin: -12px 2px 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.invite-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
}

.folder-request {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--line-soft);
}

.folder-request:first-child {
  border-top: 0;
}

.folder-request-title {
  font-size: 15px;
  line-height: 1.3;
}

.folder-request-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.invite-button {
  font-weight: 600;
  padding: 9px 0;
}

.delete-folder-button {
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  color: var(--danger);
  font-size: 16px;
}

.collaborator-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
}

.collaborator-email {
  font-size: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.collaborator-meta {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.remove-collaborator,
.settings-logout {
  color: var(--danger);
  font-size: 16px;
}

.settings-empty {
  padding: 14px;
  color: var(--muted);
  font-size: 15px;
}

.date-line {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 18px;
}

.note-input {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  resize: none;
  display: block;
  overflow: hidden;
}

.title-input {
  min-height: 45px;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.6px;
  line-height: 1.15;
  margin-bottom: 10px;
}

.body-input {
  min-height: 180px;
  font-size: 19px;
  line-height: 1.38;
  letter-spacing: -0.15px;
}

.body-input::placeholder,
.title-input::placeholder {
  color: rgba(60, 60, 67, 0.32);
}

.checklists {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin: 8px 0 16px;
}

.checklist {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.todo-row {
  display: grid;
  grid-template-columns: 26px 1fr 28px;
  align-items: center;
  gap: 6px;
}

.todo-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.6px solid #b9b2a4;
  background: transparent;
  display: grid;
  place-items: center;
  color: #fff;
}

.todo-check.checked {
  border-color: var(--gold);
  background: var(--gold);
}

.todo-text {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 19px;
  line-height: 1.25;
  padding: 5px 0;
  border-bottom: 1px solid var(--line-soft);
}

.todo-text.done {
  color: var(--muted);
  text-decoration: line-through;
}

.remove-todo {
  width: 28px;
  height: 28px;
  color: rgba(60, 60, 67, 0.38);
  font-size: 22px;
  line-height: 1;
}

.empty {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--muted);
  font-size: 17px;
  text-align: center;
  padding: 30px;
}

.mobile-back { display: none; }

.mobile-new {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--gold);
  color: #000;
  box-shadow: 0 10px 28px var(--shadow);
  display: none;
  place-items: center;
  z-index: 5;
}

.fab-menu {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 66px);
  min-width: 174px;
  overflow: hidden;
  border-radius: 16px;
  background: color-mix(in srgb, var(--paper-strong) 94%, transparent);
  border: 1px solid var(--line);
  box-shadow: 0 14px 42px var(--shadow);
  backdrop-filter: blur(20px);
  z-index: 6;
  display: none;
}

.fab-menu.open {
  display: block;
}

.fab-menu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-align: left;
  padding: 13px 14px;
  font-size: 16px;
}

.fab-menu button + button {
  border-top: 1px solid var(--line-soft);
}

.fab-menu svg {
  color: var(--gold);
  flex: 0 0 auto;
}

.scan-modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(28, 28, 30, 0.72);
  backdrop-filter: blur(18px);
  z-index: 20;
  padding: 20px;
}

.scan-modal[hidden] {
  display: none;
}

.scan-panel {
  width: min(92vw, 520px);
  border-radius: 28px;
  overflow: hidden;
  background: #000;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.42);
}

.scan-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 14px;
  color: #fff;
}

.scan-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

.scan-close {
  color: #fff;
  font-size: 16px;
  padding: 6px 0;
}

.scan-stage {
  position: relative;
  aspect-ratio: 3 / 4;
  background: linear-gradient(180deg, #0d0d0f, #151518);
}

.scan-video,
.scan-video video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-target {
  position: absolute;
  inset: 14% 10%;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 22px;
  box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.scan-status {
  padding: 14px 18px 18px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 14px;
  line-height: 1.35;
}

.todo-item {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.attach-image {
  width: 28px;
  height: 28px;
  color: var(--muted);
  display: grid;
  place-items: center;
}

.todo-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-left: 32px;
}

.todo-attachment {
  position: relative;
  width: 78px;
  height: 78px;
  overflow: hidden;
  border-radius: 14px;
  background: var(--field);
  border: 1px solid var(--line-soft);
}

.todo-attachment img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.remove-attachment {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.58);
  color: #fff;
  line-height: 1;
  font-size: 16px;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: rgba(0, 0, 0, 0.94);
  color: #fff;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.lightbox[hidden] { display: none; }

.lightbox-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 44px;
}

.lightbox-count {
  color: rgba(255, 255, 255, 0.72);
  font-size: 15px;
  font-weight: 600;
}

.lightbox-close {
  color: #fff;
  font-size: 17px;
  padding: 8px;
}

.lightbox-stage {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
}

.lightbox-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 16px 60px rgba(0, 0, 0, 0.48);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: grid;
  place-items: center;
  backdrop-filter: blur(14px);
}

.lightbox-nav:disabled {
  opacity: 0.28;
}

.lightbox-prev { left: 4px; }
.lightbox-next { right: 4px; }

.lightbox-caption {
  min-height: 30px;
  text-align: center;
  color: rgba(255, 255, 255, 0.72);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 10px 54px 0;
}

@media (max-width: 760px) {
  .app {
    display: none;
    position: relative;
    overflow: hidden;
  }

  body.authenticated .app {
    display: block;
  }

  .sidebar,
  .editor {
    position: absolute;
    inset: 0;
    border-right: 0;
  }

  .sidebar {
    z-index: 1;
    transition: transform 0.24s cubic-bezier(.2, .8, .2, 1);
  }

  .editor {
    z-index: 2;
    transform: translateX(100%);
    transition: transform 0.24s cubic-bezier(.2, .8, .2, 1);
  }

  .settings-panel {
    display: flex;
    position: absolute;
    inset: 0;
    z-index: 2;
    transform: translateX(100%);
    transition: transform 0.24s cubic-bezier(.2, .8, .2, 1);
  }

  .app.editing .sidebar,
  .app.settings-open .sidebar {
    transform: translateX(-100%);
    pointer-events: none;
  }

  .app.editing .editor {
    transform: translateX(0);
  }

  .app.settings-open .settings-panel {
    transform: translateX(0);
  }

  .app.settings-open .editor {
    display: flex;
  }

  .mobile-back {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    color: var(--gold);
    font-size: 17px;
  }

  .toolbar {
    padding-left: 12px;
  }

  .edit-area {
    padding: 10px 20px calc(92px + env(safe-area-inset-bottom));
  }

  .settings-area {
    padding: 10px 20px calc(92px + env(safe-area-inset-bottom));
  }

  .title-input {
    font-size: 30px;
  }

  .mobile-new {
    display: grid;
  }

  .app.editing .mobile-new {
    display: none;
  }
}