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

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #ece7de;
  color: #1f242c;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.kb-knots {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
}

.kb-canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

.kb-canvas:active {
  cursor: grabbing;
}

/* Top bar */
.kb-topbar {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  pointer-events: none;
}

.kb-knot-nav {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: calc(100% - 130px);
  overflow-x: auto;
  scrollbar-width: none;
  padding: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(31, 36, 44, 0.1);
  box-shadow: 0 8px 24px -12px rgba(24, 30, 42, 0.22);
  backdrop-filter: blur(10px);
}

.kb-knot-nav::-webkit-scrollbar {
  display: none;
}

.kb-knot-pill {
  flex: 0 0 auto;
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  color: #364152;
  background: transparent;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.kb-knot-pill:hover {
  background: rgba(31, 36, 44, 0.07);
  color: #111827;
}

.kb-knot-pill.is-active {
  background: #087a50;
  color: #ffffff;
}

.kb-knot-pill:focus-visible,
.kb-chip-btn:focus-visible,
.kb-icon-btn:focus-visible,
.kb-play-btn:focus-visible,
.kb-speed button:focus-visible {
  outline: 2px solid #087a50;
  outline-offset: 2px;
}

.kb-top-actions {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.kb-chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(31, 36, 44, 0.12);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: #1f242c;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 8px 24px -12px rgba(24, 30, 42, 0.22);
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition: background-color 0.15s;
  white-space: nowrap;
}

.kb-chip-btn:hover {
  background: #ffffff;
}

.kb-chip-btn[aria-expanded="true"] {
  background: #1f242c;
  color: #ffffff;
  border-color: #1f242c;
}

.kb-hint {
  position: absolute;
  top: 62px;
  right: 16px;
  z-index: 5;
  font-size: 11.5px;
  font-weight: 500;
  color: rgba(31, 36, 44, 0.58);
  pointer-events: none;
}

/* Info card */
.kb-info-card {
  position: absolute;
  top: 62px;
  right: 12px;
  z-index: 15;
  width: min(330px, calc(100vw - 24px));
  max-height: calc(100dvh - 180px);
  overflow-y: auto;
  padding: 16px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(31, 36, 44, 0.12);
  box-shadow: 0 18px 40px -16px rgba(24, 30, 42, 0.3);
  backdrop-filter: blur(12px);
  user-select: text;
}

.kb-info-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.kb-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: #e6f4ee;
  color: #087a50;
}

.kb-info-title {
  margin: 4px 0 0;
  font-size: 17px;
  font-weight: 700;
  color: #111827;
}

.kb-info-line {
  margin: 8px 0 12px;
  font-size: 13.5px;
  line-height: 1.45;
  color: #364152;
}

.kb-info-section h3 {
  margin: 0 0 6px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #64748b;
}

.kb-info-section ul {
  margin: 0 0 12px;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.45;
  color: #1f242c;
}

.kb-info-section li + li {
  margin-top: 4px;
}

.kb-info-watch {
  padding: 10px 12px;
  border-radius: 10px;
  background: #fef7e6;
  border: 1px solid #f4d896;
  font-size: 12.5px;
  line-height: 1.45;
  color: #6b4506;
}

.kb-credit {
  margin: 10px 0 0;
  font-size: 11px;
  color: #64748b;
}

/* Playback dock */
.kb-player {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 10;
  width: min(740px, calc(100% - 24px));
  padding: 10px 14px 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(31, 36, 44, 0.11);
  box-shadow: 0 16px 36px -16px rgba(24, 30, 42, 0.28);
  backdrop-filter: blur(12px);
}

.kb-step-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13.5px;
  line-height: 1.3;
}

.kb-step-num {
  flex-shrink: 0;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(8, 122, 80, 0.12);
  color: #087a50;
  font-size: 11.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.kb-step-title {
  font-weight: 600;
  color: #111827;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kb-bake-status {
  margin-left: auto;
  font-size: 11px;
  font-weight: 600;
  color: #64748b;
  white-space: nowrap;
}

.kb-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.kb-play-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: #087a50;
  color: #ffffff;
  cursor: pointer;
  transition: background-color 0.15s, transform 0.1s;
}

.kb-play-btn:hover {
  background: #066341;
}

.kb-play-btn:active {
  transform: scale(0.95);
}

.kb-icon-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #364152;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.kb-icon-btn:hover {
  background: rgba(31, 36, 44, 0.08);
  color: #111827;
}

.kb-icon-btn.is-active {
  background: rgba(8, 122, 80, 0.14);
  color: #087a50;
}

.kb-track {
  position: relative;
  flex: 1;
  min-width: 80px;
  height: 28px;
  display: flex;
  align-items: center;
}

.kb-rail {
  position: relative;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: rgba(31, 36, 44, 0.12);
  overflow: hidden;
}

.kb-rail-ready {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: rgba(8, 122, 80, 0.25);
}

.kb-rail-played {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: #087a50;
}

.kb-ticks {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  pointer-events: none;
}

.kb-ticks li button {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 10px;
  height: 10px;
  padding: 0;
  border: 2px solid #ffffff;
  border-radius: 999px;
  background: #94a3b8;
  pointer-events: auto;
  cursor: pointer;
  z-index: 2;
  transition: transform 0.12s, background-color 0.12s;
}

.kb-ticks li button:hover {
  transform: translate(-50%, -50%) scale(1.25);
}

.kb-ticks li button[aria-current="step"] {
  background: #087a50;
  transform: translate(-50%, -50%) scale(1.3);
}

.kb-scrub {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 1;
}

.kb-clock {
  flex-shrink: 0;
  min-width: 38px;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: #475569;
}

.kb-speed {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 2px;
  border-radius: 999px;
  background: rgba(31, 36, 44, 0.06);
}

.kb-speed button {
  border: 0;
  border-radius: 999px;
  padding: 4px 7px;
  font-size: 11.5px;
  font-weight: 600;
  color: #475569;
  background: transparent;
  cursor: pointer;
}

.kb-speed button.is-active {
  background: #ffffff;
  color: #111827;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

@media (max-width: 640px) {
  .kb-topbar {
    top: 8px;
    left: 8px;
    right: 8px;
  }
  .kb-knot-nav {
    max-width: calc(100% - 46px);
  }
  .kb-chip-btn span {
    display: none;
  }
  .kb-hint {
    display: none;
  }
  .kb-player {
    bottom: 8px;
    width: calc(100% - 16px);
    padding: 8px 10px 10px;
  }
  .kb-clock {
    display: none;
  }
  .kb-speed button {
    padding: 4px 5px;
    font-size: 11px;
  }
}
