:root {
  --bg: #12100e;
  --ink: #f4efe6;
  --muted: #b3a594;
  --faint: #8c8174;
  --line: rgba(244, 239, 230, 0.1);
  --line-strong: rgba(244, 239, 230, 0.2);
  --ember: #e6a15a;
  --ember-ink: #2a1c0e;
  --card: #1e1a16;
  --danger: #f0a090;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.38);
  --sans: "Outfit", system-ui, sans-serif;
  --serif: "Fraunces", Georgia, serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(900px 480px at 8% -10%, rgba(230, 161, 90, 0.16), transparent 55%),
    radial-gradient(720px 480px at 110% 110%, rgba(156, 186, 168, 0.12), transparent 50%),
    var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.4;
}

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

button, .btn {
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
}

button:hover, .btn:hover { border-color: rgba(230, 161, 90, 0.7); }

button:focus-visible, .btn:focus-within, .file:focus-within {
  outline: 2px solid var(--ember);
  outline-offset: 2px;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

button.primary {
  background: var(--ember);
  color: var(--ember-ink);
  border-color: transparent;
  font-weight: 600;
}

button.primary:hover { filter: brightness(1.05); }

#btn-delete:hover:not(:disabled) {
  border-color: var(--danger);
  color: var(--danger);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  z-index: 5;
  background: var(--ember);
  color: var(--ember-ink);
  padding: 6px 10px;
  border-radius: 8px;
  text-decoration: none;
}

.skip:focus { top: 12px; }

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 16px 10px;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 12px;
  background: radial-gradient(circle at 40% 30%, #ffd7a8, #e6a15a 46%, #8a5a28);
  color: var(--ember-ink);
  font-size: 18px;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.45rem;
  font-weight: 560;
  letter-spacing: -0.03em;
  line-height: 1;
}

.tag { margin: 3px 0 0; color: var(--muted); font-size: 0.8rem; }

.tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  flex-wrap: wrap;
}

#count {
  color: var(--faint);
  font-size: 0.8rem;
  padding: 0 4px;
  font-variant-numeric: tabular-nums;
}

.file { display: inline-flex; align-items: center; position: relative; }

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

#banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 16px 8px;
  padding: 8px 8px 8px 14px;
  border-radius: 12px;
  background: rgba(230, 161, 90, 0.12);
  border: 1px solid rgba(230, 161, 90, 0.35);
  color: #ffd7a8;
  font-size: 0.875rem;
}

#banner p { margin: 0; }

#banner[hidden] { display: none; }

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  background-image: radial-gradient(rgba(244, 239, 230, 0.055) 1px, transparent 1px);
  background-size: 22px 22px;
  cursor: grab;
}

#stage.panning { cursor: grabbing; }

#camera {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  overflow: visible;
}

#wires {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
}

#wires path {
  fill: none;
  stroke: #a48460;
  stroke-width: 1.75;
  stroke-linecap: round;
}

#wires path.hot { stroke: #e6a15a; stroke-width: 2.25; }

.node:hover { border-color: rgba(230, 161, 90, 0.55); }
.node.selected:hover { border-color: var(--ember); }

.node {
  position: absolute;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: 220px;
  min-width: 132px;
  padding: 11px 13px 12px;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
  cursor: grab;
  text-align: left;
  user-select: none;
  z-index: 1;
}

.node:active { cursor: grabbing; }

.node.root {
  max-width: 260px;
  min-width: 168px;
  padding: 14px 16px 15px;
  background: linear-gradient(180deg, #3a2e22, #1e1a16 52%);
  border-color: rgba(230, 161, 90, 0.6);
}

.node.selected {
  border-color: var(--ember);
  box-shadow: 0 0 0 1px var(--ember), var(--shadow);
  z-index: 2;
}

.node:focus { outline: none; }

.node:focus-visible {
  outline: 2px solid var(--ember);
  outline-offset: 3px;
}

.lens {
  display: block;
  margin-bottom: 4px;
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #ffd7a8;
}

.lens-who { color: #b7d4c4; }
.lens-invert { color: #f0b2a8; }
.lens-shrink { color: #e6d7c3; }
.lens-stretch { color: #b7d4ea; }
.lens-combine { color: #e6c7a8; }
.lens-risk { color: #f0a090; }
.lens-next { color: #c9deb0; }

.node .text {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.02rem;
  font-weight: 520;
  line-height: 1.25;
  letter-spacing: -0.02em;
}

.node.root .text {
  font-size: 1.35rem;
  font-weight: 560;
}

.node .text.placeholder { color: var(--muted); font-style: italic; }

.node textarea {
  display: block;
  width: 190px;
  min-height: 3.6em;
  margin: 0;
  padding: 0;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 1.02rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
  user-select: text;
}

.node.root textarea { width: 220px; font-size: 1.25rem; }

.node textarea:focus { outline: none; }

#zoom {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
}

#zoom button {
  width: 36px;
  padding: 0;
  background: rgba(18, 16, 14, 0.82);
  backdrop-filter: blur(10px);
}

#dock {
  margin: 0 16px 16px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(22, 19, 16, 0.9);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
}

#dock-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.compose-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.grow { flex: 1; min-width: 0; display: block; }

#composer {
  width: 100%;
  resize: none;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 10px;
  line-height: 1.35;
}

#composer:focus {
  outline: 2px solid var(--ember);
  outline-offset: 1px;
  border-color: transparent;
}

.dock-actions { display: flex; gap: 8px; flex: 0 0 auto; }

#lenses {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.lens-btn { height: 32px; padding: 0 10px; font-size: 0.8rem; }

#toast {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(8px);
  opacity: 0;
  pointer-events: none;
  background: var(--ink);
  color: #1a1612;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 4;
  max-width: calc(100% - 32px);
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

dialog {
  border: 1px solid var(--line-strong);
  background: #1c1915;
  color: var(--ink);
  border-radius: 20px;
  padding: 22px;
  max-width: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(10, 8, 6, 0.64); }

dialog h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-weight: 560;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}

dialog p { margin: 0 0 16px; color: var(--muted); line-height: 1.45; }

dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin: 0; }

.keys { list-style: none; margin: 0 0 14px; padding: 0; }

.keys li {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 4px 0;
  font-size: 0.92rem;
}

kbd {
  font-family: var(--sans);
  font-size: 0.75rem;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  padding: 2px 6px;
  min-width: 1.6em;
  text-align: center;
  color: var(--ink);
}

#share-url {
  width: 100%;
  margin: 0 0 14px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.03);
}

@media (max-width: 720px) {
  header { flex-wrap: wrap; gap: 8px; padding: 10px 12px 8px; }
  .tag { display: none; }
  h1 { font-size: 1.25rem; }
  .tools {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
  }
  button, .btn { height: 34px; padding: 0 10px; }
  #banner { margin: 0 12px 8px; }
  .node { max-width: 180px; min-width: 116px; }
  .node.root { max-width: 200px; }
  .node.root .text { font-size: 1.15rem; }
  .node textarea, .node.root textarea { width: 150px; }
  #zoom { left: 12px; right: auto; }
  #dock { margin: 0 8px 8px; padding: 10px; }
  .compose-row { flex-direction: column; align-items: stretch; }
  .dock-actions { justify-content: stretch; }
  .dock-actions button { flex: 1; }
  #lenses { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
