:root {
  --ink: #14201b;
  --muted: #5a6a62;
  --paper: #f3f0e8;
  --panel: #fffcf7;
  --panel-soft: #f7f3ea;
  --line: rgba(20, 32, 27, 0.1);
  --line-strong: rgba(20, 32, 27, 0.16);
  --teal: #1f5c4d;
  --teal-mid: #2a7360;
  --teal-deep: #0f2f27;
  --gold: #b8892d;
  --gold-soft: rgba(184, 137, 45, 0.16);
  --danger: #9b2d22;
  --danger-soft: rgba(155, 45, 34, 0.08);
  --ok: #1f5c4d;
  --ok-soft: rgba(31, 92, 77, 0.1);
  --warn: #8a6418;
  --warn-soft: rgba(184, 137, 45, 0.18);
  --shadow: 0 18px 50px rgba(15, 47, 39, 0.1);
  --radius: 18px;
  --radius-sm: 12px;
  --font-brand: "Bricolage Grotesque", Georgia, serif;
  --font-body: "Figtree", "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.45;
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(ellipse 80% 50% at 8% -10%, rgba(184, 137, 45, 0.22), transparent 55%),
    radial-gradient(ellipse 70% 45% at 100% 0%, rgba(31, 92, 77, 0.18), transparent 52%),
    radial-gradient(ellipse 55% 40% at 50% 110%, rgba(31, 92, 77, 0.08), transparent 60%),
    linear-gradient(165deg, #f8f5ee 0%, #eef2ef 48%, #ebe6db 100%);
  animation: atmosphere-drift 18s ease-in-out infinite alternate;
}

@keyframes atmosphere-drift {
  from {
    filter: hue-rotate(0deg) saturate(1);
    transform: scale(1);
  }
  to {
    filter: hue-rotate(-6deg) saturate(1.05);
    transform: scale(1.03);
  }
}

button,
input,
select,
textarea,
a.btn {
  font: inherit;
}

button,
a.btn {
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 0;
  border-radius: 999px;
  padding: 0.68rem 1.15rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition:
    transform 180ms var(--ease),
    background 180ms var(--ease),
    color 180ms var(--ease),
    border-color 180ms var(--ease),
    box-shadow 180ms var(--ease);
}

button:hover,
a.btn:hover {
  transform: translateY(-1px);
}

button:active,
a.btn:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: linear-gradient(180deg, var(--teal-mid), var(--teal-deep));
  color: #fff;
  box-shadow: 0 10px 24px rgba(15, 47, 39, 0.22);
}

.btn-primary:hover {
  box-shadow: 0 14px 28px rgba(15, 47, 39, 0.28);
}

.btn-ghost {
  background: rgba(255, 252, 247, 0.72);
  color: var(--teal-deep);
  border: 1px solid var(--line-strong);
}

.btn-quiet {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding-inline: 0.85rem;
}

.btn-quiet:hover {
  color: var(--teal-deep);
  background: rgba(255, 252, 247, 0.55);
}

.btn-block {
  width: 100%;
}

.btn.danger,
button.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(155, 45, 34, 0.18);
  padding: 0.38rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: none;
}

.btn.danger:hover,
button.danger:hover {
  background: rgba(155, 45, 34, 0.14);
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

.lede,
.help,
.sidebar-note,
.page-meta,
small {
  color: var(--muted);
}

.help,
.sidebar-note,
.page-meta {
  margin: 0.35rem 0 0;
  font-size: 0.9rem;
}

code {
  font-size: 0.86em;
  padding: 0.1em 0.35em;
  border-radius: 6px;
  background: rgba(31, 92, 77, 0.08);
  color: var(--teal-deep);
}

.field {
  display: grid;
  gap: 0.4rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
}

.field em {
  font-style: normal;
  font-weight: 500;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.78rem 0.9rem;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition:
    border-color 160ms var(--ease),
    box-shadow 160ms var(--ease);
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(31, 92, 77, 0.55);
  box-shadow: 0 0 0 4px rgba(31, 92, 77, 0.12);
}

.error {
  margin: 0;
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9rem;
}

/* ——— Login ——— */
.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: clamp(1.25rem, 4vw, 2.5rem);
}

