:root {
  color-scheme: light;
  --ink: #112235;
  --muted: #66717d;
  --paper: #f7f5f2;
  --card: rgba(255, 255, 255, 0.92);
  --line: rgba(17, 34, 53, 0.12);
  --red: #e60023;
  --red-dark: #ad081b;
  --green: #18794e;
  --shadow: 0 24px 80px rgba(17, 34, 53, 0.1);
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-height: 100%; background: var(--paper); }

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 7%, rgba(230, 0, 35, 0.07), transparent 28rem),
    radial-gradient(circle at 88% 26%, rgba(60, 122, 170, 0.06), transparent 25rem),
    var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.ambient { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: -1; }
.ambient i { position: absolute; border: 1px solid rgba(17, 34, 53, 0.05); border-radius: 50%; }
.ambient i:nth-child(1) { width: 23rem; height: 23rem; left: -12rem; top: 28%; }
.ambient i:nth-child(2) { width: 32rem; height: 32rem; right: -23rem; top: 5%; }
.ambient i:nth-child(3) { width: 12rem; height: 12rem; right: 12%; bottom: -7rem; border-color: rgba(230, 0, 35, 0.08); }

.app-head {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 72px;
  padding: max(14px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 14px max(20px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  background: rgba(247, 245, 242, 0.82);
  border-bottom: 1px solid rgba(17, 34, 53, 0.07);
  backdrop-filter: blur(18px) saturate(1.2);
}

.brand { display: inline-flex; width: fit-content; }
.brand img { display: block; width: 150px; max-width: 100%; height: 28px; object-fit: contain; object-position: left center; }

.tabs { display: flex; align-items: center; gap: 5px; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.62); }
.tab {
  min-height: 38px;
  padding: 0 15px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 14px;
  font-weight: 750;
  cursor: pointer;
}
.tab svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab span { min-width: 19px; padding: 1px 6px; color: inherit; border-radius: 999px; background: rgba(17,34,53,.07); font-size: 11px; }
.tab.is-active { color: var(--ink); background: #fff; box-shadow: 0 4px 15px rgba(17,34,53,.08); }

.install-button {
  justify-self: end;
  min-height: 40px;
  padding: 0 17px;
  border: 0;
  border-radius: 999px;
  color: #fff;
  background: var(--ink);
  font-weight: 750;
  cursor: pointer;
}

.app-shell { width: min(760px, 100%); margin: 0 auto; padding: 54px 24px calc(80px + env(safe-area-inset-bottom)); }
.intro { margin-bottom: 30px; text-align: center; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; color: var(--red); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.eyebrow i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 5px rgba(230,0,35,.08); }
h1 { max-width: 660px; margin: 12px auto 9px; font-size: clamp(32px, 7vw, 48px); line-height: 1.08; letter-spacing: -.045em; }
.intro p, .library-head p { margin: 0; color: var(--muted); font-size: 17px; }

.editor {
  padding: clamp(20px, 5vw, 34px);
  border: 1px solid rgba(17,34,53,.1);
  border-radius: 28px;
  background: var(--card);
  box-shadow: var(--shadow);
}

label { display: block; margin-bottom: 9px; font-size: 14px; font-weight: 800; }
label small { color: var(--muted); font-weight: 600; }
input, textarea {
  width: 100%;
  border: 1px solid rgba(17,34,53,.14);
  border-radius: 15px;
  outline: none;
  color: var(--ink);
  background: rgba(250,250,249,.94);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, textarea:focus { border-color: rgba(230,0,35,.55); background: #fff; box-shadow: 0 0 0 4px rgba(230,0,35,.08); }

.url-entry { margin-bottom: 24px; }
.url-row { display: flex; gap: 9px; }
.url-row input { min-width: 0; min-height: 49px; padding: 0 15px; }
.url-row button { flex: 0 0 auto; padding: 0 17px; border: 0; border-radius: 14px; color: #fff; background: var(--ink); font-weight: 750; cursor: pointer; }
.field-error { min-height: 18px; margin: 6px 2px 0; color: #b42318; font-size: 13px; }

.pin-card {
  min-height: 78px;
  margin-bottom: 25px;
  padding: 12px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 11px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 19px;
  background: linear-gradient(135deg, rgba(230,0,35,.045), rgba(255,255,255,.7));
}
.pin-mark { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 15px; color: #fff; background: var(--red); box-shadow: 0 10px 25px rgba(230,0,35,.18); }
.pin-mark svg { width: 31px; height: 31px; fill: currentColor; }
.pin-copy { min-width: 0; display: flex; flex-direction: column; }
.pin-copy strong, .pin-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-copy strong { font-size: 15px; }
.pin-copy span { margin-top: 3px; color: var(--muted); font-size: 13px; }
.icon-button { width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 12px; color: var(--muted); background: transparent; cursor: pointer; }
.icon-button:hover { color: var(--ink); background: rgba(17,34,53,.06); }
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.note-field textarea { min-height: 230px; padding: 17px; resize: vertical; line-height: 1.6; }
.note-meta { margin: 7px 2px 0; display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 12px; }
.tags-field { margin-top: 19px; }
.tag-box { min-height: 51px; padding: 7px 10px; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; border: 1px solid rgba(17,34,53,.14); border-radius: 15px; background: rgba(250,250,249,.94); }
.tag-box:focus-within { border-color: rgba(230,0,35,.55); background: #fff; box-shadow: 0 0 0 4px rgba(230,0,35,.08); }
.tag-box input { flex: 1 1 125px; width: auto; min-height: 34px; padding: 0 5px; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.tag-box input:focus { box-shadow: none; background: transparent; }
.tag-chips { display: contents; }
.tag-chip { min-height: 34px; padding: 0 8px 0 11px; display: inline-flex; align-items: center; gap: 6px; border-radius: 10px; color: var(--ink); background: rgba(17,34,53,.07); font-size: 13px; font-weight: 700; }
.tag-chip button { width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; color: var(--muted); background: transparent; cursor: pointer; font-size: 17px; line-height: 1; }
.tag-help { display: block; margin: 7px 2px 0; color: var(--muted); font-size: 12px; }

.form-actions { margin-top: 27px; display: flex; align-items: center; justify-content: flex-end; gap: 14px; }
.save-status { flex: 1; color: var(--green); font-size: 13px; font-weight: 700; }
.save-button, .secondary-button {
  min-height: 50px;
  padding: 0 22px;
  border: 0;
  border-radius: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: #fff;
  background: var(--red);
  box-shadow: 0 10px 26px rgba(230,0,35,.2);
  font-weight: 800;
  cursor: pointer;
}
.save-button:hover { background: var(--red-dark); }
.save-button:disabled { opacity: .64; cursor: wait; }
.save-button svg, .secondary-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.local-note { margin: 21px 6px 0; padding: 16px; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; color: var(--muted); border: 1px dashed rgba(17,34,53,.16); border-radius: 17px; background: rgba(255,255,255,.46); }
.local-note svg { width: 22px; height: 22px; grid-row: 1 / span 2; fill: none; stroke: var(--ink); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.local-note p { margin: 0; font-size: 13px; line-height: 1.55; }
.local-note strong { color: var(--ink); }
.local-note a { width: fit-content; color: var(--red); font-size: 13px; font-weight: 800; text-underline-offset: 3px; }

.library-head { margin-bottom: 25px; display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.library-head h1 { margin: 10px 0 8px; }
.secondary-button { min-height: 45px; flex: 0 0 auto; color: var(--ink); background: #fff; border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(17,34,53,.07); }
.search-box { min-height: 52px; margin: 0 0 18px; padding: 0 16px; display: flex; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255,255,255,.82); box-shadow: 0 10px 30px rgba(17,34,53,.05); }
.search-box:focus-within { border-color: rgba(230,0,35,.45); box-shadow: 0 0 0 4px rgba(230,0,35,.07); }
.search-box svg { width: 21px; height: 21px; flex: 0 0 auto; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }
.search-box input { min-height: 50px; padding: 0; border: 0; background: transparent; box-shadow: none; }
.search-box input:focus { background: transparent; box-shadow: none; }

.notes-list { display: grid; gap: 12px; }
.note-card { padding: 16px; display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 14px; align-items: start; border: 1px solid var(--line); border-radius: 19px; background: rgba(255,255,255,.86); box-shadow: 0 10px 28px rgba(17,34,53,.05); }
.note-card-mark { width: 43px; height: 43px; display: grid; place-items: center; border-radius: 13px; color: #fff; background: var(--red); }
.note-card-mark svg { width: 22px; height: 22px; fill: currentColor; }
.note-card-main { min-width: 0; border: 0; padding: 0; color: inherit; text-align: left; background: transparent; cursor: pointer; }
.note-card-main strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.note-card-main p { margin: 5px 0 9px; display: -webkit-box; overflow: hidden; color: var(--muted); font-size: 14px; line-height: 1.45; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.note-card-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.note-card-tags span { padding: 3px 7px; border-radius: 7px; color: var(--muted); background: rgba(17,34,53,.06); font-size: 11px; font-weight: 700; }
.note-card-actions { display: flex; }
.delete-note { color: #b42318; }

.empty-state { padding: 60px 24px; text-align: center; border: 1px dashed rgba(17,34,53,.16); border-radius: 24px; background: rgba(255,255,255,.55); }
.empty-state img { width: 72px; height: 72px; }
.empty-state h2 { margin: 15px 0 7px; font-size: 22px; }
.empty-state p { margin: 0 0 22px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: calc(22px + env(safe-area-inset-bottom)); z-index: 50; max-width: calc(100% - 32px); padding: 12px 17px; border-radius: 13px; transform: translateX(-50%); color: #fff; background: var(--ink); box-shadow: 0 15px 45px rgba(17,34,53,.25); font-size: 14px; font-weight: 700; }

@media (max-width: 640px) {
  .app-head { grid-template-columns: 1fr auto; gap: 10px; }
  .brand img { width: 122px; height: 24px; }
  .tabs { grid-column: 1 / -1; grid-row: 2; justify-self: stretch; display: grid; grid-template-columns: 1fr 1fr; }
  .tab { justify-content: center; }
  .install-button { grid-column: 2; grid-row: 1; }
  .app-shell { padding: 38px 15px calc(65px + env(safe-area-inset-bottom)); }
  .editor { border-radius: 23px; }
  .pin-card { grid-template-columns: auto minmax(0,1fr) auto; }
  #changeUrl { display: none; }
  .note-field textarea { min-height: 205px; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .save-status { min-height: 18px; }
  .save-button { width: 100%; }
  .library-head { align-items: stretch; flex-direction: column; }
  .secondary-button { width: 100%; }
}

@media (prefers-reduced-motion: no-preference) {
  .editor, .note-card { animation: rise .35s ease both; }
  @keyframes rise { from { opacity: 0; transform: translateY(8px); } }
}
