:root {
  --bg: #1b100b;
  --panel: #311f15d6;
  --text: #fff1d7;
  --muted: #c7ad87;
  --line: #ffe8c22e;
  --accent: #c96832;
  --accent-2: #e9ad55;
  --accent-deep: #8f3f22;
  --cream: #fff0cf;

  --panel-radius: clamp(18px, 3vw, 34px);
  --scene-perspective: 900px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100svh;
  overflow: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 14%, #51261766 0, transparent 32%),
    radial-gradient(circle at 82% 76%, #70432236 0, transparent 30%),
    linear-gradient(145deg, #130a07 0%, var(--bg) 48%, #24130c 100%);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

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

.app-shell {
  width: 100%;
  height: 100svh;
  padding: clamp(10px, 2.3vw, 28px);
}

.wordcloud-panel {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--panel-radius);
  background:
    linear-gradient(180deg, #ffffff08 0%, transparent 24%),
    var(--panel);
  box-shadow:
    inset 0 1px 0 #fff5dd16,
    0 24px 80px #0904028a;
}

.wordcloud-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, transparent 0 49.92%, #fff2d20d 50%, transparent 50.08%),
    linear-gradient(0deg, transparent 0 49.92%, #fff2d20a 50%, transparent 50.08%);
  mask-image: radial-gradient(circle at center, #000 0%, transparent 68%);
  opacity: 0.5;
}

.wordcloud-viewport {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  perspective: var(--scene-perspective);
  perspective-origin: 50% 50%;
  touch-action: none;
  user-select: none;
  cursor: crosshair;
}


.wordcloud-viewport.is-over-word {
  cursor: grab;
}

.wordcloud-viewport.is-dragging {
  cursor: grabbing;
}


.wordcloud-camera {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  will-change: transform;
}

.wordcloud-world,
.particle-world {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 0;
  height: 0;
  transform-style: preserve-3d;
}

.word {
  position: absolute;
  left: 0;
  top: 0;
  display: inline-flex;
  align-items: center;
  padding: 0.08em 0.15em;
  white-space: nowrap;
  transform-style: preserve-3d;
  transform-origin: center;
  line-height: 0.9;
  letter-spacing: -0.035em;
  font-weight: 650;
  color: var(--text);
  text-shadow:
    0 0 18px #e9ad551f,
    0 2px 12px #1206039e;
  will-change: transform, opacity, filter, font-size;
  transition: font-size 1100ms cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
  touch-action: none;
  backface-visibility: hidden;
}

.word:focus-visible {
  outline: 1px solid color-mix(in srgb, var(--accent-2) 65%, transparent);
  outline-offset: 0.14em;
  border-radius: 0.12em;
}

.word[data-tone="accent"] {
  color: var(--accent-2);
}

.word[data-tone="cream"] {
  color: var(--cream);
}

.word[data-tone="deep"] {
  color: #dc8052;
}

.particle {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--particle-size, 6px);
  height: var(--particle-size, 6px);
  border-radius: 999px;
  background: var(--particle-color, var(--accent-2));
  box-shadow: 0 0 22px color-mix(in srgb, var(--particle-color) 45%, transparent);
  will-change: transform, opacity, filter;
  pointer-events: none;
}

.ambient {
  position: absolute;
  z-index: 0;
  width: min(48vw, 620px);
  aspect-ratio: 1;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.16;
  pointer-events: none;
}

.ambient--one {
  left: -10%;
  top: -22%;
  background: var(--accent);
}

.ambient--two {
  right: -12%;
  bottom: -30%;
  background: var(--accent-2);
  opacity: 0.08;
}

.panel-vignette {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  box-shadow:
    inset 0 0 90px 16px #120804ba,
    inset 0 0 220px 60px #170a0699;
}

.view-mode-toggle {
  position: absolute;
  z-index: 7;
  top: clamp(14px, 2vw, 24px);
  right: clamp(14px, 2vw, 24px);
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #1b100bc9;
  box-shadow:
    inset 0 1px 0 #fff6df12,
    0 8px 28px #10070350;
}

.view-mode-button {
  min-width: 64px;
  min-height: 34px;
  padding: 7px 13px;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  font-weight: 720;
  letter-spacing: 0.03em;
  transition:
    color 350ms ease,
    background 500ms cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 500ms ease,
    transform 500ms cubic-bezier(0.22, 1, 0.36, 1);
}

.view-mode-button:hover {
  color: var(--cream);
}

.view-mode-button:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent-2) 72%, transparent);
  outline-offset: 2px;
}

.view-mode-button.is-active {
  color: var(--cream);
  background: #432619e8;
  box-shadow:
    inset 0 1px 0 #fff5dd14,
    0 0 14px #e9ad5515;
}

.scene-toggle:disabled {
  cursor: default;
  opacity: 0.42;
}

.word.word--measure {
  position: absolute;
  left: -100000px;
  top: -100000px;
  visibility: hidden;
  opacity: 0 !important;
  filter: none !important;
  transform: none !important;
  transition: none !important;
  pointer-events: none;
}

.word.word--measure .word-count-slot,
.word.word--measure .word-count-badge {
  transition: none !important;
}