.login-stage {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: center;
  animation: rise-in 700ms var(--ease) both;
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.login-brand {
  padding: clamp(0.5rem, 2vw, 1rem);
}

.login-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  margin-bottom: 1.1rem;
  filter: drop-shadow(0 10px 20px rgba(15, 47, 39, 0.15));
  animation: logo-float 5s ease-in-out infinite;
}

@keyframes logo-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.brand-mark {
  margin: 0;
  font-family: var(--font-brand);
  font-size: clamp(2.2rem, 5vw, 3.4rem);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 0.95;
  color: var(--teal-deep);
}

.brand-line {
  margin: 0.85rem 0 0;
  max-width: 18rem;
  font-size: 1.05rem;
  color: var(--muted);
}

.login-card {
  background: rgba(255, 252, 247, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 28px;
  padding: clamp(1.4rem, 3vw, 2rem);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  display: grid;
  gap: 0.95rem;
  animation: rise-in 800ms var(--ease) 80ms both;
}

.login-card h1,
.workspace-head h2,
.section-head h2,
.dialog-card h3 {
  margin: 0;
  font-family: var(--font-brand);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--teal-deep);
}

.login-card h1 {
  font-size: clamp(1.8rem, 3vw, 2.25rem);
}

.login-card .lede {
  margin: 0;
}

/* ——— App shell ——— */
.app-view {
  min-height: 100vh;
  animation: rise-in 450ms var(--ease) both;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem clamp(1rem, 3vw, 1.6rem);
  background: rgba(255, 252, 247, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
  justify-self: start;
}

.brand-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand-lockup strong {
  display: block;
  font-family: var(--font-brand);
  font-size: 1rem;
  letter-spacing: -0.02em;
  color: var(--teal-deep);
}

.brand-lockup small {
  display: block;
  margin-top: 0.05rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
}

.status-pill {
  justify-self: center;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: min(420px, 42vw);
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--ok-soft);
  color: var(--ok);
  border: 1px solid rgba(31, 92, 77, 0.12);
}

.status-pill::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
  box-shadow: 0 0 0 4px rgba(31, 92, 77, 0.12);
}

.status-pill[data-state="dirty"] {
  background: var(--warn-soft);
  color: var(--warn);
}

.status-pill[data-state="dirty"]::before {
  box-shadow: 0 0 0 4px rgba(184, 137, 45, 0.18);
  animation: pulse-dot 1.4s ease-in-out infinite;
}

.status-pill[data-state="idle"] {
  background: rgba(90, 106, 98, 0.1);
  color: var(--muted);
}

.status-pill[data-state="idle"]::before {
  box-shadow: none;
}

@keyframes pulse-dot {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.35);
    opacity: 0.65;
  }
}

.top-actions {
  justify-self: end;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  justify-content: flex-end;
}

.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: clamp(1rem, 2vw, 1.4rem);
  width: min(1240px, calc(100% - 2rem));
  margin: 1.15rem auto 2.5rem;
}

.sidebar {
  position: sticky;
  top: 5.1rem;
  align-self: start;
  padding: 1.1rem;
  border-radius: var(--radius);
  background: rgba(255, 252, 247, 0.72);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.sidebar-head h2,
.section-head h2 {
  font-size: 1.15rem;
}

.sidebar-head h2 {
  margin: 0;
  font-family: var(--font-brand);
  color: var(--teal-deep);
}

#pageList {
  list-style: none;
  margin: 1rem 0 0.9rem;
  padding: 0;
  display: grid;
  gap: 0.28rem;
  max-height: min(62vh, 560px);
  overflow: auto;
}

#pageList li {
  margin: 0;
}

#pageList button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border-radius: 14px;
  border: 1px solid transparent;
  padding: 0.7rem 0.8rem;
  display: grid;
  gap: 0.15rem;
  box-shadow: none;
  transform: none;
}

