:root {
  --zk-ink: #f7f7fb;
  --zk-muted: rgba(210, 216, 238, 0.72);
  --zk-faint: rgba(174, 181, 208, 0.54);
  --zk-line: rgba(154, 174, 255, 0.18);
  --zk-line-hot: rgba(255, 103, 61, 0.58);
  --zk-room: #080914;
  --zk-panel: rgba(13, 18, 38, 0.76);
  --zk-panel-soft: rgba(255, 255, 255, 0.045);
  --zk-paper: #f5eddc;
  --zk-paper-2: #fff8e8;
  --zk-paper-ink: #1e2332;
  --zk-paper-muted: rgba(36, 41, 56, 0.72);
  --zk-orange: #ff673d;
  --zk-ease: cubic-bezier(.16, 1, .3, 1);
}

.zk-body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 68% 15%, rgba(81, 92, 195, 0.34), transparent 31rem),
    radial-gradient(circle at 16% 18%, rgba(255, 103, 61, 0.10), transparent 24rem),
    linear-gradient(135deg, #080914 0%, #11162d 50%, #232858 100%);
}

.zk-body::before {
  background:
    linear-gradient(rgba(255, 255, 255, 0.022) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 42px 42px;
  opacity: 0.45;
}

.zettel-desk {
  width: min(1420px, calc(100% - 44px));
  padding: 28px 0 64px;
}

.zettel-desk .back-pill {
  position: relative;
  z-index: 4;
}

.zettel-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 360px);
  gap: 28px;
  align-items: end;
  padding: 50px 0 26px;
}

.zettel-hero h1 {
  max-width: 840px;
  margin: 0;
  color: var(--zk-ink);
  font-size: clamp(4.4rem, 7.2vw, 6.4rem);
  line-height: 0.9;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.zettel-lead {
  max-width: 62ch;
  margin: 22px 0 0;
  color: var(--zk-muted);
  font-size: 1.28rem;
  line-height: 1.55;
}

.kasten-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--zk-line);
  border-radius: 8px;
  background: rgba(8, 12, 27, 0.58);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
}

.kasten-stats span {
  min-height: 62px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 12px;
  border: 1px solid rgba(154, 174, 255, 0.14);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--zk-muted);
  font-size: 12px;
  font-weight: 820;
  line-height: 1.25;
}