.scene-controls {
  position: absolute;
  z-index: 6;
  left: 50%;
  bottom: clamp(14px, 2vw, 24px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  max-width: calc(100% - 24px);
  transform: translateX(-50%);
}

.scene-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 40px;
  padding: 8px 14px 8px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  background: #1b100bc9;
  box-shadow:
    inset 0 1px 0 #fff6df12,
    0 8px 28px #10070366;
  cursor: pointer;
  white-space: nowrap;
  transition:
    border-color 300ms ease,
    background 300ms ease,
    box-shadow 300ms ease,
    color 300ms ease,
    transform 500ms cubic-bezier(0.22, 1, 0.36, 1);
}

.scene-toggle:hover {
  border-color: #ffe8c24f;
  background: #28170fcf;
}

.scene-toggle:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent-2) 72%, transparent);
  outline-offset: 3px;
}

.scene-toggle__dot {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  border: 1px solid #ffe8c23d;
  border-radius: 50%;
  background: #fff0cf12;
  box-shadow: inset 0 0 0 4px #1b100b;
  transition:
    background 500ms ease,
    box-shadow 500ms ease,
    border-color 500ms ease,
    transform 650ms cubic-bezier(0.22, 1, 0.36, 1);
}

.scene-toggle.is-active {
  color: var(--cream);
  border-color: #e9ad556b;
  background: #432619d9;
}

.scene-toggle.is-active .scene-toggle__dot {
  border-color: var(--accent-2);
  background: var(--accent-2);
  box-shadow:
    inset 0 0 0 4px #432619,
    0 0 14px #e9ad555c;
  transform: scale(1.04);
}

.scene-toggle__label {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.025em;
}

/*
 * The count slot begins at zero width. Expanding the slot changes the parent
 * word's width gradually, so the word and badge recenter together instead of
 * snapping when counts are toggled.
 */
.word-count-slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 0;
  height: var(--count-size, 28px);
  margin-right: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateX(0.12em) scale(0.82);
  transform-origin: center;
  transition:
    width 900ms cubic-bezier(0.22, 1, 0.36, 1),
    margin-right 900ms cubic-bezier(0.22, 1, 0.36, 1),
    opacity 700ms ease,
    transform 900ms cubic-bezier(0.22, 1, 0.36, 1);
}

.word-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--count-size, 28px);
  height: var(--count-size, 28px);
  flex: 0 0 var(--count-size, 28px);
  border: 1px solid #ffe8c255;
  border-radius: 50%;
  color: var(--cream);
  background: #24150ec7;
  box-shadow:
    inset 0 1px 0 #fff4d91a,
    0 0 16px #e9ad5510;
  font-size: var(--count-font-size, 11px);
  font-weight: 720;
  line-height: 1;
  letter-spacing: -0.02em;
  transition:
    width 1100ms cubic-bezier(0.22, 1, 0.36, 1),
    height 1100ms cubic-bezier(0.22, 1, 0.36, 1),
    font-size 1100ms cubic-bezier(0.22, 1, 0.36, 1);
}

.word-label {
  display: inline-block;
  flex: 0 0 auto;
}

.wordcloud-world.show-counts .word-count-slot {
  width: var(--count-size, 28px);
  margin-right: var(--count-gap, 10px);
  opacity: 1;
  transform: translateX(0) scale(1);
}

.wordcloud-viewport.is-list-mode
  .wordcloud-world.show-counts
  .word-count-slot {
  width:
    calc(
      var(--count-size, 28px) *
      var(--list-count-scale, 1)
    );
  height:
    calc(
      var(--count-size, 28px) *
      var(--list-count-scale, 1)
    );
  margin-right:
    calc(
      var(--count-gap, 10px) *
      var(--list-count-scale, 1)
    );
  overflow: visible;
}

.wordcloud-viewport.is-list-mode .word-count-badge {
  font-size: calc(var(--count-font-size, 11px) * 1.4);
  transform: scale(var(--list-count-scale, 1));
  transition:
    width 1100ms cubic-bezier(0.22, 1, 0.36, 1),
    height 1100ms cubic-bezier(0.22, 1, 0.36, 1),
    font-size 1100ms cubic-bezier(0.22, 1, 0.36, 1),
    transform 900ms cubic-bezier(0.22, 1, 0.36, 1);
}

.status {
  position: absolute;
  z-index: 5;
  left: 50%;
  bottom: clamp(62px, calc(2vw + 48px), 76px);
  margin: 0;
  padding: 8px 12px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: #1b100bb5;
  font-size: 12px;
  letter-spacing: 0.02em;
  opacity: 1;
  transition: opacity 500ms ease;
  pointer-events: none;
}

.status.is-hidden {
  opacity: 0;
}

@media (max-width: 600px) {
  :root {
    --scene-perspective: 720px;
  }

  .app-shell {
    padding: 7px;
  }

  .wordcloud-panel {
    border-radius: 18px;
  }

  .view-mode-toggle {
    top: 10px;
    right: 10px;
  }

  .view-mode-button {
    min-width: 54px;
    min-height: 32px;
    padding: 6px 10px;
  }

  .scene-controls {
    gap: 6px;
    max-width: calc(100% - 14px);
  }

  .scene-toggle {
    min-height: 38px;
    padding: 7px 11px 7px 9px;
  }

  .scene-toggle__label {
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .word,
  .particle,
  .wordcloud-camera {
    transition: none;
  }

  .ambient {
    display: none;
  }
}
