:root {
  color-scheme: dark;
  --bg: #0d1015;
  --text: #f5f0e6;
  --muted: #bcb7ad;
  --line: rgba(255,255,255,.13);
  --panel: rgba(17,21,28,.86);
  --tag: rgba(238,230,215,.83);
  --tag-soft: rgba(197,207,214,.72);
  --accent: #e6c98e;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", "Avenir Next", Avenir, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
}

button, input {
  font: inherit;
}

button {
  color: var(--text);
}

#app {
  position: relative;
  min-height: 100vh;
  padding:
    max(28px, env(safe-area-inset-top))
    max(34px, env(safe-area-inset-right))
    max(28px, env(safe-area-inset-bottom))
    max(34px, env(safe-area-inset-left));
  background:
    radial-gradient(circle at 18% 12%, rgba(230,201,142,.10), transparent 28%),
    radial-gradient(circle at 82% 70%, rgba(158,181,198,.09), transparent 30%),
    linear-gradient(160deg, #0d1015 0%, #141922 52%, #0c0f14 100%);
}

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  min-height: 88px;
  transition: opacity .5s ease;
}

.brand {
  display: flex;
  align-items: center;
  gap: clamp(12px, 1.8vw, 22px);
  min-width: 0;
}

.brand-logo {
  width: clamp(58px, 7.5vw, 94px);
  height: auto;
  flex: 0 0 auto;
  filter: drop-shadow(0 3px 14px rgba(0,0,0,.24));
}

.brand-copy {
  min-width: 0;
}

.brand .eyebrow {
  color: var(--muted);
  font-size: clamp(.72rem, 1.1vw, .95rem);
  font-weight: 650;
  letter-spacing: .15em;
  text-transform: uppercase;
}

.brand h1 {
  margin: .18em 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.7rem, 3.3vw, 3.5rem);
  font-weight: 500;
  line-height: .95;
  letter-spacing: -.035em;
}

.stats {
  max-width: 42ch;
  color: var(--muted);
  font-size: clamp(.75rem, 1.1vw, .95rem);
  line-height: 1.45;
  text-align: right;
}

.stage {
  position: relative;
  min-height: calc(100vh - 170px);
  margin-top: 12px;
  isolation: isolate;
}

.cluster {
  position: absolute;
  min-width: 220px;
  max-width: min(42vw, 680px);
  padding: 16px 18px 18px;
  transform: translate(-50%, -50%);
  opacity: 0;
  filter: blur(4px);
  transition:
    opacity 1.45s ease,
    filter 1.45s ease,
    transform 1.8s cubic-bezier(.2,.8,.2,1);
  will-change: transform, opacity, filter;
}

.cluster.visible {
  opacity: 1;
  filter: blur(0);
}

.cluster.leaving {
  opacity: 0;
  filter: blur(6px);
}

.author {
  margin: 0 0 .48em;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.75rem, 4vw, 5.2rem);
  font-weight: 600;
  line-height: .95;
  letter-spacing: -.045em;
  text-wrap: balance;
  text-shadow: 0 2px 24px rgba(0,0,0,.28);
}

.tags {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .22em .48em;
  max-width: 100%;
}

.tag {
  display: inline-block;
  color: var(--tag);
  font-size: clamp(.92rem, 1.6vw, 1.85rem);
  font-weight: 460;
  line-height: 1.2;
  letter-spacing: .005em;
  opacity: .93;
  transform: translateY(0);
  animation: settle 1.2s ease both;
}

.tag:nth-child(3n+2) {
  color: var(--tag-soft);
  font-size: clamp(.82rem, 1.35vw, 1.55rem);
}

.tag:nth-child(4n) {
  color: var(--accent);
}

@keyframes settle {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: .93; transform: translateY(0); }
}

.controls {
  position: absolute;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: calc(100% - 32px);
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(9,12,16,.78);
  box-shadow: 0 12px 36px rgba(0,0,0,.25);
  backdrop-filter: blur(14px);
  transform: translateX(-50%);
  transition: opacity .35s ease, transform .35s ease;
}

.controls.idle {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
}

.controls button, .empty-state button {
  min-height: 44px;
  padding: 8px 15px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 999px;
  background: rgba(255,255,255,.07);
  cursor: pointer;
}

.controls button:hover, .empty-state button:hover {
  background: rgba(255,255,255,.12);
}

.controls button:focus-visible,
.empty-state button:focus-visible,
.settings-panel input:focus-visible {
  outline: 3px solid rgba(230,201,142,.65);
  outline-offset: 2px;
}

.settings-panel {
  position: absolute;
  right: max(22px, env(safe-area-inset-right));
  bottom: 88px;
  z-index: 25;
  width: min(430px, calc(100% - 44px));
  padding: 18px 18px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 18px 46px rgba(0,0,0,.32);
  backdrop-filter: blur(18px);
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) 155px 28px;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.setting-row label {
  color: var(--text);
  font-size: .92rem;
}