#pageList button:hover {
  background: rgba(31, 92, 77, 0.06);
  border-color: rgba(31, 92, 77, 0.1);
  transform: none;
}

#pageList button.active {
  background: linear-gradient(135deg, rgba(31, 92, 77, 0.12), rgba(184, 137, 45, 0.1));
  border-color: rgba(31, 92, 77, 0.2);
  box-shadow: inset 3px 0 0 var(--teal);
}

#pageList .page-name {
  font-size: 0.92rem;
  font-weight: 700;
}

#pageList .page-count {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.main {
  display: grid;
  gap: 1rem;
  min-width: 0;
}

.workspace,
.composer,
.publish-panel,
.dialog-card {
  background: rgba(255, 252, 247, 0.88);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: 0 10px 30px rgba(15, 47, 39, 0.05);
}

.workspace {
  padding: clamp(1rem, 2vw, 1.35rem);
  min-height: 280px;
}

.workspace-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.85rem;
  margin-bottom: 1.1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--line);
}

.workspace-head h2 {
  font-size: clamp(1.45rem, 2.5vw, 1.9rem);
}

.units-host {
  display: grid;
  gap: 0.85rem;
}

.unit-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.55), transparent 40%),
    var(--panel-soft);
  animation: rise-in 420ms var(--ease) both;
}

.unit-card + .unit-card {
  animation-delay: 40ms;
}

.unit-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.unit-card h3 {
  margin: 0;
  font-family: var(--font-brand);
  font-size: 1.08rem;
  letter-spacing: -0.02em;
  color: var(--teal-deep);
}

.unit-card .idea {
  margin: 0.35rem 0 0.85rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.unit-card .idea strong {
  color: var(--ink);
  font-weight: 700;
}

.link-list {
  display: grid;
  gap: 0.45rem;
}

.link-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.7rem 0.8rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(20, 32, 27, 0.06);
}

.link-thumb {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  object-fit: cover;
  background: rgba(31, 92, 77, 0.08);
  flex: 0 0 auto;
}

.link-thumb.placeholder {
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--teal);
}

.link-row strong {
  display: block;
  font-size: 0.94rem;
  color: var(--ink);
}

.link-row a {
  display: block;
  margin-top: 0.15rem;
  word-break: break-all;
  font-size: 0.78rem;
  color: var(--teal-mid);
  text-decoration: none;
}

.link-row a:hover {
  text-decoration: underline;
}

.empty-state {
  margin: 0;
  padding: 1.4rem 1rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.35);
}

.empty-state strong {
  display: block;
  margin-bottom: 0.25rem;
  font-family: var(--font-brand);
  color: var(--teal-deep);
  font-size: 1.05rem;
}

.tools {
  display: grid;
  grid-template-columns: 1.35fr 0.9fr;
  gap: 1rem;
}

.composer,
.publish-panel {
  padding: clamp(1rem, 2vw, 1.25rem);
}

.section-head {
  margin-bottom: 1rem;
}

.section-head h2 {
  font-size: 1.25rem;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.span-2 {
  grid-column: 1 / -1;
}

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

.toast {
  margin: 0.9rem 0 0;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  background: var(--ok-soft);
  color: var(--teal-deep);
  font-size: 0.88rem;
  font-weight: 600;
  border: 1px solid rgba(31, 92, 77, 0.12);
}

.upload-zone {
  position: relative;
  min-height: 132px;
  border: 1.5px dashed rgba(31, 92, 77, 0.35);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.7), rgba(247, 243, 234, 0.9));
  overflow: hidden;
  transition:
    border-color 160ms var(--ease),
    background 160ms var(--ease),
    box-shadow 160ms var(--ease);
}

.upload-zone:hover,
.upload-zone:focus-within,
.upload-zone.is-dragover {
  border-color: var(--teal);
  background: rgba(31, 92, 77, 0.06);
  box-shadow: 0 0 0 4px rgba(31, 92, 77, 0.08);
}

.upload-zone.has-file {
  border-style: solid;
  border-color: rgba(31, 92, 77, 0.2);
}

.upload-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}

