:root {
  --bg: #f6f6f2;
  --surface: #ffffff;
  --ink: #163a3f;
  --text: #45585c;
  --muted: #7c9499;
  --line: #dde9e7;
  --brand: #388087;
  --brand-dark: #2c666b;
  --soft: #e7f3f1;
  --salmon: #dd5f55;
  --shadow: 0 1px 2px rgba(4, 22, 21, 0.04), 0 10px 28px rgba(4, 22, 21, 0.06);
  --font: "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Merriweather", Georgia, "Times New Roman", serif;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button, input, textarea { font: inherit; color: inherit; }

button { cursor: pointer; touch-action: manipulation; }

input, textarea { font-size: 16px; }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

::selection { background: #c2edce; }

[hidden] { display: none !important; }

.wrap {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 calc(88px + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 28px;
}

.wordmark {
  margin: 0;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 900;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.save {
  flex: 1;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.logout {
  border: 0;
  background: transparent;
  padding: 6px 2px;
  color: var(--brand-dark);
  font-weight: 600;
}

.booting {
  margin: 8vh 0 0;
  color: var(--muted);
}

.gate { margin-top: 10vh; }

.gate-form {
  display: grid;
  gap: 10px;
  width: min(360px, 100%);
}

.gate-form label {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.gate-form input {
  height: 48px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0 14px;
  color: var(--ink);
  font-size: 16px;
}

.gate-form button {
  height: 48px;
  border: 0;
  border-radius: var(--radius);
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

.gate-form button:hover { background: var(--brand-dark); }

.gate-form button:disabled { opacity: 0.6; cursor: wait; }

.gate-error {
  min-height: 1.2em;
  margin: 0;
  color: var(--salmon);
  font-size: 14px;
}

.pill-scroll {
  overflow-x: auto;
  padding: 4px 2px 14px;
  margin: 0 -2px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.pills {
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-height: 32px;
  max-width: 240px;
  padding: 2px 8px 2px 2px;
  border: 1px solid #d5e4e1;
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 0 rgba(22, 58, 63, 0.04);
  font-size: 14px;
}

.pill.is-active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.pill-label {
  min-width: 0;
  padding: 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.pill-label.is-placeholder { color: var(--muted); font-weight: 500; }

.pill.is-active .pill-label.is-placeholder { color: rgba(255, 255, 255, 0.72); }

.add-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: 0 0 auto;
  border: 1px dashed var(--brand);
  border-radius: 10px;
  background: transparent;
  color: var(--brand-dark);
  font-size: 20px;
  font-weight: 500;
  line-height: 1;
}

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

.project-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0 16px;
}

.project-name {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--ink);
}

.sections { display: grid; }

.subheader {
  margin: 0 0 12px;
  padding: 4px 8px 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.sub-row,
.item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 2px;
  min-height: 34px;
}

.item {
  grid-template-columns: 28px minmax(0, 1fr) auto auto;
  margin-left: 22px;
  border-top: 1px solid #eef3f2;
}

.note-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.note-btn.has-note,
.note-btn[aria-expanded="true"] {
  color: var(--brand-dark);
}

.note-btn[aria-expanded="true"] { background: var(--soft); }

.note-btn .chevron {
  transform-origin: 50% 50%;
  transition: transform 120ms ease;
}

.note-btn[aria-expanded="true"] .chevron { transform: rotate(90deg); }

.note-panel {
  position: relative;
  grid-column: 1 / -1;
  margin-top: 10px;
  padding: 0 0 12px;
}

.note-input {
  display: block;
  width: 100%;
  max-width: 100%;
  min-height: 88px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfb;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  line-height: 1.45;
  resize: vertical;
}

.note-links {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.note-links a {
  color: var(--brand-dark);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.note-photos:empty { display: none; }

.photo {
  position: relative;
  width: 72px;
  height: 72px;
}

.photo-open {
  display: block;
  width: 72px;
  height: 72px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: var(--line);
  overflow: hidden;
}

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

.photo-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 999px;
  background: rgba(22, 58, 63, 0.78);
  color: #fff;
  font-size: 14px;
  line-height: 1;
}

.photo-add {
  display: inline-flex;
  align-items: center;
  height: 30px;
  margin-top: 10px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 600;
}

.photo-file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.photo-error {
  margin: 8px 0 0;
  color: var(--salmon);
  font-size: 14px;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(22, 58, 63, 0.86);
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 28px;
  line-height: 1;
}

.sub-name,
.item-name { margin: 0; min-width: 0; }

.sub-name { font-size: 17px; font-weight: 600; color: var(--ink); }

.item-name { font-size: 15.5px; font-weight: 500; color: var(--text); }

.title-btn {
  display: block;
  width: 100%;
  margin: 0;
  padding: 4px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: text;
}

.title-btn:hover { background: rgba(56, 128, 135, 0.08); }

.pill.is-active .title-btn:hover { background: rgba(255, 255, 255, 0.08); }

.title-input {
  display: block;
  width: 100%;
  margin: 0;
  padding: 6px 8px;
  border: 0;
  border-radius: 8px;
  background: rgba(56, 128, 135, 0.08);
  box-shadow: inset 0 0 0 1.5px var(--brand);
  font: inherit;
  font-size: 16px;
  color: inherit;
}

.grip,
.mini-plus,
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.pill .grip,
.pill .mini-plus {
  width: 26px;
  height: 26px;
}

.grip { cursor: grab; touch-action: none; }

.grip:active { cursor: grabbing; }

.pill.is-active .grip,
.pill.is-active .mini-plus { color: rgba(255, 255, 255, 0.86); }

.mini-plus {
  background: var(--soft);
  color: var(--brand-dark);
  font-size: 18px;
  font-weight: 500;
  line-height: 1;
}

.pill.is-active .mini-plus { background: rgba(255, 255, 255, 0.14); }

.mini-plus:hover,
.icon-btn:hover,
.note-btn:hover,
.grip:hover { background: rgba(56, 128, 135, 0.12); }

.pill.is-active .mini-plus:hover,
.pill.is-active .grip:hover { background: rgba(255, 255, 255, 0.2); }

.icon-btn { font-size: 18px; line-height: 1; }

.icon-btn.is-armed,
.text-btn.is-armed {
  width: auto;
  padding: 0 10px;
  background: var(--salmon);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.text-btn {
  flex: 0 0 auto;
  border: 0;
  border-radius: 10px;
  background: transparent;
  padding: 8px 10px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.text-btn:hover { background: rgba(221, 95, 85, 0.1); color: var(--salmon); }

.empty {
  margin: 12px 0 0;
  color: var(--muted);
}

.drop-slot {
  flex: 0 0 auto;
  box-sizing: border-box;
  border: 1px dashed rgba(56, 128, 135, 0.45);
  border-radius: 14px;
  background: rgba(56, 128, 135, 0.08);
}

.drop-slot-sub { margin: 0 0 12px; }

.is-floating {
  position: fixed;
  z-index: 30;
  margin: 0;
  pointer-events: none;
  box-shadow: 0 16px 40px rgba(22, 58, 63, 0.18);
}

body.is-dragging,
body.is-dragging * { user-select: none; }

@media (max-width: 640px) {
  .wrap {
    width: min(760px, calc(100% - 24px));
    padding-top: max(22px, env(safe-area-inset-top));
  }
  .wordmark { font-size: 26px; }
  .project-name { font-size: 20px; }
  .item { margin-left: 8px; }
  .top { gap: 10px; }
  .pill { max-width: 200px; }
  .note-panel { margin-top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
  .note-btn .chevron { transition: none; }
}