.setting-row input {
  width: 100%;
}

.setting-row input:disabled {
  opacity: .48;
  cursor: not-allowed;
}

.setting-row output {
  color: var(--accent);
  text-align: right;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  font-size: .92rem;
}

.toggle-row input {
  width: 20px;
  height: 20px;
}

.settings-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: .78rem;
  line-height: 1.4;
}

.message {
  position: absolute;
  top: 18px;
  left: 50%;
  z-index: 30;
  max-width: calc(100% - 40px);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--text);
  transform: translateX(-50%);
}

.empty-state {
  position: absolute;
  inset: 20% 20px auto;
  z-index: 15;
  text-align: center;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(1.8rem, 4vw, 3.4rem);
}

.empty-state p {
  margin: 0 0 18px;
  color: var(--muted);
}

.hidden { display: none !important; }

.no-title .masthead {
  opacity: 0;
  pointer-events: none;
}

.no-title .stage {
  min-height: calc(100vh - 88px);
  margin-top: -40px;
}


/* Adaptive desktop density
   Larger canvases reveal more authors and terms instead of inflating type. */
#app[data-density="medium"] .cluster {
  max-width: min(31vw, 520px);
}
#app[data-density="medium"] .author {
  font-size: clamp(1.7rem, 3vw, 4rem);
}
#app[data-density="medium"] .tag {
  font-size: clamp(.9rem, 1.3vw, 1.5rem);
}
#app[data-density="medium"] .tag:nth-child(3n+2) {
  font-size: clamp(.82rem, 1.12vw, 1.3rem);
}

#app[data-density="large"] .cluster {
  width: min(29vw, 500px);
  max-width: min(29vw, 500px);
  padding: 12px 14px 14px;
}
#app[data-density="large"] .author {
  margin-bottom: .4em;
  font-size: clamp(1.65rem, 2.55vw, 3.45rem);
}
#app[data-density="large"] .tag {
  font-size: clamp(.86rem, 1.08vw, 1.28rem);
  line-height: 1.16;
}
#app[data-density="large"] .tag:nth-child(3n+2) {
  font-size: clamp(.8rem, .96vw, 1.12rem);
}

#app[data-density="xl"] .cluster {
  width: min(22.5vw, 440px);
  max-width: min(22.5vw, 440px);
  min-width: 0;
  padding: 10px 12px 12px;
}
#app[data-density="xl"] .author {
  margin-bottom: .34em;
  font-size: clamp(1.55rem, 2.05vw, 3rem);
  line-height: .98;
  overflow-wrap: anywhere;
}
#app[data-density="xl"] .tags {
  gap: .18em .4em;
}
#app[data-density="xl"] .tag {
  font-size: clamp(.82rem, .92vw, 1.14rem);
  line-height: 1.14;
}
#app[data-density="xl"] .tag:nth-child(3n+2) {
  font-size: clamp(.76rem, .82vw, 1rem);
}


/* Three-row full-screen modes. These deliberately trade some individual
   cloud size for substantially more catalog content on screen. */
#app[data-density="three-row"] .cluster {
  width: min(29vw, 470px);
  max-width: min(29vw, 470px);
  min-width: 0;
  padding: 7px 10px 9px;
}
#app[data-density="three-row"] .author {
  margin-bottom: .27em;
  font-size: clamp(1.38rem, 1.85vw, 2.55rem);
  line-height: .96;
  overflow-wrap: anywhere;
}
#app[data-density="three-row"] .tags {
  gap: .14em .34em;
}
#app[data-density="three-row"] .tag {
  font-size: clamp(.74rem, .78vw, .98rem);
  line-height: 1.1;
}
#app[data-density="three-row"] .tag:nth-child(3n+2) {
  font-size: clamp(.69rem, .7vw, .88rem);
}

#app[data-density="ultrawide"] .cluster {
  width: min(21.5vw, 430px);
  max-width: min(21.5vw, 430px);
  min-width: 0;
  padding: 6px 9px 8px;
}
#app[data-density="ultrawide"] .author {
  margin-bottom: .24em;
  font-size: clamp(1.3rem, 1.45vw, 2.35rem);
  line-height: .96;
  overflow-wrap: anywhere;
}
#app[data-density="ultrawide"] .tags {
  gap: .12em .31em;
}
#app[data-density="ultrawide"] .tag {
  font-size: clamp(.7rem, .63vw, .92rem);
  line-height: 1.08;
}
#app[data-density="ultrawide"] .tag:nth-child(3n+2) {
  font-size: clamp(.66rem, .57vw, .84rem);
}

/* Reclaim a little extra stage height when a three-row layout is active. */
#app[data-density="three-row"] .stage,
#app[data-density="ultrawide"] .stage {
  min-height: calc(100vh - 145px);
  margin-top: 4px;
}