.upload-empty {
  display: grid;
  place-content: center;
  gap: 0.25rem;
  min-height: 132px;
  padding: 1rem;
  text-align: center;
  pointer-events: none;
}

.upload-empty strong {
  font-family: var(--font-brand);
  color: var(--teal-deep);
  font-size: 1.02rem;
}

.upload-empty span {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--muted);
}

.upload-preview {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 0.85rem;
  align-items: center;
  padding: 0.75rem;
  position: relative;
  z-index: 3;
}

.upload-preview img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 14px;
  background: rgba(31, 92, 77, 0.08);
}

.upload-preview-meta {
  display: grid;
  gap: 0.35rem;
  justify-items: start;
  min-width: 0;
}

.upload-preview-meta strong {
  font-size: 0.9rem;
  word-break: break-word;
}

.upload-zone.has-file .upload-input {
  pointer-events: none;
}

.url-fallback {
  margin-top: 0.55rem;
}

.url-fallback summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
  list-style: none;
}

.url-fallback summary::-webkit-details-marker {
  display: none;
}

.url-fallback[open] summary {
  margin-bottom: 0.45rem;
  color: var(--teal-deep);
}

.url-fallback input {
  margin-top: 0.15rem;
}

.type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.type-option {
  position: relative;
  display: block;
  cursor: pointer;
}

.type-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.type-option span {
  display: grid;
  place-items: center;
  min-height: 2.7rem;
  padding: 0.55rem 0.75rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.7);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--muted);
  transition:
    background 160ms var(--ease),
    color 160ms var(--ease),
    border-color 160ms var(--ease),
    box-shadow 160ms var(--ease);
}

.type-option input:checked + span {
  background: linear-gradient(180deg, var(--teal-mid), var(--teal-deep));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px rgba(15, 47, 39, 0.18);
}

.type-option input:focus-visible + span {
  box-shadow: 0 0 0 4px rgba(31, 92, 77, 0.16);
}

.file-preview {
  grid-template-columns: 72px 1fr;
}

.file-badge {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 14px;
  background: rgba(31, 92, 77, 0.1);
  color: var(--teal-deep);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.link-row-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-items: stretch;
}

.link-row .btn-edit {
  background: rgba(31, 92, 77, 0.08);
  color: var(--teal-deep);
  border: 1px solid rgba(31, 92, 77, 0.18);
  padding: 0.38rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: none;
}

.link-row .btn-edit:hover {
  background: rgba(31, 92, 77, 0.14);
}

.composer.is-editing {
  box-shadow: 0 0 0 2px rgba(184, 137, 45, 0.35), 0 10px 30px rgba(15, 47, 39, 0.05);
}

@media (max-width: 640px) {
  .link-row-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

dialog {
  border: 0;
  padding: 0;
  background: transparent;
}

dialog::backdrop {
  background:
    radial-gradient(circle at 50% 20%, rgba(184, 137, 45, 0.18), transparent 45%),
    rgba(15, 47, 39, 0.45);
  backdrop-filter: blur(4px);
}

.dialog-card {
  width: min(460px, 92vw);
  padding: 1.35rem;
  display: grid;
  gap: 0.8rem;
  animation: rise-in 280ms var(--ease) both;
}

.dialog-card h3 {
  font-size: 1.4rem;
}

@media (max-width: 980px) {
  .login-stage {
    grid-template-columns: 1fr;
    max-width: 460px;
  }

  .login-brand {
    text-align: center;
  }

  .brand-line {
    margin-inline: auto;
  }

  .topbar {
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .brand-lockup,
  .status-pill,
  .top-actions {
    justify-self: stretch;
  }

  .status-pill {
    max-width: none;
    justify-content: center;
  }

  .top-actions {
    justify-content: flex-start;
  }

  .layout {
    grid-template-columns: 1fr;
    width: min(100% - 1.25rem, 1240px);
  }

  .sidebar {
    position: static;
  }

  #pageList {
    max-height: none;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  }

  .tools {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: auto;
  }

  .link-row {
    grid-template-columns: auto 1fr;
  }

  .link-row .danger {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .workspace-head {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
