:root {
  --bg: #f5f4ef;
  --card: #ffffff;
  --ink: #1c1c1e;
  --muted: #6e6e73;
  --line: #e3e1d8;
  --accent: #3056d3;
  --accent-ink: #ffffff;
  --accent-soft: #e6ecfc;
  --live: #2fa84f;
  --shadow: 0 1px 2px rgba(30, 28, 20, 0.05), 0 3px 10px rgba(30, 28, 20, 0.04);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131416;
    --card: #1c1e21;
    --ink: #ececee;
    --muted: #9a9aa2;
    --line: #2b2d32;
    --accent: #7f9cff;
    --accent-ink: #0d1330;
    --accent-soft: #222c4a;
    --live: #3ccf66;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding:
    env(safe-area-inset-top)
    max(14px, env(safe-area-inset-right))
    calc(40px + env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  -webkit-tap-highlight-color: transparent;
}

.wrap { max-width: 680px; margin: 0 auto; }

button { font: inherit; color: inherit; cursor: pointer; }

/* ---- header ---- */

.top {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 14px 2px 12px;
}
.top h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--live);
  flex: none;
  transition: background 0.3s;
}
.status.off { background: var(--muted); opacity: 0.45; }

.chip {
  margin-left: auto;
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13.5px;
  font-weight: 550;
  color: var(--accent);
}
.chip.on { color: var(--muted); }

.banner {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--accent-soft);
  font-size: 14.5px;
}
.banner .link { margin-left: 6px; }

.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-size: 14px;
  font-weight: 550;
}

/* ---- composer ---- */

.composer {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px 8px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}
.composer:focus-within { border-color: var(--accent); }

textarea {
  display: block;
  width: 100%;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: inherit;
  font: inherit;
  min-height: 2.9em;
  max-height: 55vh;
  padding: 0;
}
textarea::placeholder { color: var(--muted); opacity: 0.8; }

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}
.kbd-hint { color: var(--muted); font-size: 12.5px; }
@media (pointer: coarse) { .kbd-hint { visibility: hidden; } }

.primary {
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 15px;
  font-weight: 600;
  padding: 7px 18px;
}
.primary:disabled { opacity: 0.5; }

/* ---- notes ---- */

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.note {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px 4px;
  box-shadow: var(--shadow);
  scroll-margin: 80px;
  transition: opacity 0.2s;
}
.note-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
  -webkit-user-select: text;
}
.note-text a { color: var(--accent); text-underline-offset: 2px; }

.note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.when { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.actions { display: flex; flex: none; margin-right: -8px; }
.actions button {
  background: none;
  border: 0;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 550;
  padding: 9px 9px;
  min-height: 36px;
}
.actions button:hover { background: var(--accent-soft); color: var(--ink); }
.actions button.done { color: var(--accent); }

.note.editing { border-color: var(--accent); }
.note.editing .note-meta { margin-top: 6px; }
.note.leaving { opacity: 0.35; }

.note.fresh { animation: fresh 2.2s ease-out; }
@keyframes fresh {
  0%, 30% { background: var(--accent-soft); }
  100% { background: var(--card); }
}
.note.flash { animation: flash 1.8s ease-out; }
@keyframes flash {
  0%, 40% { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
  100% { border-color: var(--line); }
}

.empty {
  margin: 44px 0;
  text-align: center;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.6;
}

/* ---- recently removed ---- */

.removed {
  margin-top: 28px;
  color: var(--muted);
  font-size: 14px;
}
.removed summary {
  cursor: pointer;
  padding: 6px 2px;
  font-weight: 550;
  list-style-position: inside;
}
.removed-list { display: flex; flex-direction: column; margin: 6px 0 10px; }
.removed-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px;
  border-top: 1px solid var(--line);
}
.removed-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.removed-row button {
  flex: none;
  background: none;
  border: 0;
  color: var(--accent);
  font-size: 13.5px;
  font-weight: 550;
  padding: 8px 6px;
}

/* ---- sign-in (phone) and phones (PC) ---- */

.signin {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px 16px 14px;
  box-shadow: var(--shadow);
}
.signin h2 { margin: 0 0 6px; font-size: 17px; }
.signin p { margin: 0 0 12px; color: var(--muted); font-size: 14.5px; }
.signin-form { display: flex; gap: 8px; }
.signin-form input {
  flex: 1;
  min-width: 0;
  font: 600 20px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  outline: 0;
}
.signin-form input:focus { border-color: var(--accent); }
.error { color: #c2410c; font-size: 14px; margin: 10px 0 0 !important; }

.fine { margin: 4px 0 8px; font-size: 13.5px; }
.pair-code {
  margin: 10px 0 4px;
  font: 700 26px/1.2 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.12em;
  color: var(--ink);
}
.pair-code small {
  display: block;
  font: 500 12.5px/1.4 -apple-system, "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0;
  color: var(--muted);
}
.foot { margin: 22px 0 0; text-align: center; }

/* ---- toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: calc(100vw - 28px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #1f2023;
  color: #fff;
  font-size: 14.5px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  z-index: 10;
}
.toast[hidden] { display: none; }
.toast button {
  background: none;
  border: 0;
  padding: 2px 0;
  color: #a9bcff;
  font-weight: 650;
}