/* Even on very large displays, keep the masthead elegant rather than scaling
   indefinitely with the viewport. */
@media (min-width: 1420px) and (min-height: 780px) {
  .brand-logo { width: 78px; }
  .brand h1 { font-size: 3rem; }
  .brand .eyebrow { font-size: .82rem; }
  .stats { font-size: .86rem; }
}

@media (max-width: 760px) {
  #app { padding: 22px 18px 92px; }
  .masthead { min-height: 82px; }
  .brand {
    gap: 10px;
    align-items: center;
  }
  .brand-logo {
    width: 48px;
  }
  .brand .eyebrow {
    font-size: .58rem;
    letter-spacing: .11em;
  }
  .brand h1 {
    font-size: clamp(1.42rem, 6vw, 2.25rem);
    line-height: .94;
  }
  .stats { display: none; }
  .stage { min-height: calc(100vh - 150px); }
  .cluster {
    width: min(88vw, 540px);
    max-width: none;
    min-width: 0;
    padding: 8px 6px 10px;
  }
  .author {
    font-size: clamp(1.55rem, 7vw, 3.1rem);
    line-height: 1;
    overflow-wrap: anywhere;
  }
  .tags {
    gap: .24em .52em;
  }
  .tag { font-size: clamp(.86rem, 3.2vw, 1.25rem); }
  .tag:nth-child(3n+2) { font-size: clamp(.8rem, 2.8vw, 1.1rem); }
  .setting-row {
    grid-template-columns: 1fr 100px 24px;
    gap: 8px;
  }
  .controls {
    border-radius: 18px;
    width: calc(100% - 24px);
  }
}

/* Phones use a deliberately simpler composition: two centered author clouds,
   separated vertically. This prevents long names and subject lists from
   colliding or being clipped at the screen edges. */
@media (max-width: 600px) {
  .stage {
    min-height: calc(100vh - 156px);
  }
  .cluster {
    width: min(90vw, 500px);
    padding-inline: 4px;
  }
  .author {
    margin-bottom: .42em;
    font-size: clamp(1.6rem, 7.4vw, 2.35rem);
  }
  .tag {
    font-size: clamp(.84rem, 3.35vw, 1.12rem);
    line-height: 1.22;
  }
  .tag:nth-child(3n+2) {
    font-size: clamp(.8rem, 3vw, 1.02rem);
  }
}


/* Short phone screens in landscape need their own composition. Width alone is
   misleading here: an iPhone may be 800+ CSS px wide but only ~390 px tall.
   Keep exactly two compact clouds side-by-side and reclaim vertical space. */
@media (orientation: landscape) and (max-height: 500px) {
  #app {
    padding:
      max(10px, env(safe-area-inset-top))
      max(20px, env(safe-area-inset-right))
      max(60px, env(safe-area-inset-bottom))
      max(20px, env(safe-area-inset-left));
  }

  .masthead {
    min-height: 48px;
    align-items: flex-start;
  }

  .brand {
    gap: 8px;
  }

  .brand-logo {
    width: 38px;
  }

  .brand .eyebrow {
    font-size: .52rem;
    letter-spacing: .11em;
  }

  .brand h1 {
    margin-top: .05em;
    font-size: clamp(1.15rem, 3.7vw, 1.72rem);
    line-height: .92;
  }

  .stats {
    display: none;
  }

  .stage {
    min-height: calc(100vh - 86px);
    margin-top: 0;
  }

  .cluster {
    width: min(43vw, 390px);
    max-width: 43vw;
    min-width: 0;
    padding: 4px 8px 8px;
  }

  .author {
    margin-bottom: .34em;
    font-size: clamp(1.35rem, 4.4vw, 2.25rem);
    line-height: .96;
    overflow-wrap: anywhere;
  }

  .tags {
    gap: .18em .42em;
  }

  .tag {
    font-size: clamp(.72rem, 2.1vw, 1rem);
    line-height: 1.13;
  }

  .tag:nth-child(3n+2) {
    font-size: clamp(.68rem, 1.9vw, .92rem);
  }

  .controls {
    bottom: max(6px, env(safe-area-inset-bottom));
    width: auto;
    max-width: calc(100% - 30px);
    padding: 5px;
    gap: 5px;
    border-radius: 15px;
  }

  .controls button {
    min-height: 36px;
    padding: 5px 10px;
    font-size: .78rem;
  }

  .settings-panel {
    right: max(12px, env(safe-area-inset-right));
    bottom: 56px;
    max-height: calc(100vh - 68px);
    overflow: auto;
  }

  .no-title .stage {
    min-height: calc(100vh - 54px);
    margin-top: -10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cluster, .controls { transition-duration: .01ms !important; }
  .tag { animation: none !important; }
}