.kasten-stats strong {
  color: var(--zk-ink);
  font-size: 1.65rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.card-index {
  display: grid;
  grid-template-columns: minmax(220px, 0.54fr) minmax(560px, 1.5fr) minmax(250px, 0.62fr);
  gap: 18px;
  align-items: start;
  margin-top: 10px;
}

.drawer-rail,
.reading-desk,
.connection-stack {
  border: 1px solid var(--zk-line);
  border-radius: 8px;
  background: var(--zk-panel);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

.drawer-rail,
.connection-stack {
  position: sticky;
  top: 20px;
  padding: 18px;
}

.rail-head,
.table-topline,
.connection-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.rail-head span,
.table-topline span,
.connection-head span {
  color: var(--zk-faint);
  font-size: 12px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.drawer-list,
.connection-stack [data-connections] {
  display: grid;
  gap: 10px;
}

.drawer-tab,
.connection-card {
  appearance: none;
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(154, 174, 255, 0.14);
  border-radius: 8px;
  box-shadow: none;
  cursor: pointer;
  text-align: left;
}

.drawer-tab {
  position: relative;
  display: grid;
  gap: 7px;
  padding: 14px 14px 13px 18px;
  background:
    linear-gradient(90deg, rgba(255, 103, 61, 0.10), transparent 46%),
    rgba(255, 255, 255, 0.04);
  color: var(--zk-ink);
  opacity: 0;
  transform: translateX(-12px);
  animation: drawer-in 420ms var(--drawer-delay, 0ms) var(--zk-ease) both;
  transition: transform 190ms var(--zk-ease), border-color 190ms ease, background 190ms ease;
}

.drawer-tab::before {
  content: "";
  position: absolute;
  inset: 10px auto 10px 0;
  width: 4px;
  border-radius: 0 999px 999px 0;
  background: transparent;
  transition: background 190ms ease, box-shadow 190ms ease;
}

.drawer-tab:hover,
.drawer-tab:focus-visible,
.drawer-tab.is-active {
  transform: translateX(5px);
  border-color: var(--zk-line-hot);
  background:
    linear-gradient(90deg, rgba(255, 103, 61, 0.17), transparent 58%),
    rgba(255, 255, 255, 0.055);
  outline: none;
}

.drawer-tab.is-active::before {
  background: var(--zk-orange);
  box-shadow: 0 0 18px rgba(255, 103, 61, 0.42);
}

.drawer-tab span {
  color: var(--zk-ink);
  font-weight: 900;
  line-height: 1.18;
}

.drawer-tab small {
  color: var(--zk-muted);
  line-height: 1.35;
}

.drawer-tab em {
  justify-self: start;
  color: #ffd7ca;
  font-size: 11px;
  font-style: normal;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

.reading-desk {
  position: relative;
  min-height: 700px;
  padding: 18px;
  background:
    radial-gradient(circle at 50% 32%, rgba(255, 255, 255, 0.07), transparent 19rem),
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.018)),
    rgba(7, 10, 23, 0.72);
  overflow: hidden;
}

.reading-desk::before,
.reading-desk::after {
  content: "";
  position: absolute;
  left: 11%;
  right: 11%;
  height: 18px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.23);
  filter: blur(18px);
  pointer-events: none;
}

.reading-desk::before {
  top: 142px;
}

.reading-desk::after {
  bottom: 54px;
}

.table-topline,
.table-hint {
  position: relative;
  z-index: 3;
}

.card-stack {
  position: relative;
  z-index: 2;
  min-height: 570px;
  display: grid;
  place-items: center;
  padding: 20px 0 18px;
}

.card-stack::before,
.card-stack::after {
  content: "";
  position: absolute;
  width: min(88%, 640px);
  min-height: 430px;
  border-radius: 8px;
  background: #eadfc9;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

.card-stack::before {
  transform: translateY(18px) rotate(-2deg);
  opacity: 0.46;
}

.card-stack::after {
  transform: translateY(9px) rotate(1.5deg);
  opacity: 0.62;
}

.paper-card {
  position: relative;
  z-index: 4;
  width: min(96%, 760px);
  min-height: 500px;
  padding: 32px;
  border: 1px solid rgba(62, 52, 33, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(rgba(33, 31, 24, 0.035) 1px, transparent 1px),
    radial-gradient(circle at 18% 10%, rgba(255, 255, 255, 0.82), transparent 14rem),
    linear-gradient(135deg, var(--zk-paper-2), var(--zk-paper));
  background-size: 100% 34px, auto, auto;
  color: var(--zk-paper-ink);
  box-shadow: 0 34px 86px rgba(0, 0, 0, 0.38);
  cursor: grab;
  touch-action: none;
  user-select: none;
  transform: translate3d(0, 0, 0);
  transition: transform 220ms var(--zk-ease), opacity 180ms ease, box-shadow 180ms ease;
}

.paper-card.is-entering {
  animation: card-pull 460ms var(--zk-ease) both;
}

.paper-card.is-dragging {
  cursor: grabbing;
  transition: none;
  will-change: transform;
  box-shadow: 0 40px 96px rgba(0, 0, 0, 0.46);
}

.paper-card.is-threshold {
  outline: 2px solid rgba(255, 103, 61, 0.62);
  outline-offset: 7px;
}

.paper-card.is-returning {
  transition: transform 260ms var(--zk-ease), outline-color 180ms ease;
}

.paper-card.is-swiping {
  transition: transform 180ms ease-out, opacity 180ms ease-out;
}

.paper-card.is-empty {
  display: grid;
  place-items: center;
  gap: 10px;
  text-align: center;
  cursor: default;
}

.paper-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  color: var(--zk-paper-muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.10em;
  text-transform: uppercase;
}

.paper-head code {
  padding: 6px 9px;
  border: 1px solid rgba(35, 32, 24, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.42);
  color: #2d2d32;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.source-band {
  display: grid;
  gap: 8px;
  margin: 0 0 18px;
  padding: 13px 14px;
  border: 1px solid rgba(35, 32, 24, 0.14);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(255, 103, 61, 0.12), transparent 58%),
    rgba(255, 255, 255, 0.38);
}

.source-band div {
  display: grid;
  gap: 3px;
}

.source-band span {
  color: rgba(255, 103, 61, 0.98);
  font-size: 10px;
  font-weight: 950;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.source-band strong {
  color: var(--zk-paper-ink);
  font-size: 0.98rem;
  line-height: 1.25;
}

.source-band small,
.source-band p {
  margin: 0;
  color: rgba(36, 41, 56, 0.64);
  font-size: 12px;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}

.paper-card h2 {
  max-width: 100%;
  margin: 0 0 20px;
  color: var(--zk-paper-ink);
  font-size: clamp(2rem, 3vw, 2.85rem);
  line-height: 1.04;
  letter-spacing: 0;
  overflow-wrap: normal;
  word-break: normal;
  hyphens: auto;
}

.paper-fields {
  display: grid;
  gap: 14px;
  margin: 0;
}

.paper-fields div {
  display: grid;
  gap: 6px;
}

.paper-fields dt {
  color: rgba(255, 103, 61, 0.96);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.paper-fields dd {
  max-width: 65ch;
  margin: 0;
  color: var(--zk-paper-muted);
  font-size: 0.98rem;
  line-height: 1.48;
  overflow-wrap: anywhere;
}

.proof-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.proof-strip span {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 8px 9px;
  border: 1px solid rgba(34, 31, 22, 0.12);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.34);
  color: rgba(30, 35, 50, 0.76);
  font-size: 12px;
  line-height: 1.3;
}

.proof-strip b {
  color: rgba(255, 103, 61, 0.92);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.paper-output {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 26px;
}

.paper-output span {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border: 1px solid rgba(34, 31, 22, 0.14);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.46);
  color: rgba(30, 35, 50, 0.78);
  font-size: 12px;
  font-weight: 850;
}

.card-loading {
  margin: 0;
  color: var(--zk-paper-muted);
}

.table-hint {
  margin: 0;
  color: var(--zk-faint);
  font-size: 12px;
  font-weight: 780;
  text-align: center;
}

.connection-card {
  display: grid;
  gap: 8px;
  padding: 13px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--zk-ink);
  opacity: 0;
  transform: translateY(9px);
  animation: connection-in 360ms var(--connection-delay, 0ms) var(--zk-ease) both;
  transition: transform 170ms var(--zk-ease), border-color 170ms ease, background 170ms ease;
}

.connection-card:hover,
.connection-card:focus-visible,
.connection-card.is-active {
  transform: translateY(-2px);
  border-color: var(--zk-line-hot);
  background: rgba(255, 103, 61, 0.10);
  outline: none;
}

.connection-card span {
  color: #ffd7ca;
  font-size: 11px;
  font-weight: 920;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.connection-card strong {
  color: var(--zk-ink);
  line-height: 1.26;
  overflow-wrap: anywhere;
}

.connection-card small,
.connection-empty {
  color: var(--zk-muted);
  line-height: 1.45;
}

.connection-card.has-target::after {
  content: "Verweis vorhanden";
  justify-self: start;
  margin-top: 3px;
  color: var(--zk-faint);
  font-size: 11px;
  font-weight: 850;
}

.connection-card.has-source::after {
  content: "Quelle öffnen";
}

.zk-footer {
  margin-top: 20px;
  padding: 18px;
  border: 1px solid var(--zk-line);
  border-radius: 8px;
  background: rgba(8, 12, 27, 0.54);
  text-align: center;
}

@keyframes drawer-in {
  from {
    opacity: 0;
    transform: translateX(-14px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes card-pull {
  from {
    opacity: 0;
    transform: translate3d(var(--enter-x, 22px), 12px, 0) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translate3d(0, 0, 0) scale(1);
  }
}

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

@media (max-width: 1120px) {
  .card-index {
    grid-template-columns: minmax(210px, 0.56fr) minmax(0, 1.44fr);
  }

  .connection-stack {
    grid-column: 2;
    position: static;
  }
}

@media (max-width: 820px) {
  .zettel-desk {
    width: calc(100% - 28px);
    padding-top: 22px;
  }

  .zettel-hero {
    grid-template-columns: 1fr;
    padding-top: 44px;
  }

  .zettel-hero h1 {
    font-size: 4.2rem;
  }

  .kasten-stats {
    grid-template-columns: 1fr;
  }

  .kasten-stats span {
    min-height: 48px;
  }

  .card-index {
    display: grid;
    grid-template-columns: 1fr;
  }

  .drawer-rail,
  .connection-stack {
    position: static;
  }

  .drawer-list {
    display: flex;
    overflow-x: auto;
    padding-bottom: 7px;
    scroll-snap-type: x mandatory;
  }

  .drawer-tab {
    flex: 0 0 min(78vw, 320px);
    scroll-snap-align: start;
  }

  .reading-desk {
    min-height: auto;
  }

  .card-stack {
    min-height: 520px;
    padding-top: 10px;
  }

  .card-stack::before,
  .card-stack::after {
    width: 90%;
    min-height: 410px;
  }

  .paper-card {
    width: 94%;
    min-height: 430px;
    padding: 26px;
  }

  .paper-card h2 {
    font-size: 2.55rem;
  }

  .connection-stack [data-connections] {
    display: flex;
    overflow-x: auto;
    padding-bottom: 7px;
    scroll-snap-type: x mandatory;
  }

  .connection-card {
    flex: 0 0 min(82vw, 340px);
    scroll-snap-align: start;
  }
}

@media (max-width: 460px) {
  .zettel-hero h1 {
    font-size: 3.6rem;
  }

  .zettel-lead {
    font-size: 1.08rem;
  }

  .paper-card {
    width: 96%;
    padding: 22px;
  }

  .paper-card h2 {
    font-size: 2.15rem;
  }

  .proof-strip {
    grid-template-columns: 1fr;
  }

  .paper-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}
